composition using loops
code
#include "../Canvas.as" /* task03 :: pfa This program generates a set of transformed shapes, basing their starting point on the current mouse coordinates each time the stage loads. Justin Grossman :: 10.16.03 */// setup stuff ///////////////////////////////////////////////////////////// some random background color switchingvar bg_r = Math.random(); var bg_g = Math.random(); var bg_b = Math.random();// starting values for pen colors and propertiesvar r = 0.5 * Math.random() ; var g = 0.1;//Math.random() ;var b = 0.01 * Math.random() ; var penweight = 0.715;//this can be decremented on iterationvar penopacity = 0.2;//this can be incremented on iteration// increments a value (by a normalized amount)function IncrementIt(oldvalue) { var newvalue = oldvalue + 0.35;//massage the added value to change characteristicsif (newvalue > 1) { newvalue = Math.abs(1 - oldvalue); } return newvalue; }// opposite as IncrementIt();function DecrementIt(oldvalue) { var newvalue = oldvalue - 0.05; if (newvalue < 0) { newvalue = Math.abs(1 + oldvalue); } return newvalue; }// draws the shape (3sided)function DrawShape3(startpt_x, startpt_y, endpt_x, endpt_y) { Canvas.drawLine(startpt_x, startpt_y, startpt_x, endpt_y); Canvas.drawLine(startpt_x, endpt_y, endpt_x, endpt_y); Canvas.drawLine(endpt_x, endpt_y, startpt_x, startpt_y); }// the actual program ////////////////////////////////////////////////////Canvas.setBackgroundColor(bg_r, bg_g, bg_b);// sets starting point of shape to normalized mouse coordinates (on load)var startpt_x = ( _xmouse / 600 ); var startpt_y = ( _ymouse / 600 );//trace("(x mouse, y mouse) = (" + startpt_x + ", " + startpt_y + ")");// sets endpoint of shape to random canvas coordinatesvar endpt_x = Math.random(); var endpt_y = Math.random(); for (i = 0; i < 15; i++) {//iterates process that draws i shapes// sets up toolCanvas.setPenColor(r, g, b); Canvas.setPenWeight(penweight); Canvas.setOpacity(penopacity);// calls function that draws the shapeDrawShape3(startpt_x, startpt_y, endpt_x, endpt_y);// transforms the tool parametersendpt_x = IncrementIt(endpt_x); endpt_y = 1 - 0.5 * endpt_x; r = IncrementIt(r); g = IncrementIt(g); b = IncrementIt(b); penweight = DecrementIt(penweight); penopacity = IncrementIt(penopacity); }