[MWForum]figure generator follow-up
Jeff Knope
mwforum@lists.mathcats.com
Sat, 4 Jan 2003 10:32:06 -0800
This is a multi-part message in MIME format.
------=_NextPart_000_0005_01C2B3DC.875CD420
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Wow. You guys are waaaay too polite. New to this forum stuff, last =
week I sent off some CAD-like utilities I'd quickly extracted from one =
of my projects, along with the cavilier suggestion you clean it up. I =
soon realized there was zero possibility anybody could actually get it =
to work. Please accept my beet-faced apologies. I truly hope nobody =
spent much hair-pulling time with it. What really amazes me is nobody =
busted me for it.
For penance, I have prepared a cleaned-up stand-alone version, along =
with a setup procedure to get it off on the right footing. It is set up =
to run in the MW default projectsize, with toolbar, console and narrow =
procedures tab exposed. I have used comments at the top of the =
procedures tab to present the menu and notes on its use. So, after you =
copy the entire thing into the procedures tab, run the tabs scroll bar =
clear to the top so you can see the menu and notes.
First, run SETUP from the console. Run it only once. Next, run FIGURE =
from the console. You create a figure with mouseclicks in the graphs =
area. You close both the figure and the FIGURE procedure with a "c" =
keystroke.
You can "donut" a figure with RING :name :num. If you do it immediately =
after creating a figure, use :fig for :name. But realize :fig changes =
with each use of FIGURE or RING. So if you want to be keep a figure (in =
the current session) you should do a: make "somename :fig immediately =
after creating a figure. You can then RING that figure at any time by =
using the name you've given it.
If anybody has any trouble with this whatsoever, please let me know.
; 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=20
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=20
let [key readchar]
if :key =3D "r [make "mode 3] ;rectangular
if :key =3D "d [make "mode 2] ;diagonal
if :key =3D "c [make "mode 4] ;close
if :key =3D "u [make "mode 5] ;undo
end
TO ORTHO=20
if not :fig =3D [] [if and (last mousepos) > -235 :mode =3D 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 =3D 2 [setc 9 setpos last :fig setc :col setpos =
mousepos]]
if :mode =3D 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 =3D 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 =3D [] [setpos :pt pd make "fig lput :pt :fig stop]
if :mode =3D 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 =3D 2 [make "fig lput :pt :fig]
end
TO REPORT=20
ifelse :fig =3D [] [][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 =3D [] [pu stop]
setpos first :fig
DRWFIG bf :fig
end
TO RING :pts :amt=20
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=20
if (count :dastuff) =3D 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=20
if (first :pt) =3D (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
------=_NextPart_000_0005_01C2B3DC.875CD420
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2722.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Wow. You guys are waaaay too =
polite. =20
New to this forum stuff, last week I sent off some CAD-like utilities =
I'd=20
quickly extracted from one of my projects, along with the cavilier=20
suggestion you clean it up. I soon realized there was zero =
possibility=20
anybody could actually get it to work. Please accept my beet-faced =
apologies. I truly hope nobody spent much hair-pulling time =
with=20
it. What really amazes me is nobody busted me for it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>For penance, I have prepared a =
cleaned-up=20
stand-alone version, along with a setup procedure to get it off on the =
right=20
footing. It is set up to run in the MW default projectsize, with =
toolbar,=20
console and narrow procedures tab exposed. I have used comments at =
the top=20
of the procedures tab to present the menu and notes on its =
use. So,=20
after you copy the entire thing into the procedures tab, run the tabs =
scroll bar=20
clear to the top so you can see the menu and notes.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>First, run SETUP from the =
console. Run it=20
only once. Next, run FIGURE from the console. You create a =
figure=20
with mouseclicks in the graphs area. You close both the figure and =
the=20
FIGURE procedure with a "c" keystroke.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>You can "donut" a figure with RING =
:name=20
:num. If you do it immediately after creating a figure, use :fig =
for=20
:name. But realize :fig changes with each use of FIGURE or =
RING. So=20
if you want to be keep a figure (in the current session) you should do =
a:=20
make "somename :fig immediately after creating a figure. You =
can=20
then RING that figure at any time by using the name you've given=20
it.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>If anybody has any trouble with this =
whatsoever,=20
please let me know.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT size=3D2>
<P>; COMMAND MENU:</P>
<P>;*************************</P>
<P>;FIGURE</P>
<P>*******</P>
<P>;Mode Keys:</P>
<P>;"r" rectangular (default)</P>
<P>;"d" diagonal mode</P>
<P>;Option Keys:</P>
<P>;"u" undo last segment</P>
<P>;"c" close</P>
<P>;NOTE: You can change modes 'on-the-fly' while entering a figure with =
mouseclicks.</P>
<P>;NOTE: the last segment is entered automatically when you press "c" =
(close).=20
It closes both the procedure and the figure.</P>
<P>;NOTE: After closing a figure give it a name with: make "somename =
:fig=20
<cr></P>
<P>;NOTE: You can redraw a figure after a "clean" or "cg" with DRAWFIG=20
:somename</P>
<P>;*************************</P>
<P>;RING :somename :num</P>
<P>;***************</P>
<P>;creates a new figure that either circumscribes or inscribes (:num + =
or -)=20
the named figure; :num is the offset in turtlesteps from the named =
figure.</P>
<P> </P>
<P> </P>
<P>TO SETUP</P>
<P>newtext "Xtext [-317 -168][62 22]</P>
<P>set "xtext "showname? "false</P>
<P>newtext "Ytext [-317 -190][62 22]</P>
<P>set "ytext "showname? "false</P>
<P>newtext "label1 [-371 -168][55 44]</P>
<P>set "label1 "text [X dist: Y dist:]</P>
<P>newturtle "cross pu</P>
<P>setbg 9</P>
<P>setc 45</P>
<P>end</P></FONT><FONT face=3D"Courier New" size=3D2>
<P>TO </FONT><FONT size=3D2>FIGURE</FONT><FONT face=3D"Courier New" =
size=3D2> </P>
<P>make "fig []</P>
<P>forever [GETMODE]</P>
<P>tto "cross ht</P>
<P>make "mode 3</P></FONT><FONT size=3D2>
<P>make "col color</P></FONT><FONT face=3D"Courier New" size=3D2>
<P>pu</P>
<P>set "yellow "mouseclick [DOPT]</P>
<P>set "black "mouseclick [DOPT]</P>
<P>forever [REPORT]</P>
<P>ORTHO</P>
<P>set "yellow "mouseclick []</P>
<P>set "black "mouseclick []</P>
<P>cancel [GETMODE]</P>
<P>pu</P>
<P>end</P>
<P>TO GETMODE </P>
<P>let [key readchar]</P>
<P>if :key =3D "r [make "mode 3] ;rectangular</P>
<P>if :key =3D "d [make "mode 2] ;diagonal</P>
<P>if :key =3D "c [make "mode 4] ;close</P>
<P>if :key =3D "u [make "mode 5] ;undo</P>
<P>end</P>
<P>TO ORTHO </P>
<P>if not :fig =3D [] [if and (last mousepos) > -235 :mode =3D 3 =
[make "x (first=20
mousepos) - (first last :fig) make "y (last mousepos) - (last last :fig) =
ifelse=20
(abs :x) > (abs :y) [pd setc 9 setpos last :fig setc :col setx first =
mousepos=20
sety last last :fig][pd setc 9 setpos last :fig setc :col sety last =
mousepos=20
setx first last :fig]] if and (last mousepos) > -235 :mode =3D 2 =
[setc 9 setpos=20
last :fig setc :col setpos mousepos]]</P>
<P>if :mode =3D 4 [setc 9 setpos last :fig setc :col setpos first :fig =
make "fig=20
lput first :fig :fig</FONT><FONT size=3D2> cancel [REPORT] setc 9 setpos =
mousepos=20
setpos last :fig setc :col DRAWFIG :fig pu</FONT><FONT face=3D"Courier =
New"=20
size=3D2> </FONT><FONT size=3D2>stop</FONT><FONT face=3D"Courier New" =
size=3D2>]</P>
<P>if :mode =3D 5 [ifelse (count :fig) > 1 [setc 9 setpos last :fig =
pd setpos=20
last bl :fig make "fig bl :fig make "mode 1 waituntil [:mode > =
1]][make "fig=20
[] pu make "mode 3]]</P>
<P>ORTHO</P>
<P>end</P>
<P>TO DOPT</P>
<P>make "pt mousepos</P>
<P>if :fig =3D [] [setpos :pt pd make "fig lput :pt :fig stop]</P>
<P>if :mode =3D 3 [ifelse (abs :x) > (abs :y) [make "fig lput list =
(first :pt)=20
(last last :fig) :fig] [make "fig lput list (first last :fig) (last :pt) =
:fig]]</P>
<P>if :mode =3D 2 [make "fig lput :pt :fig]</P>
<P>end</P>
<P>TO REPORT </P>
<P>ifelse :fig =3D [] [][make "xdist (abs(first last :fig) - (first =
mousepos)) set=20
"Xtext "text (word (int :xdist / 6) "' "- round (((:xdist / 6) - int =
(:xdist /=20
6)) * 12) "") make "ydist (abs(last last :fig) - (last mousepos)) set =
"Ytext=20
"text (word (int :ydist / 6) "' "- round (((:ydist / 6) - int (:ydist / =
6)) *=20
12) "")]</P>
<P>end</P>
<P>TO DRAWFIG :fig</P>
<P>pu setpos first :fig pd</P>
<P>DRWFIG bf :fig</P>
<P>END</P>
<P>TO DRWFIG :fig</P>
<P>if :fig =3D [] [pu stop]</P>
<P>setpos first :fig</P>
<P>DRWFIG bf :fig</P>
<P>end</P>
<P>TO RING :pts :amt </P>
<P>pu</P>
<P>make "daring []</P>
<P>make "dastuff fput last bl :pts :pts</P>
<P>RNG :dastuff :amt</P>
<P>make "daring lput first :daring :daring</P>
<P>DRAWFIG :daring</P>
<P>end</P>
<P>TO RNG :dastuff :amt </P>
<P>if (count :dastuff) =3D 2 [stop]</P>
<P>ANG (list first :dastuff first bf :dastuff first bf bf :dastuff)</P>
<P>lt (:ang / 2) fd (:amt * (1 / sin (:ang / 2))) make "daring lput pos=20
:daring</P>
<P>RNG bf :dastuff :amt</P>
<P>end</P></FONT><FONT size=3D2></FONT><FONT face=3D"Courier New" =
size=3D2>
<P>TO ANG :pts</P>
<P>local [hdga hdgb]</P>
<P>setpos first bf :pts</P>
<P>TOWARD first :pts make "hdga heading</P>
<P>TOWARD last :pts make "hdgb heading</P>
<P>ifelse :hdgb > :hdga [make "ang :hdgb - :hdga][make "ang :hdgb + =
360 -=20
:hdga]</P>
<P>end</P></FONT><FONT size=3D2></FONT><FONT face=3D"Courier New" =
size=3D2>
<P>TO TOWARD :pt </P>
<P>if (first :pt) =3D (first pos) [ifelse (last :pt) > (last pos) =
[seth 0=20
stop][seth 180 stop]];;;no divide by 0</P>
<P>make "slp ((last :pt) - (last pos)) / ((first :pt) - (first pos))</P>
<P>ifelse (first :pt) > (first pos) [seth minus ((arctan :slp) - 90)] =
[seth=20
minus ((arctan :slp) + 90)]</P>
<P>end</P></FONT><FONT size=3D2></FONT></DIV></BODY></HTML>
------=_NextPart_000_0005_01C2B3DC.875CD420--