Re: Code for a circle
Re: Code for a circle
- Subject: Re: Code for a circle
- From: Bill Briggs <email@hidden>
- Date: Thu, 13 Mar 2003 21:33:49 -0400
I'm always amazed at the stuff people recruit AppleScript to do for
them. I just couldn't resist this one. You can change the number of
repeats and the diameter of the circle by setting d and r.
- web
tell application "Finder"
--activate
set d to 40 -- diameter of circle
set r to 8 -- number of repeats
set frontWindow to window 1
set {xp, yp} to position of frontWindow
set x1 to xp + (d / 2)
set y1 to yp
repeat with k from 1 to r
set t to (-1) ^ k
repeat with i from 1 to d by 2
set xCoord to x1 + (t * (d / 2)) - t * i
-- get y offset information from quadrant
if xCoord is greater than x1 and t is less than 0 then
set ytog to -1
else if xCoord is greater than x1 and t is greater than 0 then
set ytog to 1
else if xCoord is less than x1 and t is greater than 0 then
set ytog to 1
else if xCoord is less than x1 and t is less than 0 then
set ytog to -1
end if
try -- to avoid problem when the next step in the calculation blows up
set yCoord to ((ytog * ((((d / 2) ^ 2) - ((xCoord - x1) ^ 2)) ^
0.5)) + y1) -- t * (d / 2)
on error
set yCoord to y1
end try
set position of frontWindow to {xCoord, yCoord}
end repeat
end repeat
end tell
At 1:49 PM -0500 13/03/03, Paul Skinner wrote:
Can anyone explain the formula I should use to generate values for
the position of a window such that the values all fall close to
lying on a 30 pixel diameter circle ?
What I'm trying to do is make a window politely draw
attention to itself. I currently use this bit...
tell application "Finder"
activate
try
set frontWindow to window 1
set {x, y} to position of frontWindow
repeat with v from 30 to 10 by -10
set r to (v / 10)
repeat with i from 1 to v by r
set position of frontWindow to {x + i, y}
end repeat
set x to x + v
repeat with i from 1 to v by r
set position of frontWindow to {x, y + i}
end repeat
set y to y + v
repeat with i from 1 to v by r
set position of frontWindow to {x - i, y}
end repeat
set x to x - v
repeat with i from 1 to v by r
set position of frontWindow to {x, y - i}
end repeat
set y to y - v
end repeat
end try
end tell
This moves the front finder window in three progressively
smaller squares. The result isn't too bad, but I'd like to move it
in circles rather than a square. It just seems that would be more
Mac OS X-like in behavior.
Paul Skinner
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.