#!/bin/sh # MetaCard 2.4 stack # The following is not ASCII text, # so now would be a good time to q out of more exec mc $0 "$@" x StopTurtles 7local x,y,angles,penDown,gPoints,labelCount,tName global radPerDeg,degPerRad local x0,y0 function convertLinesTurtleToMouse tLines repeat for each line tLine in tLines put item 1 of tLine into theX put item 2 of tLine into theY put round(x0 + theX)& comma& round(y0- theY) & return after results end repeat return results end convertLinesTurtleToMouse function convertLinesMouseToTurtle tLines repeat for each line tLine in tLines put item 1 of tLine into theX put item 2 of tLine into theY put round(theX-x0)& comma & round(y0 - theY) & return after results end repeat return results end convertLinesMouseToTurtle --on setColor tColor -- set the forecolor of grc tName to tColor --end setColor on startTurtle tName if tName is empty then put "turtle" into tName --lock messages put true into penDown -- put pi/180 into radPerDeg -- put 180/pi into degPerRad put round(the the width of this card /2) into x0 put round(the height of this card /2) into y0 put x0&comma&y0 & return into gPoints put 0 into x put 0 into y put 0 into angles put 0 into labelCount if there is no graphic tName then set the style of the templateGraphic to "line" create graphic tName end if --set the endArrow of graphic tName to false -- clean tName --unlock messages end startTurtle on startT temp startTurtle temp end startT on st temp startTurtle temp end st function ext pointList,d put the number of lines in pointList into n put line n - 1 of pointlist into pt1 put line n of pointList into pt2 put extension(pt1,pt2,d) into line n+1 of pointList -- put pointList & return into field "data" return pointList end ext function extension p1,p2,d repeat with i = 1 to 2 put param(i) into p[i] put item 1 of p[i] into x[i] put item 2 of p[i] into y[i] end repeat put atan2(y[2]-y[1] , x[2]-x[1]) into a put x[2] + d* cos(a) into x[3] put y[2] + d* sin(a) into y[3] put round(x[3]),round(y[3]) into tPt return tPt end extension on label inputText lock screen put the tool into tTool choose the browse tool set the textstyle of the templateField to "bold" set the style of the templateField to "transparent" set the textAlign of templateField to center put "fieldLabel" &tName& labelCount into nField if there is no field nField then create field nField add 1 to labelCount put inputText into field nField set the loc of field nField to turtlePtToMousePt(xycor()) set the width of field nField to the formattedwidth of field nField set the height of field nField to the formattedHeight of field nField set the tool to tTool unlock screen end label on stopTurtle tName --put tName&"Turtle" into tName set the points of graphic tName to gPoints --unlock screen end stopTurtle on stopT tName stopturtle tName end stopT on home setxy 0,0 end home on right temp subtract temp from angles end right on rt temp right temp end rt on left a add a to angles end left on lt a left a end lt on ffd temp forward temp end ffd on incXY dx,dy --if penDown then put round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints if penDown then put round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints else put return & round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints end if add dx to x add dy to y --create graphic tName -- set the points of graphic "myGraphic" to gPoints end incXY on setxy xnew,ynew get the paramCount if it = 1 then put item 2 of xnew into ynew put item 1 of xnew into xnew end if if penDown then put round(x0+xnew)&comma&round(y0 - ynew)& return after gPoints else put return & round(x0 + xnew)&comma&round(y0 - ynew)& return after gPoints end if put xnew into x put ynew into y --create graphic tName -- set the points of graphic "myGraphic" to gPoints end setxy on setRA rr,aa put rr*cosine(aa) into x put rr*Sine(aa) into y setXY x,y end setRA function distance xtemp,ytemp get the paramCount if it = 1 then put item 2 of xtemp into ytemp put item 1 of xtemp into xtemp end if return sqrt ((x-xtemp)^2 + (y-ytemp)^2) end distance function xycor return round(x) & comma & round(y) end xycor function xcor return x end xcor function ycor return y end ycor on pu put false into penDown end pu on penUp pu end penUp on penDown pd end penDown on pd put true into penDown end pd on forward distance put distance * cos(radPerDeg * angles) into dx put distance * sin(radPerDeg * angles) into dy --if penDown then drag from round(x0 + x),round(y0 - y) to round(x0 + x + dx), round(y0 - y - dy) add dx to x add dy to y if penDown then put round(x+x0)&comma&round(-y+y0)& return after gPoints else put return & round(x+x0)&comma&round(-y+y0)& return after gPoints end if -- set the points of graphic "myGraphic" to gPoints --put gPoints into field "points" end forward on seth temp put temp into angles end seth on bk temp fd - temp end bk on back temp bk temp end back function heading repeat while angles>360 subtract 360 from angles end repeat repeat while angles < 0 add 360 to angles end repeat return angles end heading function toward xTemp,yTemp return direction (xTemp,yTemp) end toward function direction xtemp,ytemp get the paramCount if it is 1 then put item 2 of xtemp into ytemp put item 1 of xtemp into xtemp end if put ytemp - y into dy put xtemp - x into dx if dx = 0 then if dy > 0 then return 90 else return 90 + 180 end if if dy = 0 then if dx > 0 then return 0 else return 180 end if put degPerRad * atan(abs(dy) / abs(dx)) into angl if dy > 0 then if dx > 0 then return angl else return 180 - angl end if if dx > 0 then return 360 - angl else return 180 + angl end if end direction on setHome xx,yy get the paramCount if it is 1 then put item 2 of xx into yy put item 1 of xx into xx end if put round((the width of this card)/2 + xx) into x0 put round((the height of this card)/2 - yy) into y0 put x0&comma&y0 & return into gPoints end setHome on st startTurtle end st on fd temp forward temp end fd on ct put empty into field 1 end ct on cleartext ct end cleartext on pr t put t& return after field 1 end pr on clean tName -- repeat while the number of images > 0 -- delete image 1 -- end repeat -- put "eyeball" into tSaveList -- put 1 into i -- set the points of graphic tName&"Turtle" to "" -- repeat number of graphics -- if the short name of graphic i is not in tSaveList then -- delete graphic i -- next repeat -- else add 1 to i -- end repeat -- repeat with i = the number of fields down to 1 -- if "label" is in the short name of field i then delete field i -- end repeat end clean on cleanAllGraphics repeat the number of graphics delete graphic 1 end repeat end cleanAllGraphics on cleanG tGraphic get the paramcount switch it case 1 repeat with i = the number of graphics down to 1 if tGraphic is in the short name of grc i then --set the points of grc tName to "" --delete grc i --put "" into gPoints put x0&comma&y0 & return into gPoints put 0 into x put 0 into y end if end repeat break case 0 repeat with i = the number of graphics down to 1 --delete grc i set the points of grc i to "" end repeat break end switch end cleanG on cleanGraphics temp cleanG temp end cleanGraphics on cleanL tLabel get the paramcount switch it case 1 repeat with i = the number of fields down to 1 if tLabel is in the short name of field i then delete field i end repeat break case 0 repeat with i = the number of fields down to 1 if "label" is in the short name of field i then delete field i end repeat break end switch end cleanL on cleanLabel temp cleanL temp end cleanLabel on cleanPts put empty into gPoints end cleanPts on centeredCircle r put the tool into savedTool choose the oval tool set the centered to true drag from round(x0+x),round(y0-y) to round(x0+x+r),round(y0-y-r) set the centered to false choose the savedTool end centeredCircle function mousePtToTurtlePt theX,theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if --sethome 0,0 put round(theX-x0) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end mousePtToTurtlePt function mpttp pt return mousePtToTurtlePt(pt) end mpttp function tptmp pt return turtlePtToMousePt(pt) end tptmp function mt theX, theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if -- sethome 0,0 put round(theX-x0) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end mt function mpttp theX,theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if sethome 0,0 put round(theX-x0) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end mpttp function tptmp theX,theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if put round(x0 + theX) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end tptmp function turtlePtToMousePt theX, theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if put round(x0 + theX) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end turtlePtToMousePt function tm theX,theY get the paramcount if it is 1 then put item 2 of theX into theY put item 1 of theX into theX end if put round(x0 + theX) into item 1 of temp put round(y0 - theY) into item 2 of temp return temp end tm function log x return ln(x)/ln(10) end log function sine a return sin(pi/180*a) end sine function cosine a return cos(radPerDeg*a) end cosine function tangent a return tan(radPerDeg*a) end tangent function arcSine temp return 180/pi* asin(temp) end arcSine function arcCos temp return degPerRad* acos(temp) end arcCos function arcTan temp return degPerRad* atan(temp) end arcTan function fact n put 1 into results repeat with i = 1 to n multiply results by i end repeat return results end fact function randomInRange b,t return random(t-b+1) + b-1 end randomInRange function commaFormat tNum put tNum mod 1 into remainder delete char 1 of remainder put trunc(tNum) into tNum put the Number of chars in tNum into n repeat with i = 1 to trunc((n-1)/3) put comma after char n - 3*i of tNum end repeat return tNum& remainder end commaformat function clickPoint set the cursor to cross wait until mouseClick() --Wait for the mouse click. return mousePtToTurtlePt(mouseLoc()) --Return the mouse coordinates converted to turtle coordinates. end clickPoint function intersection p1,p2,p1',p2' put the paramCount into tCount if tCount is 2 then put line 1 of p2 into p1' put line 2 of p2 into p2' put line 2 of p1 into p2 put line 1 of p1 into p1 end if put item 1 of p1 into x1 put item 2 of p1 into y1 put item 1 of p2 into x2 put item 2 of p2 into y2 if x1<> x2 then put x2-x1 into dx else put .00001 into dx put y2-y1 into dy put dy/dx into m put y1-m*x1 into b put item 1 of p1' into x1' put item 2 of p1' into y1' put item 1 of p2' into x2' put item 2 of p2' into y2' if x1'<> x2' then put x2'-x1' into dx' else put .00001 into dx' put y2'-y1' into dy' put dy'/dx' into m' if m' = m then add .00001 to m' put y1'-m'*x1' into b' put (b-b')/(m'-m) into x put m*x+b into y return x,y end intersection on functionKey tKey switch tKey case 8 if the tool is "browse tool" then choose the pointer tool else choose the browse tool end if break case 2 edit the script of this stack break case 3 edit the script of this card break case 5 go to next card break case 4 go to previous card break case 6 ct break end switch end functionKey --on openstack -- set the grid to false -- set the alwaysbuffer of this stack to true --end openstack -- --on openStack -- insert the script of me into back -- --hide stack "SmallPlugIn" --end openStack on myFind tWord put the number of fields into nFields repeat with i =1 to nFields put field i into tText if tWord is in tText then put wordoffset(tWord,tText)into tWordNum select word tWordNum in field i put the formattedtext of field i into tText replace return&return with return in tText put lineOffset(tWord,tText) into tLineNum put the effective textHeight of field i into tHeight set the scroll of field i to (tLineNum-1) * (tHeight) wait until the mouseClick else beep end if end repeat choose the browse tool end myFind on getFile answer file "What file" if it is not empty then put it into tFileName put "file:" & tFileName into tFileName get url tFileName put it into field 1 else exit getFile end getFile on putField ask "What field to save?" if it is not empty then put field it into tContents else put field 1 into tContents ask file "Put where?" if it is not empty then put "file:"& it into tFileName put tContents into url tFileName else beep exit putField end if end putField on preopenstack set the style of this stack to "toplevel" put pi/180 into radPerDeg put 180/pi into degPerRad put round(the the width of this card /2) into x0 put round(the height of this card /2) into y0 end preopenstack on tabKey if controlkey() = "down" then if the tool = "pointer tool" then choose browse tool else choose pointer tool else pass tabKey end tabKey lsm revstack false W Geneva U Geneva U Geneva U Lucida Grande U Geneva U Geneva W Lucida Grande W Lucida Grande W Lucida Grande cREVGeometryCache stackID 2424 cREVGeneral scriptChecksum QvY debugObjects :button id 2347 of card id 2352 of stack "StartStopTurtles"breakPoints handlerList HconvertLinesTurtleToMouse convertLinesMouseToTurtle startTurtle startT st ext extension label stopTurtle stopT home right rt left lt ffd incXY setxy setRA distance xycor xcor ycor pu penUp penDown pd forward seth bk back heading toward direction setHome st fd ct cleartext pr clean cleanAllGraphics cleanG cleanGraphics cleanL cleanLabel cleanPts centeredCircle mousePtToTurtlePt mpttp tptmp mt mpttp tptmp turtlePtToMousePt tm log sine cosine tangent arcSine arcCos arcTan fact randomInRange commaFormat clickPoint intersection functionKey myFind getFile putField preopenstack tabKeyscriptSelection char 12073 to 12072 bookmarks tempScript prevHandler intersectionscript e
local x,y,angles,penDown,gPoints,labelCount,tName
global radPerDeg,degPerRad
local x0,y0
function convertLinesTurtleToMouse tLines
repeat for each line tLine in tLines
put item 1 of tLine into theX
put item 2 of tLine into theY
put round(x0 + theX)& comma& round(y0- theY) & return after results
end repeat
return results
end convertLinesTurtleToMouse
function convertLinesMouseToTurtle tLines
repeat for each line tLine in tLines
put item 1 of tLine into theX
put item 2 of tLine into theY
put round(theX-x0)& comma & round(y0 - theY) & return after results
end repeat
return results
end convertLinesMouseToTurtle
--on setColor tColor
-- set the forecolor of grc tName to tColor
--end setColor
on startTurtle tName
if tName is empty then put "turtle" into tName
--lock messages
put true into penDown
-- put pi/180 into radPerDeg
-- put 180/pi into degPerRad
put round(the the width of this card /2) into x0
put round(the height of this card /2) into y0
put x0&comma&y0 & return into gPoints
put 0 into x
put 0 into y
put 0 into angles
put 0 into labelCount
if there is no graphic tName then
set the style of the templateGraphic to "line"
create graphic tName
end if
--set the endArrow of graphic tName to false
-- clean tName
--unlock messages
end startTurtle
on startT temp
startTurtle temp
end startT
on st temp
startTurtle temp
end st
function ext pointList,d
put the number of lines in pointList into n
put line n - 1 of pointlist into pt1
put line n of pointList into pt2
put extension(pt1,pt2,d) into line n+1 of pointList
-- put pointList & return into field "data"
return pointList
end ext
function extension p1,p2,d
repeat with i = 1 to 2
put param(i) into p[i]
put item 1 of p[i] into x[i]
put item 2 of p[i] into y[i]
end repeat
put atan2(y[2]-y[1] , x[2]-x[1]) into a
put x[2] + d* cos(a) into x[3]
put y[2] + d* sin(a) into y[3]
put round(x[3]),round(y[3]) into tPt
return tPt
end extension
on label inputText
lock screen
put the tool into tTool
choose the browse tool
set the textstyle of the templateField to "bold"
set the style of the templateField to "transparent"
set the textAlign of templateField to center
put "fieldLabel" &tName& labelCount into nField
if there is no field nField then create field nField
add 1 to labelCount
put inputText into field nField
set the loc of field nField to turtlePtToMousePt(xycor())
set the width of field nField to the formattedwidth of field nField
set the height of field nField to the formattedHeight of field nField
set the tool to tTool
unlock screen
end label
on stopTurtle tName
--put tName&"Turtle" into tName
set the points of graphic tName to gPoints
--unlock screen
end stopTurtle
on stopT tName
stopturtle tName
end stopT
on home
setxy 0,0
end home
on right temp
subtract temp from angles
end right
on rt temp
right temp
end rt
on left a
add a to angles
end left
on lt a
left a
end lt
on ffd temp
forward temp
end ffd
on incXY dx,dy
--if penDown then put round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints
if penDown
then
put round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints
else
put return & round (x0 +x +dx) &comma &round(y0 -y - dy)& return after gPoints
end if
add dx to x
add dy to y
--create graphic tName
-- set the points of graphic "myGraphic" to gPoints
end incXY
on setxy xnew,ynew
get the paramCount
if it = 1 then
put item 2 of xnew into ynew
put item 1 of xnew into xnew
end if
if penDown
then
put round(x0+xnew)&comma&round(y0 - ynew)& return after gPoints
else
put return & round(x0 + xnew)&comma&round(y0 - ynew)& return after gPoints
end if
put xnew into x
put ynew into y
--create graphic tName
-- set the points of graphic "myGraphic" to gPoints
end setxy
on setRA rr,aa
put rr*cosine(aa) into x
put rr*Sine(aa) into y
setXY x,y
end setRA
function distance xtemp,ytemp
get the paramCount
if it = 1 then
put item 2 of xtemp into ytemp
put item 1 of xtemp into xtemp
end if
return sqrt ((x-xtemp)^2 + (y-ytemp)^2)
end distance
function xycor
return round(x) & comma & round(y)
end xycor
function xcor
return x
end xcor
function ycor
return y
end ycor
on pu
put false into penDown
end pu
on penUp
pu
end penUp
on penDown
pd
end penDown
on pd
put true into penDown
end pd
on forward distance
put distance * cos(radPerDeg * angles) into dx
put distance * sin(radPerDeg * angles) into dy
--if penDown then drag from round(x0 + x),round(y0 - y) to round(x0 + x + dx), round(y0 - y - dy)
add dx to x
add dy to y
if penDown
then
put round(x+x0)&comma&round(-y+y0)& return after gPoints
else
put return & round(x+x0)&comma&round(-y+y0)& return after gPoints
end if
-- set the points of graphic "myGraphic" to gPoints
--put gPoints into field "points"
end forward
on seth temp
put temp into angles
end seth
on bk temp
fd - temp
end bk
on back temp
bk temp
end back
function heading
repeat while angles>360
subtract 360 from angles
end repeat
repeat while angles < 0
add 360 to angles
end repeat
return angles
end heading
function toward xTemp,yTemp
return direction (xTemp,yTemp)
end toward
function direction xtemp,ytemp
get the paramCount
if it is 1 then
put item 2 of xtemp into ytemp
put item 1 of xtemp into xtemp
end if
put ytemp - y into dy
put xtemp - x into dx
if dx = 0 then
if dy > 0 then return 90
else return 90 + 180
end if
if dy = 0 then
if dx > 0 then return 0
else return 180
end if
put degPerRad * atan(abs(dy) / abs(dx)) into angl
if dy > 0 then
if dx > 0 then return angl
else return 180 - angl
end if
if dx > 0 then
return 360 - angl
else
return 180 + angl
end if
end direction
on setHome xx,yy
get the paramCount
if it is 1 then
put item 2 of xx into yy
put item 1 of xx into xx
end if
put round((the width of this card)/2 + xx) into x0
put round((the height of this card)/2 - yy) into y0
put x0&comma&y0 & return into gPoints
end setHome
on st
startTurtle
end st
on fd temp
forward temp
end fd
on ct
put empty into field 1
end ct
on cleartext
ct
end cleartext
on pr t
put t& return after field 1
end pr
on clean tName
-- repeat while the number of images > 0
-- delete image 1
-- end repeat
-- put "eyeball" into tSaveList
-- put 1 into i
-- set the points of graphic tName&"Turtle" to ""
-- repeat number of graphics
-- if the short name of graphic i is not in tSaveList then
-- delete graphic i
-- next repeat
-- else add 1 to i
-- end repeat
-- repeat with i = the number of fields down to 1
-- if "label" is in the short name of field i then delete field i
-- end repeat
end clean
on cleanAllGraphics
repeat the number of graphics
delete graphic 1
end repeat
end cleanAllGraphics
on cleanG tGraphic
get the paramcount
switch it
case 1
repeat with i = the number of graphics down to 1
if tGraphic is in the short name of grc i then
--set the points of grc tName to "" --delete grc i
--put "" into gPoints
put x0&comma&y0 & return into gPoints
put 0 into x
put 0 into y
end if
end repeat
break
case 0
repeat with i = the number of graphics down to 1
--delete grc i
set the points of grc i to ""
end repeat
break
end switch
end cleanG
on cleanGraphics temp
cleanG temp
end cleanGraphics
on cleanL tLabel
get the paramcount
switch it
case 1
repeat with i = the number of fields down to 1
if tLabel is in the short name of field i then delete field i
end repeat
break
case 0
repeat with i = the number of fields down to 1
if "label" is in the short name of field i then delete field i
end repeat
break
end switch
end cleanL
on cleanLabel temp
cleanL temp
end cleanLabel
on cleanPts
put empty into gPoints
end cleanPts
on centeredCircle r
put the tool into savedTool
choose the oval tool
set the centered to true
drag from round(x0+x),round(y0-y) to round(x0+x+r),round(y0-y-r)
set the centered to false
choose the savedTool
end centeredCircle
function mousePtToTurtlePt theX,theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
--sethome 0,0
put round(theX-x0) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end mousePtToTurtlePt
function mpttp pt
return mousePtToTurtlePt(pt)
end mpttp
function tptmp pt
return turtlePtToMousePt(pt)
end tptmp
function mt theX, theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
-- sethome 0,0
put round(theX-x0) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end mt
function mpttp theX,theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
sethome 0,0
put round(theX-x0) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end mpttp
function tptmp theX,theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
put round(x0 + theX) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end tptmp
function turtlePtToMousePt theX, theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
put round(x0 + theX) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end turtlePtToMousePt
function tm theX,theY
get the paramcount
if it is 1 then
put item 2 of theX into theY
put item 1 of theX into theX
end if
put round(x0 + theX) into item 1 of temp
put round(y0 - theY) into item 2 of temp
return temp
end tm
function log x
return ln(x)/ln(10)
end log
function sine a
return sin(pi/180*a)
end sine
function cosine a
return cos(radPerDeg*a)
end cosine
function tangent a
return tan(radPerDeg*a)
end tangent
function arcSine temp
return 180/pi* asin(temp)
end arcSine
function arcCos temp
return degPerRad* acos(temp)
end arcCos
function arcTan temp
return degPerRad* atan(temp)
end arcTan
function fact n
put 1 into results
repeat with i = 1 to n
multiply results by i
end repeat
return results
end fact
function randomInRange b,t
return random(t-b+1) + b-1
end randomInRange
function commaFormat tNum
put tNum mod 1 into remainder
delete char 1 of remainder
put trunc(tNum) into tNum
put the Number of chars in tNum into n
repeat with i = 1 to trunc((n-1)/3)
put comma after char n - 3*i of tNum
end repeat
return tNum& remainder
end commaformat
function clickPoint
set the cursor to cross
wait until mouseClick() --Wait for the mouse click.
return mousePtToTurtlePt(mouseLoc()) --Return the mouse coordinates converted to turtle coordinates.
end clickPoint
function intersection p1,p2,p1',p2'
put the paramCount into tCount
if tCount is 2 then
put line 1 of p2 into p1'
put line 2 of p2 into p2'
put line 2 of p1 into p2
put line 1 of p1 into p1
end if
put item 1 of p1 into x1
put item 2 of p1 into y1
put item 1 of p2 into x2
put item 2 of p2 into y2
if x1<> x2 then
put x2-x1 into dx
else put .00001 into dx
put y2-y1 into dy
put dy/dx into m
put y1-m*x1 into b
put item 1 of p1' into x1'
put item 2 of p1' into y1'
put item 1 of p2' into x2'
put item 2 of p2' into y2'
if x1'<> x2' then
put x2'-x1' into dx'
else put .00001 into dx'
put y2'-y1' into dy'
put dy'/dx' into m'
if m' = m then add .00001 to m'
put y1'-m'*x1' into b'
put (b-b')/(m'-m) into x
put m*x+b into y
return x,y
end intersection
on functionKey tKey
switch tKey
case 8
if the tool is "browse tool" then
choose the pointer tool
else
choose the browse tool
end if
break
case 2
edit the script of this stack
break
case 3
edit the script of this card
break
case 5
go to next card
break
case 4
go to previous card
break
case 6
ct
break
end switch
end functionKey
--on openstack
-- set the grid to false
-- set the alwaysbuffer of this stack to true
--end openstack
--
--on openStack
-- insert the script of me into back
-- --hide stack "SmallPlugIn"
--end openStack
on myFind tWord
put the number of fields into nFields
repeat with i =1 to nFields
put field i into tText
if tWord is in tText then
put wordoffset(tWord,tText)into tWordNum
select word tWordNum in field i
put the formattedtext of field i into tText
replace return&return with return in tText
put lineOffset(tWord,tText) into tLineNum
put the effective textHeight of field i into tHeight
set the scroll of field i to (tLineNum-1) * (tHeight)
wait until the mouseClick
else
beep
end if
end repeat
choose the browse tool
end myFind
on getFile
answer file "What file"
if it is not empty then
put it into tFileName
put "file:" & tFileName into tFileName
get url tFileName
put it into field 1
else exit getFile
end getFile
on putField
ask "What field to save?"
if it is not empty then
put field it into tContents
else put field 1 into tContents
ask file "Put where?"
if it is not empty then
put "file:"& it into tFileName
put tContents into url tFileName
else
beep
exit putField
end if
end putField
on preopenstack
set the style of this stack to "toplevel"
put pi/180 into radPerDeg
put 180/pi into degPerRad
put round(the the width of this card /2) into x0
put round(the height of this card /2) into y0
end preopenstack
on tabKey
if controlkey() = "down" then
if the tool = "pointer tool"
then choose browse tool
else choose pointer tool
else pass tabKey
end tabKey
Poon drawSpring L,N,s,springAngle,curvature --lock screen startTurtle "spring" put L/N/2 into dy -- Vertical separation of coils if 2*N*s < L then answer "Can't stretch spring this far." exit to top end if put arcsine(dy/s) into tAngle --Coil angle seth tAngle - springAngle fd s/2 put 180 - 2*tAngle into da repeat (N-1) times left da fd s right da+curvature --Curvature of spring fd s end repeat left da fd s right da+curvature fd s/2 put xyCor() into tLoc put turtlePtToMousePt(tLoc) into tLoc stopturtle "spring" --unlock screen end drawSpring sm cREVGeometryCacheIDs 1120261697661 22221120421819616 22981120259350941 22141120259374789 22151120260960754 22191120509058509 23801120261002581 22211120259376988 22161120260915272 22181120421234298 22961120421149303 22911120260613200 22171120258650085 22071120260987960 22201120422079352 22991120258960767 2212 cREVGeometrycache order total 16 cREVGeneral bookmarks handlerList drawSpringtempScript prevHandler drawSpringscript L i @ sm springConstant 0.008 friction 0.006 cREVGeometryCacheIDs 1120263772746 22241120421211964 22921120508488373 23781120263772715 22231120263772834 22261120410113441 22391120507149666 23761120263772792 22251120178507163 21541120257500973 22051120187698180 21701120318682725 22321120424883607 2318 cREVGeometryCache total 13order cREVGeneral z j H J P@on preopencard set the loc of button "platform" to 411,443 set the loc of grc "spring" to 412,447 hide field "message" drawSpring 2,20,20 set the bottom of img "manWorking.png" to the top of button "platform" end preopencard on drawSpring L,N,s startTurtle "spring" pu setHome -30,-140 pd put L/N/2 into dy put arcsine(dy/s) into tAngle seth tAngle fd s/2 put 180 - 2*tAngle into da repeat (N-1) times left da fd s right da fd s end repeat left 180 - 2*tAngle fd s right da fd s/2 stopturtle "spring" end drawSpring sm cREVGeneral bookmarks handlerList preopencard drawSpringprevHandler drawSpringtempScript script cREVGeometryCacheIDs 1120229733011 21941120229678112 21921120230546963 21961120421214952 22931120227957016 21911120229732923 21931120229854629 21951120234551560 22011120236232627 2203 cREVGeometryCache total 9order Pon preopencard send "mouseUP" to button "reset Jack" end preopencard on drawSpring L,N,s,springAngle,curvature --lock screen startTurtle "spring" pu setHome -30,-200 pd put L/N/2 into dy if 2*N*s < L then answer "Can't stretch spring this far." exit to top end if put arcsine(dy/s) into tAngle seth tAngle - springAngle fd s/2 put 180 - 2*tAngle into da repeat (N-1) times left da fd s right da+curvature --Curvature of spring fd s end repeat left da fd s right da+curvature fd s/2 put xyCor() into tLoc put turtlePtToMousePt(tLoc) into tLoc stopturtle "spring" set the loc of image "jackAlone.png" to tLoc --unlock screen end drawSpring on drawSpring L,N,s,curvature --lock screen startTurtle "spring" pu setHome -30,-200 pd put L/N/2 into dy put arcsine(dy/s) into tAngle seth tAngle fd s/2 put 180 - 2*tAngle into da repeat (N-1) times left da+curvature --Curvature of spring fd s right da fd s end repeat left 180 - 2*tAngle fd s right da fd s/2 put xyCor() into tLoc put turtlePtToMousePt(tLoc) into tLoc stopturtle "spring" set the loc of image "jackAlone.png" to tLoc --unlock screen end drawSpring sm cREVGeneral cREVGeometryCacheIDs 1120406990855 22371120422453576 23001120407023780 22381120421217985 22941120395761342 22341120395789078 22351120410981944 2241 cREVGeometrycache order total 7 card id 1002 @ 33 sm cREVGeometryCacheIDs 1120421070958 22891120517131208 24241056723367368 10031060545782077 18471120274299547 14441120421220222 22951120274299548 15071120274299549 15521059857410357 1561 cREVGeometrycache total 9order cREVGeneral 7 x help @ 33 sm cREVGeometryCacheIDs 1005143486413 15321005143499075 15331014640140291 15311059830583348 15361005143503767 15341057770918193 1535 cREVGeometryCache order total 6 Color pinwheel Eqon mouseUP cleanallgraphics cleanG "test" --cleanLabel put "red,orange,black,green,blue,violet" into colorList repeat with i = 1 to 12 put "test" &i into tName startTurtle tName put 1+ (i-1) mod 6 into tNum set the forecolor of grc tName to item tNum of colorlist set the linesize of grc tName to 8 seth i*360/12 fd 100 stopturtle tName end repeat end mouseUP 3333 \ ) cREVGeneral revUniqueID 1056723367368 bookmarks handlerList mouseUPtempScript prevHandler mouseUPscriptSelection char 1 to 10script Color circles Eqon mouseUP cleanG cleanL put "red,orange,yellow,green,blue,violet" into colorList startTurtle "blueTurtle" set the forecolor of grc "blueTurtle" to blue set the linesize of grc "blueTurtle" to 4 set the endarrow of grc "blueTurtle" to true repeat 180 fd 2 lt 2 end repeat stopTurtle "blueTurtle" startTurtle "redTurtle" set the forecolor of grc "redTurtle" to red set the linesize of grc "redTurtle" to 2 seth 180 repeat 180 fd 2 lt 2 end repeat stopturtle "redTurtle" end mouseUP 3333 = \ ) Selection Description false cREVGeneral scriptChecksum 3vje I}revUniqueID 1120274299547 bookmarks handlerList mouseUPtempScript prevHandler mouseUPscriptSelection char 326 to 325script Won mouseUP
cleanG
cleanL
put "red,orange,yellow,green,blue,violet" into colorList
startTurtle "blueTurtle"
set the forecolor of grc "blueTurtle" to blue
set the linesize of grc "blueTurtle" to 4
set the endarrow of grc "blueTurtle" to true
repeat 180
fd 2
lt 2
end repeat
stopTurtle "blueTurtle"
startTurtle "redTurtle"
set the forecolor of grc "redTurtle" to red
set the linesize of grc "redTurtle" to 2
seth 180
repeat 180
fd 2
lt 2
end repeat
stopturtle "redTurtle"
end mouseUP
Intersection Eqon mouseUP answer "Click at four points to create two intersecting lines. I will move to the point of intersection." cleanallgraphics --cleanG "test" cleanL put the loc of me into theStartLoc startTurtle "blueTurtle" set the forecolor of grc "blueTurtle" to blue pu put clickPoint() into a setxy a put clickPoint() into b pd setxy b stopTurtle "blueTurtle" startTurtle "redTurtle" set the forecolor of grc "redTurtle" to red pu put clickPoint() into c setxy c pd put clickPoint() into d setxy d put intersection(a,b,c,d) into theIntersection stopturtle "redTurtle" move me to turtlePtToMousePt(theIntersection) in 1 sec wait 1 sec move me to theStartLoc in 1 sec end mouseUP 3333 h \ ) cREVGeneral revUniqueID 1120274299548 New Field 2 * T cREVGeneral revUniqueID 1014640140291 FThis card defines the main elements in the turtle graphic vocabulary. E New Field 1 )` ,F cREVGeneral revUniqueID 1005143486413 0 Commands [and their abreviations] ! forward 100 [fd 100] 4Moves the turtle 100 pixels at the current heading. 3 back 100 [bk 100] 9Moves the turtle back 100 pixels at the current heading. 8 right 30 [rt 30] 8Rotates the turtle clockwise through a 30 degree angle. 7 left 30 [lt 30] ?Rotates the turtle counterclockwise through a 30 degree angle. > setHeading 45 [seth 45] Directs the turtle to an angle of 45 degrees. (All angles are measured in the usual Cartesian manner, that is counterclockwise from 3 O'clock.) setX 30 8Moves the turtle horizontally to the coordinate x = 30. 7 setY 40 6Moves the turtle vertically to the coordinate y = 40. 5 setXY 30,40 +Moves the turtle to the coordinates 30,40. * incXY 3,4 IIncreases the x coordinate of the turtle by 3 and the y coordinate by 4. H New Field 3 )` * Y cREVGeneral revUniqueID 1005143499075 % Functions xcor ( ) #Returns the turtles x coordinate. ycor ( ) #Returns the turtles y coordinate. xyCor ( ) 4Returns a list of the turtles x and y coordinates. heading ( ) Returns the turtle's heading. #direction (30,40) or toward(30,40) qReturns the direction of the point 30,40 from the current location of the turtle. It does not rotate the turtle. distance (30,40) QReturns the distance from the current location of the turtle to the point 30,40. clickPoint ( ) jReturns the x and y coordinates of the point of the mouse click--useful in importing data into a program. Intersection(ax,ay,bx,by) MReturns the intersection of two lines whose endpoints are ax, ay and bx, by. L New Field 4 )` j cREVGeneral revUniqueID 1005143503767 8 Miscellaneous * * StartTurtle [st] tName Initiates the turtle (control) with the name tName, giving the control the custom properties of x, y coordinates, heading, pen state (up or down) and graphic points. The associated graphic (trace)is {tName} &"grc" StopTurtle [stopT] tName @Sets the graphic points and end conversation with turtle tName. ? home ;Moves the turtle to the origin and pointing to the right. : setHome 30,40 Sets the home position of the turtle a distance 30 to the right of screen-center, and a distance 40 above screen-center. (It does not move the turtle home.) cleanG tName }Clears the graphic points of the named turtle but not the graphic itself. If tName is omitted, it clears all graphic points. | penUp [pu] MRaises the drawing pen. The turtle will no longer leave a track as he moves. L penDown [pd] Lowers the drawing pen. !TurtlePtToMousePt [tptmp](point) {Converts turtle coordinates, measured from the screen's center, to mouse coordinates, measured from the upper left corner. z "MousePtToTurtlePt (point) [mpttp] See above. centeredCircle 5 IDraws a circle, centered about the current turtle position, of radius 5. H Label "x" TPrints an x (or whatever you place within quotes) at the current turtle location. S sci (num,sig) xReturns the input num in scientific notation with "sig" significant figures, e.g. sci(312345.67, 3) becomes 3.12*10^5. w commaFormat(num) bReturns the num with commas delimiting each triplet, i.e. commaFormat(9999999) returns 9,999,999. a Return Eq .on mouseUP go to previous card end mouseUP 3333 w( ( cREVGeneral revUniqueID 1057770918193 Field 1 )` X cREVGeneral revUniqueID 1059830583348 IThe turtle is a metaphor for a drawing pen. The pen has four properties: ,x and y coordinates, heading, and pen state The x and y Cartesian coordinates are measured relative to the center of the screen, the heading is the traditional polar angle, i.e. due east is 0 degrees and due north 90 degrees. The pen state is either up or down--drawing or not. ITo make the graphic receptive to the Turtle Graphic vocabulary you must: W1) Initiate the turtle with StartTurtle (or st) and the turtle name, e.g. st "redLine" 02) Write instructions for the turlte "redLine." 3) Finally finish with stopTurtle, e.g. stopTurtle "redLine" Nothing appears on the screen until stopTurtle is executed. stopTurtle sets the graphic points. You may only speak to one turtle at a time. Do not start a second turtle until you have stopped the previous turtle. That is: StartTurtle "redLine" doStuff stopTurtle "redLline" StartTurtel "blueLine" dostuff stopTurtle "blueLine" Since the turtle represents a line graphic, you may set the color, line size, and end/start arrow. For example if the turtle's name is "redLine" then you would: . set the forecolor of grc "redLine" to "red" ) set the lineSize of grc "redLine" to 2 , set the endArrow of grc "redLine" to true ` Y Ellipse Eqlocal phi,majorAxis,minorAxis on mouseUP cleanallgraphics --cleanG "test" put 300 into majorAxis put 100 into minorAxis ask "What angle?" with 0 put it into temp1 put the result into temp2 if the result is not "cancel" then put it into phi else exit to top startTurtle "ellipse" --Get from origin to ellipse with the pen down. pu setRA r(0,phi),0 --Now on the ellipse. pd repeat with a = 1 to 360 setRA r(a),a --Polar coordinates: r,a end repeat stopTurtle "ellipse" --Now set the points end mouseUP function r theAng put cosine(theAng-phi) into c put sine(theAng-phi) into s return sqrt(1/(c*c/majorAxis/majorAxis + s*s/minorAxis/minorAxis))-- Ellipse at angle phi end r 3333 \ ) cREVGeneral scriptChecksum # {'NƱN_breakPoints handlerList mouseUP rscriptSelection char 534 to 533revUniqueID 1120274299549 bookmarks tempScript prevHandler mouseUPscriptlocal phi,majorAxis,minorAxis
on mouseUP
cleanallgraphics
--cleanG "test"
put 300 into majorAxis
put 100 into minorAxis
ask "What angle?" with 0
put it into temp1
put the result into temp2
if the result is not "cancel" then
put it into phi
else exit to top
startTurtle "ellipse"
--Get from origin to ellipse with the pen down.
pu
setRA r(0,phi),0
--Now on the ellipse.
pd
repeat with a = 1 to 360
setRA r(a),a --Polar coordinates: r,a
end repeat
stopTurtle "ellipse" --Now set the points
end mouseUP
function r theAng
put cosine(theAng-phi) into c
put sine(theAng-phi) into s
return sqrt(1/(c*c/majorAxis/majorAxis + s*s/minorAxis/minorAxis))-- Ellipse at angle phi
end r
Help Eq ,on mouseUP go to card "help" end mouseUP 3333 \ ( cREVGeneral revUniqueID 1059857410357 7 Rotate ellipse Ep# on mouseUP startTurtle answer "Click at the center of rotation." put clickPoint() into tCenter setHome tCenter put the points of grc "ellipse" into tMousePoints put convertLinesMouseToTurtle(tMousePoints) into tTurtlePoints put the number of lines in tTurtlePoints into nPoints -- Ask "What angle?" with 90 -- put it into phi put 90 into phi repeat with i = 1 to nPoints put line i of tTurtlePoints into tTurtlePoint put distance(tTurtlePoint) into r --Radius in polar coordinates put direction(tTurtlePoint) into a --Angle in polar coordinates add phi to a put r*cosine(a)&comma&r*sine(a) into newPoint put turtlePtToMousePt(newPoint) into line i of newGraphicPoints end repeat set the points of grc "ellipse" to newGraphicPoints end mouseUP V " Selection Description false cREVGeneral revUniqueID 1060545782077 z spring K 6 * 7;CKT\dlt| cREVGeneral revUniqueID 1120187698180 ChangingLight.png @ * ^ _PNG IHDR ! pHYs gAMA cHRM m s H w 2 _IDATxYdu%Ϲf A !j")JI))LewvTU_Kϩ~ǮRJ9J-TD88@>{33\<" As=^{-/|v4Pf ^ ιDzuݣz#*=[7/B o럀P 1?xK9/={d65aL'?A?0p6rʽW<^G~'OGGȈrt5Uڋ|**hKzW?T`ŧ͖QJB&Uav:\FlR;88xɧpkW/~7~W~|_?C7?zs7o>qxxЫAtŽ{3cEV^|\p_WK݀1{Y ނ vst*Slx6+{ܢ:{'?+GG]u^˿'_=mow7}??"3ze\.;c1HDΩZ+"!_|~\-kgW͍1)|1:ٔB8pkƯu]LydP^A`lvpxh=99yoկ7~~7~D(ΎOW)2'OfxC?Pm,~&xטzZf6_D=iz'\\MuO?Í{-ז+s[:fwx!,hmj !fU,bb엇\3O`py|ꓟ+WaqvgƊRaX: wc+. &LDyf6`T MƤb 5m>nYkRdPfqmM2S]U`ߛǗlvm`OL;$2{L&"c@fƐ`G=xpK__g|?s??s