In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Whirl Variation 1.

`Whirls are figures constructed by nesting a sequence of polygons (each having the same number of sides), each slightly smaller and rotated relative to the previous one. ( http://mathworld.wolfram.com/Whirl.html )`
by szbzs2004 01 Mar 2011
Embed
```/**
* Copyright szbzs2004 ( http://wonderfl.net/user/szbzs2004 )
*/

package  {

import flash.display.Shape;
import flash.display.Sprite;
import flash.display.GraphicsPathCommand;
import flash.display.GraphicsPathWinding;

import flash.events.Event;

import com.bit101.components.ColorChooser;
import com.bit101.components.HSlider;
import com.bit101.components.Window;

public class WhirlVariation1 extends Sprite {

private const DEFAULT_SIDES:int = 4;
private const DEFAULT_DEPTH:int = 33;
private const DEFAULT_Q:Number = 0.11;

private var drawing:Shape;

private var sides:int = DEFAULT_SIDES;
private var depth:int = DEFAULT_DEPTH;
private var q:Number = DEFAULT_Q;

private var color:uint = 0xff0000;

private var pWindow:Window;
private var rSlider:HSlider;
private var aSlider:HSlider;
private var sSlider:HSlider;
private var dSlider:HSlider;
private var qSlider:HSlider;
private var cChooser:ColorChooser;

public function WhirlVariation1() {
WhirlInit();
ParametersWindowInit();
WhirlDraw();
}

private function WhirlInit():void {
var w:int = stage.stageWidth;
var h:int = stage.stageHeight;

radius = Math.max(w / 2, h / 2) * Math.SQRT2;

drawing = new Shape();
drawing.x = w / 2;
drawing.y = h / 2;
}

private function WhirlDraw():void {
var i:int, j:int, p:int;
var c:Vector.<int> = new Vector.<int>();
var d:Vector.<Number> = new Vector.<Number>();

for (i = 0; i <= sides; ++i) {
var a:Number = (2 * i + 1) * Math.PI / sides;
c.push(i == 0 ? GraphicsPathCommand.MOVE_TO : GraphicsPathCommand.LINE_TO);
}

p = 0;
for (i = 1; i < depth; ++i) {
var x0:Number = d[p++];
var y0:Number = d[p++];
for (j = 0; j < sides; ++j) {
var x1:Number = d[p++];
var y1:Number = d[p++];
c.push(j == 0 ? GraphicsPathCommand.MOVE_TO : GraphicsPathCommand.LINE_TO);
d.push(x0 + q * (x1 - x0), y0 + q * (y1 - y0));
x0 = x1;
y0 = y1;
}
c.push(GraphicsPathCommand.LINE_TO);
d.push(d[p], d[p + 1]);
}

drawing.graphics.clear();
drawing.graphics.beginFill(color);
drawing.graphics.drawPath(c, d, GraphicsPathWinding.EVEN_ODD);
}

private function ParametersWindowInit():void {

pWindow = new Window(this, 10, 10, "Whirl Variation 1.");
//            pWindow.hasMinimizeButton = true;

rSlider = new HSlider(pWindow, 0, 20, changeR);

aSlider = new HSlider(pWindow, 0, 30, changeA);
aSlider.setSliderParams(0, 360, 0);

sSlider = new HSlider(pWindow, 0, 40, changeS);
sSlider.setSliderParams(3, 30, sides);

dSlider = new HSlider(pWindow, 0, 50, changeD);
dSlider.setSliderParams(1, 100, depth);

qSlider = new HSlider(pWindow, 0, 60, changeQ);
qSlider.setSliderParams(0, 1, q);

cChooser = new ColorChooser(pWindow, 0, 70, color, changeC);
cChooser.usePopup = true;

pWindow.setSize(100, 87);
}

private function changeR(e:Event):void {
WhirlDraw();
}

private function changeA(e:Event):void {
drawing.rotation = e.target.value;
}

private function changeS(e:Event):void {
sides = e.target.value;
WhirlDraw();
}

private function changeD(e:Event):void {
depth = e.target.value;
WhirlDraw();
}

private function changeQ(e:Event):void {
q = e.target.value;
WhirlDraw();
}

private function changeC(e:Event):void {
color = e.target.value;
WhirlDraw();
}
}
}
```