Spirals in motion
The idea of this blog is to make my Flash work, the portfolio pieces and experiments, more available. My site will soon get a zetaclear nail fungus treatment
redesign using a Papervision interface, which while cool in many ways will make it a little harder for people to find my content, so this blog should hopefully remedy that. And also provide you with a way to give me feedback on things.
So I'll start of with a random one... this was always one of my favourite experiments but I've yet to find a use for it, so it can kick off the blog
As is usual in my experiments, roll your mouse over the screen to interact with the changing patterns.
It was written way back when in AS1, set your background to black and stick this in frame 1:
-
var angleDelta = 45*(Math.PI/180), rx, ry, ex, ey;
-
var regDist = r/Math.cos(angleDelta/2);
-
var angle = 0;
-
this.moveTo(x+r, y);
-
for (var i = 0; i < 8; i++) {
-
angle += angleDelta;
-
rx = x+Math.cos(angle-(angleDelta/2))*(regDist);
-
ry = y+Math.sin(angle-(angleDelta/2))*(regDist);
-
ex = x+Math.cos(angle)*r;
-
ey = y+Math.sin(angle)*r;
-
this.curveTo(rx, ry, ex, ey);
-
}
-
}
-
-
var k = 0.14;
-
var friction = 0.825;
-
var cx = Stage.width/2;
-
var cy = Stage.height/2;
-
var ox = cx;
-
var oy = cy;
-
var numBranches = 3;
-
var numNodes = 30; // Number of circles per branch
-
var nodes = [];
-
// Set up colours
-
var col = Math.random()*Math.PI*2;
-
var colInc = 0.1;
-
// Create the circles
-
for(n=0, z=1; n < numBranches; n++){
-
nodes.push(new Array());
-
for(var m=0; m < numNodes; m++, z++){
-
nodes[n].push(thisNode =
-
this.createEmptyMovieClip("mc_"+z, (m*numBranches)+n));
-
// Initally all are white, this is adjusted later
-
thisNode.beginFill(0xffffff);
-
drawCircle.apply(thisNode, [0, 0, 220 * (1-(m/numNodes))]);
-
thisNode.endFill();
-
thisNode.thisCol = new Color(thisNode);
-
}
-
}
-
// Localise Math functions for better performance.
-
this.sin = Math.sin;
-
this.cos = Math.cos;
-
this.abs = Math.abs;
-
this.createEmptyMovieClip("border", z);
-
this.border.lineStyle(1, 0xAAAAAA);
-
this.border.lineTo(Stage.width-1, 0);
-
this.border.lineTo(Stage.width-1, Stage.height-1);
-
this.border.lineTo(0, Stage.height-1);
-
this.border.lineTo(0, 0);
-
this.onEnterFrame = function(){
-
var thisCol, nRatio, r, g, b, rDone, gDone, bDone, rInc, gInc, bInc;
-
var dx = ox - cx;
-
var dy = oy - cy;
-
var xRatio = dx/cx;
-
var yRatio = dy/cy;
-
var radInc = xRatio * -7;
-
var thetaInc = yRatio * 0.05;
-
var thetaMod = xRatio * 1.5;
-
col += colInc;
-
for(var n=0; n < numBranches; n++){
-
nRatio = n/numBranches;
-
theta = thetaMod + ((Math.PI*2)*nRatio);
-
thisCol = col + ((Math.PI*2)*nRatio);
-
rDone = this.abs(0x88 + (this.sin(thisCol))*0x77);
-
gDone = this.abs(0x88 + (this.sin(1.5 + thisCol))*0x77);
-
bDone = this.abs(0x88 + (this.sin(3 + thisCol))*0x77);
-
rInc = rDone / numNodes;
-
gInc = gDone / numNodes;
-
bInc = bDone / numNodes;
-
r = g = b = 0;
-
for(var m=0, rad=80; m < numNodes; m++){
-
theta += thetaInc;
-
rad += radInc;
-
thisNode = nodes[n][m];
-
thisNode._x = cx+(this.cos(theta) * rad);
-
thisNode._y = cy+(this.sin(theta) * rad);
-
r += rInc;
-
g += gInc;
-
b += bInc;
-
thisNode.thisCol.setRGB(r << 16 | g << 8 | b);
-
}
-
}
-
vx = (vx + ((_xmouse - ox) * k)) * friction;
-
vy = (vy + ((_ymouse - oy) * k)) * friction;
-
ox += vx;
-
oy += vy;
-
}
Posted: 01:51 PM under Flash Experiments.
Tags: colour, Maths, motion, mouse, rgb, spiral
