; COMMAND MENU:
;*************************
;FIGURE
*******
;Mode Keys:
;"r" rectangular (default)
;"d" diagonal mode
;Option Keys:
;"u" undo last segment
;"c" close
;NOTE: You can change modes 'on-the-fly' while entering a figure with
mouseclicks.
;NOTE: the last segment is entered automatically when you press "c" (close).
It closes both the procedure and the figure.
;NOTE: After closing a figure give it a name with: make "somename :fig
<cr>
;NOTE: You can redraw a figure after a "clean" or "cg" with DRAWFIG
:somename
;*************************
;RING :somename :num
;***************
;creates a new figure that either circumscribes or inscribes (:num + or
-)
the named figure; :num is the offset in turtlesteps from the named figure.
TO SETUP
newtext "Xtext [-317 -168][62 22]
set "xtext "showname? "false
newtext "Ytext [-317 -190][62 22]
set "ytext "showname? "false
newtext "label1 [-371 -168][55 44]
set "label1 "text [X dist: Y dist:]
newturtle "cross pu
setbg 9
setc 45
end
TO
FIGURE
make "fig []
forever [GETMODE]
tto "cross ht
make "mode 3
make "col color
pu
set "yellow "mouseclick [DOPT]
set "black "mouseclick [DOPT]
forever [REPORT]
ORTHO
set "yellow "mouseclick []
set "black "mouseclick []
cancel [GETMODE]
pu
end
TO GETMODE
let [key readchar]
if :key = "r [make "mode 3] ;rectangular
if :key = "d [make "mode 2] ;diagonal
if :key = "c [make "mode 4] ;close
if :key = "u [make "mode 5] ;undo
end
TO ORTHO
if not :fig = [] [if and (last mousepos) > -235 :mode = 3 [make "x
(first
mousepos) - (first last :fig) make "y (last mousepos) - (last last :fig)
ifelse
(abs :x) > (abs :y) [pd setc 9 setpos last :fig setc :col setx first
mousepos
sety last last :fig][pd setc 9 setpos last :fig setc :col sety last mousepos
setx first last :fig]] if and (last mousepos) > -235 :mode = 2 [setc 9
setpos
last :fig setc :col setpos mousepos]]
if :mode = 4 [setc 9 setpos last :fig setc :col setpos first :fig make
"fig
lput first :fig :fig
cancel [REPORT] setc 9 setpos
mousepos
setpos last :fig setc :col DRAWFIG :fig pu stop]
if :mode = 5 [ifelse (count :fig) > 1 [setc 9 setpos last :fig pd
setpos
last bl :fig make "fig bl :fig make "mode 1 waituntil [:mode > 1]][make
"fig
[] pu make "mode 3]]
ORTHO
end
TO DOPT
make "pt mousepos
if :fig = [] [setpos :pt pd make "fig lput :pt :fig stop]
if :mode = 3 [ifelse (abs :x) > (abs :y) [make "fig lput list (first
:pt)
(last last :fig) :fig] [make "fig lput list (first last :fig) (last :pt)
:fig]]
if :mode = 2 [make "fig lput :pt :fig]
end
TO REPORT
ifelse :fig = [] [][make "xdist (abs(first last :fig) - (first mousepos))
set
"Xtext "text (word (int :xdist / 6) "' "- round (((:xdist / 6) - int (:xdist
/
6)) * 12) "") make "ydist (abs(last last :fig) - (last mousepos)) set "Ytext
"text (word (int :ydist / 6) "' "- round (((:ydist / 6) - int (:ydist / 6))
*
12) "")]
end
TO DRAWFIG :fig
pu setpos first :fig pd
DRWFIG bf :fig
END
TO DRWFIG :fig
if :fig = [] [pu stop]
setpos first :fig
DRWFIG bf :fig
end
TO RING :pts :amt
pu
make "daring []
make "dastuff fput last bl :pts :pts
RNG :dastuff :amt
make "daring lput first :daring :daring
DRAWFIG :daring
end
TO RNG :dastuff :amt
if (count :dastuff) = 2 [stop]
ANG (list first :dastuff first bf :dastuff first bf bf :dastuff)
lt (:ang / 2) fd (:amt * (1 / sin (:ang / 2))) make "daring lput pos
:daring
RNG bf :dastuff :amt
end
TO ANG :pts
local [hdga hdgb]
setpos first bf :pts
TOWARD first :pts make "hdga heading
TOWARD last :pts make "hdgb heading
ifelse :hdgb > :hdga [make "ang :hdgb - :hdga][make "ang :hdgb + 360 -
:hdga]
end
TO TOWARD :pt
if (first :pt) = (first pos) [ifelse (last :pt) > (last pos) [seth 0
stop][seth 180 stop]];;;no divide by 0
make "slp ((last :pt) - (last pos)) / ((first :pt) - (first pos))
ifelse (first :pt) > (first pos) [seth minus ((arctan :slp) - 90)]
[seth
minus ((arctan :slp) + 90)]
end