Programming for Artists, Autumn 2004

Task 3- Loop Program

 
 

 
 
 
      

// import canvas file
#include "canvas.as"
// new canvas object
var C = new Canvas();
// set background color as dark gray
C.setBackgroundColor(.1, .1, .3);
// x value for base corner for triangle
var f = .8;
// y value for base corner for triangle
var g = .7;
// base red value for triangle
var rb = .9;
// base green value for triangle
var gb = .8;
// base blue value for triangle
var bb = .8;
// counter for triangle while loop
var m = 1;
// while loop to create and evolve triangles
while (m<15) {
C.setPenColor(rb, gb, bb);
C.setPenWeight(.001);
C.drawLine(f, g, f-.3, g-.03);
C.drawLine(f, g, f+.05, g+.3);
C.drawLine(f+.05, g+.3, f-.3, g-.03);
f += .01;
g -= .02;
m += 1;
rb -= .01;
gb -= .05;
bb -= .06;
}
// base point1 values for thick diagonals
var px1 = .4;
var px2 = .4;
py1 = .6;
// base color values for thick diagonals
var r = .1;
var g = .2;
var b = .4;
// base pen width for thick diagonals
var w = .78;
var n = 1;
while (n<15) {
// draw thick diagonals
C.setpenColor(r, g, b);
C.setpenWeight(w);
C.drawLine(px1, py1, px2, py2);
px1 += .02;
py1 += .02;
px2 -= .02;
py2 += .02;
n += 1;
r += .06;
g += .02;
b += .03;
w -= .05;
}
// draw single thin diagonal in lighter color
C.setPenWeight(.02);
// set to thinner pen weight
C.setPenColor(.9, .8, .9);
C.drawLine(px1, py1, px2, py2);
var pxd = (px1-px2);
var pyd = (py2-px1);
var xd = .2;
var p = 1;
// Loop to create verticle green lines
while (n<33) {
// Set green line width
C.setPenWeight(.015);
// Set pen color to green
C.setPenColor(.6, .9, .6);
//draw green lines
C.drawLine(px1+.2, py1+pyd-.2, px2+pxd+.2, py2-.1);
// set full-length vertical line color
C.setPencolor(p, p, p);
// Set full-length vertical line width
C.setPenWeight(.001);
// Draw verticle line
C.drawLine(px1+xd, 0, px2+pxd+xd, 1);
xd -= .02;
px1 -= .03;
px2 -= .03;
n += 1;
p -= .056;
}
// bottom left corner top-layer lines
j = 1;
// base x value for boxes
xx = .15;
// base y value for boxes
yy = .9;
// base subtraction step value
sub = .01;
// red %
r = .5;
// green %
g = .9;
// blue %
b = .4;
// Box pen weight
C.setpenWeight(.005);
// rising & shrinking objects
while (j<9) {
C.setpenColor(r, g, b);
C.drawline(xx-sub, yy-sub, xx+sub, yy-sub);
C.drawline(xx+sub, yy-sub, xx+sub, yy+sub);
C.drawline(xx+sub, yy+sub, xx-sub, yy+sub);
C.drawline(xx-sub, yy+sub, xx-sub, yy-sub);
yy -= .04;
sub -= .001;
// shrink by sub value
g -= .1;
// less green
r -= .02;
// more red
j += 1;
}
// rising and growing objects
while (j<18) {
C.setpenColor(r, g, b);
C.drawline(xx-sub, yy-sub, xx+sub, yy-sub);
C.drawline(xx+sub, yy-sub, xx+sub, yy+sub);
C.drawline(xx+sub, yy+sub, xx-sub, yy+sub);
C.drawline(xx-sub, yy+sub, xx-sub, yy-sub);
yy -= .04;
sub += .001;
// grow by sub value
g += .07;
// more green
b += .05;
// more blue
j += 1;
r += .03;
// more red
}