RegPoint Kaleidoscope
April 18, 1999
by Pat McClellan
Dear Multimedia Handyman,
Any hints on how I can create a kaleidoscope (or at least groovy kaleidoscope-like effects) in Director?
Bruce
Dear Bruce,
Glad you asked that! That gives me a chance to talk about the new sprite rotation feature in Director 7. To create a kaleidascope reflection, you can simply drag multiple copies of a sprite onto the stage, rotating each subsequent one by a particular angle. Here's a demo available for download in Mac or PC format.
In this example, I'm using only 4 castmembers. I've set up each one a little different, just for visual variety. Take a look at the "yellow dots" cast member. I've created 8 sprite instances of it, each one rotated 360/8... or 45 degrees. There are 6 sprite instances of the "red squiggles", each rotated 360/6.... or 60 degrees. I just use the rotation setting in the score window to set these up -- no Lingo required.
Now comes the fun part of moving them. I created a simple movie script which is toggled on and off with a mouseClick anywhere on the stage. When activated, the handler simply moves the regPoint of each of my cast members, corresponding with the movement of the mouse. Here's how I set things up. (This is all a movie script, not attached to any sprite.)
on startMovie global gMemList, gFlag set gMemList = [member 1 of castLib 1, ¬ member 2 of castLib 1,member 3 of castLib ¬ 1,member 4 of castLib 1] repeat with i in gMemList set the regPoint of i = point(0,0) end repeat set gFlag to #stop end
The startMovie script sets up a list of members which includes all of my graphic doodles. It also cycles through the list, resetting the regPoint of each member to its original spot.
on mouseDown global gFlag, gStartLoc if gFlag = #stop then set gFlag to #go set gStartLoc = point(the mouseH, the mouseV) else set gFlag to #stop end if end
The mouseDown handler toggles a global flag, which will allow the regPoint updates to happen. It also stores the point which was clicked. This is important because it is the mouse's movement from the point which will affect the regPoints of the cast Members.
on exitFrame global gMemList, gStartLoc, gFlag if gFlag = #go then set deltaLoc = gStartLoc - ¬ point(the mouseH, the mouseV) repeat with whichMem in gMemList set currentReg = the regPoint of whichMem set the regPoint of whichMem = deltaLoc end repeat end if end
Remember that the exitFrame handler is not assigned to any specific frame, but will execute on every exitFrame. This handler checks to see if the gFlag is set to #go. If so, it calculates the difference between the current mouseLoc and the starting loc (at the time of the click). This difference (which I call deltaLoc) is applied to the regPoint of each of the graphic members in our list, and voila, we have a kaleidoscope effect.
One note. Since the sprites are not moving at all (but rather the members appear to move) Trails ink effect will have no visible effect at all. If you really want a trailing kind of effect, then you'll have to use a different approach, involving lots of math and trigonometry. You'll apply these formulas to each of the sprites, requiring lots more processor work. Jim Collins has done some incredible work like this that must be seen to be believed. Check out Jim's Developer Profile for the URL and background info.
Good luck with your project.
Copyright 1997-2024, Director Online. Article content copyright by respective authors.