Language

Recent Posts

Tags

3D AlivePDF AS1 blocker colour cropped character ExternalInterface Flash Flash Bug FocusEvent FOCUS_IN FOCUS_OUT greyscale grayscale bitmapdata bitmap highlight Input KEY_FOCUS_CHANGE Maths Menu motion mouse navigateToURL PDF PHP Pop-up popup rgb selectionBeginIndex selectionEndIndex setSelection spiral TextField User Interface

Site search

September 2010
M T W T F S S
« Mar    
 12345
6789101112
13141516171819
20212223242526
27282930  

Categories

Tags

Blogroll

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 :)

Spirals in Motion

Spirals in Motion

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:

drawCircle = function (x, y, r) {
  1.  var angleDelta = 45*(Math.PI/180), rx, ry, ex, ey;
  2.  var regDist = r/Math.cos(angleDelta/2);
  3.  var angle = 0;
  4.  this.moveTo(x+r, y);
  5.  for (var i = 0; i < 8; i++) {
  6.    angle += angleDelta;
  7.    rx = x+Math.cos(angle-(angleDelta/2))*(regDist);
  8.    ry = y+Math.sin(angle-(angleDelta/2))*(regDist);
  9.    ex = x+Math.cos(angle)*r;
  10.    ey = y+Math.sin(angle)*r;
  11.    this.curveTo(rx, ry, ex, ey);
  12.  }
  13. }
  14.  
  15. var k = 0.14;
  16. var friction = 0.825;
  17. var cx = Stage.width/2;
  18. var cy = Stage.height/2;
  19. var ox = cx;
  20. var oy = cy;
  21. var numBranches = 3;
  22. var numNodes = 30; // Number of circles per branch
  23. var nodes = [];
  24. // Set up colours
  25. var col = Math.random()*Math.PI*2;
  26. var colInc = 0.1;
  27. // Create the circles
  28. for(n=0, z=1; n < numBranches; n++){
  29.  nodes.push(new Array());
  30.  for(var m=0; m < numNodes; m++, z++){
  31.   nodes[n].push(thisNode =
  32.    this.createEmptyMovieClip("mc_"+z, (m*numBranches)+n));
  33.   // Initally all are white, this is adjusted later
  34.   thisNode.beginFill(0xffffff);
  35.   drawCircle.apply(thisNode, [0, 0, 220 * (1-(m/numNodes))]);
  36.   thisNode.endFill();
  37.   thisNode.thisCol = new Color(thisNode);
  38.  }
  39. }
  40. // Localise Math functions for better performance.
  41. this.sin = Math.sin;
  42. this.cos = Math.cos;
  43. this.abs = Math.abs;
  44. this.createEmptyMovieClip("border", z);
  45. this.border.lineStyle(1, 0xAAAAAA);
  46. this.border.lineTo(Stage.width-1, 0);
  47. this.border.lineTo(Stage.width-1, Stage.height-1);
  48. this.border.lineTo(0, Stage.height-1);
  49. this.border.lineTo(0, 0);
  50. this.onEnterFrame = function(){
  51.  var thisCol, nRatio, r, g, b, rDone, gDone, bDone, rInc, gInc, bInc;
  52.  var dx = ox - cx;
  53.  var dy = oy - cy;
  54.  var xRatio = dx/cx;
  55.  var yRatio = dy/cy;
  56.  var radInc = xRatio * -7;
  57.  var thetaInc = yRatio * 0.05;
  58.  var thetaMod = xRatio * 1.5;
  59.  col += colInc;
  60.  for(var n=0; n < numBranches; n++){
  61.   nRatio = n/numBranches;
  62.   theta = thetaMod + ((Math.PI*2)*nRatio);
  63.   thisCol = col + ((Math.PI*2)*nRatio);
  64.   rDone = this.abs(0x88 + (this.sin(thisCol))*0x77);
  65.   gDone = this.abs(0x88 + (this.sin(1.5 + thisCol))*0x77);
  66.   bDone = this.abs(0x88 + (this.sin(3 + thisCol))*0x77);
  67.   rInc = rDone / numNodes;
  68.   gInc = gDone / numNodes;
  69.   bInc = bDone / numNodes;
  70.   r = g = b = 0;
  71.   for(var m=0, rad=80; m < numNodes; m++){
  72.    theta += thetaInc;
  73.    rad += radInc;
  74.    thisNode = nodes[n][m];
  75.    thisNode._x = cx+(this.cos(theta) * rad);
  76.    thisNode._y = cy+(this.sin(theta) * rad);
  77.    r += rInc;
  78.    g += gInc;
  79.    b += bInc;
  80.    thisNode.thisCol.setRGB(r << 16 | g << 8 | b);
  81.   }
  82.  }
  83.  vx = (vx + ((_xmouse - ox) * k)) * friction;
  84.  vy = (vy + ((_ymouse - oy) * k)) * friction;
  85.  ox += vx;
  86.  oy += vy;
  87. }

Write a comment