HPW wrote:Running Turtle.lsp with the UTF-8 EXE gives an error ' Bad screen distance "302,1612092" '.
Running an equivalent program UTF-8 EXE was able to carry all its calculations and display Japanese without any problems
Jean-Pierre
========= Kame.lsp
;; Kame.lsp - graphics
;; written by Jean-Pierre Berard
;;
;; 1 rad = 180/3.1415927 = 57.29578 deg
;; 1 deg = 0.017453292 rad
(set! color "blue")
(set! width 500)
(set! height 500)
(define (convert angle) (mul angle 0.017453292))
(define (adjacent-cos angle hypo) (mul hypo (cos (convert angle))))
(define (adjacent-tan angle opposite) (div opposite (tan (convert angle))))
(define (hypo-sin angle opposite) (div opposite (sin (convert angle))))
(define (hypo-cos angle adjacent) (div adjacent (cos (convert angle))))
(define (opposite-sin angle hypo) (mul hypo (sin (convert angle))))
(define (opposite-tan angle adjacent) (mul adjacent (tan (convert angle))))
(define (outer inner-angle) (sub 180 inner-angle))
(define (rectangular angle radius)
(set! x (adjacent-cos angle radius))
(set! y (opposite-sin angle radius))
(println "x=" x " y=" y)
true
)
(define (polar x y)
(set! angle (div (atan (div y x)) 0.017453292))
(set! radius (root (add (pow x 2) (pow y 2)) 2))
(println "angle=" angle " radius=" radius)
true
)
(define (triangulation side side-size)
(set! y (div side-size 2))
(set! angle (div 360 side 2))
(set! x (adjacent-tan angle y))
(set! radius (hypo-sin angle y))
(println "angle=" angle " radius=" radius)
(println "x=" x " y=" y)
(pen 'yellow)
(forward y)
(right 90)
(forward x)
(right (sub 180 angle))
(forward radius)
true
)
(define (pseudo-polygon side n)
(set! ratio (div 360 side))
(dotimes (x side)
(forward n)
(right ratio))
(left ratio)
)
(define (polygon side n)
(dotimes (x side)
(forward n)
(right (div 360 side))
))
(define (oval x y)
(set! Y (sub lastY (div y 2)))
(tk ".kw.canvas create oval "
(join (map string (list lastX Y (add lastX x) (add Y y))) " ")
" -outline " color)
(round (div direction 0.017453292))
)
(define (circle n)
(set! X 0)
(set! x (round lastX))
(set! y (round lastY))
(set 'direction -1.570796327)
(set! ratio (mul (div 57.29578 n) 2))
(until (and (= x X) (= y (round lastY)))
(set! X (round lastX))
(forward 1)
(right ratio))
)
(define (cercle n)
(set! x (round lastX))
(set! y (round lastY))
(set! lastX (+ x n))
(for (t 0 2 0.005) ;; from 0 to 2 rad
(set! newX (mul n (cos (mul pi t))))
(set! newY (mul n (sin (mul pi t))))
(set! newX (add newX x))
(set! newY (add newY y))
(tk ".kw.canvas create line "
(join (map string (list lastX lastY newX newY)) " ")
" -fill " color)
(set 'lastX newX)
(set 'lastY newY))
(set 'lastX x)
(set 'lastY y)
(round (div direction 0.017453292))
)
(define (rose clr)
(set 'color clr)
(dotimes (x 90)
(pseudo-polygon 4 60)
(right 2))
)
(define (square n)
(dotimes (x 4)
(forward n)
(right 90))
)
(define (squirl n)
(dotimes (x (/ n 3))
(forward n)
(right 90)
(set! n (- n 2)))
(round (div direction 0.017453292))
)
(define (dragon sign level)
(if (= 0 level)
(forward 4)
(begin
(dec 'level)
(right (sign 45))
(dragon - level)
(left (sign 90))
(dragon + level)
(right (sign 45))
)))
(define (dragon-curve n clr)
(set 'color clr)
(dragon + n)
)
(define (right d)
(set 'direction (add direction (mul d 0.017453292)))
(round (div direction 0.017453292)))
(define (left d)
(set 'direction (sub direction (mul d 0.017453292)))
(round (div direction 0.017453292)))
(define (forward d)
(set 'newX (add lastX (mul (cos direction) d)))
(set 'newY (add lastY (mul (sin direction) d)))
(tk ".kw.canvas create line "
(join (map string (list lastX lastY newX newY)) " ")
" -fill " color)
(tk "update idletasks")
(set 'lastX newX)
(set 'lastY newY)
(round (div direction 0.017453292))
)
(define (backward d)
(set! direction (mul -1 direction))
(forward d)
)
(define (pen clr) (set! color (string clr)))
(define (clear) ;; upper left and lower right
(tk ".kw.canvas create rectangle 0 0 "
(join (map string (list width height)) " ")
" -fill black -tag clear")
(center)
)
(define (center)
(set 'lastX (/ width 2))
(set 'lastY (/ height 2))
(set 'direction -1.570796327))
(define (start x y)
(set 'lastX x)
(set 'lastY y)
(set 'direction -1.570796327))
(define (goto x y)
(set 'lastX x)
(set 'lastY y)
(round (div direction 0.017453292))
)
(begin
(set! today (parse (date (apply date-value (now)))))
(println (car today) " " (cadr today) " " (caddr today))
(set! nihongo {\u4e80\u3000\u4f5c\u56f3})
(tk "if {[winfo exists .kw] == 1} {destroy .kw}")
(tk "toplevel .kw")
(tk "canvas .kw.canvas -width " width " -height " height " -bg black")
(tk "pack .kw.canvas")
(tk "wm geometry .kw +290+25")
(tk "wm title .kw { Kame.lsp}")
(tk "bind .kw exit")
(start 50 450)
(squirl 400)
(rose "red")
(tk ".kw.canvas create text 130 380 "
"-fill white -font {Times 22 normal} -text " nihongo)
)
(define (help)
(println "outer inner-angle")
(println "adjacent-cos angle hypo")
(println "adjacent-tan angle opposite")
(println "hypo-sin angle opposite")
(println "hypo-cos angle adjacent")
(println "opposite-sin angle hypo")
(println "opposite-tan angle adjacent")
(println "triangulation side side-size")
(println "rectangular angle radius")
(println "polar x y")
true
)