//Michael Miller
//Section A
//mmiller5@andrew.cmu.edu
//Project-05
var toggle = [-1,1]; //randomly flip the spiral
var columnNum = 9
function setup() {
createCanvas(480, 480);
background(255);
}
function draw() {
for (var i1 = 0; i1 < columnNum; i1 ++) { //makes rows of bamboo
x = map(i1, 0, 7, 0, 7 * width / columnNum);
var yOffset = random(-height / 3, 0); /*each column height will be
randomly offset*/
for (var i2 = 0; i2 < 4; i2 ++) { //makes columns of bamboo
y = map(i2, 0, 3, 0, 3 * height / 3);
bambooDesign(x, y, yOffset);
}
}
noLoop();
}
function bambooDesign(x, y, yOffset) { //makes bamboo segments
colorFill(x, y, yOffset);
stroke(0, 25);
strokeWeight(3);
fill(200, 204, 153);
rect(x + .5, y + yOffset - 2.5, width / columnNum - 1, 4);//segment joints
var spiralX = x + width / (2 * columnNum) + random(-5, 5);
var spiralY = y + yOffset + height / 6
var flip = random(toggle);
spiral(spiralX, spiralY, flip);
}
function colorFill(x, y, yOffset) { //colors each bamboo segment with a gradient
var size = 1
for (var iy = size / 2; iy < height / 3; iy += size) {
for (var ix = size / 2; ix < width / columnNum; ix += size) {
//color of each segment will be the same, so map it to current one
r = map(iy + y, y, y + height / 3, 125, 175);
g = map(ix + x, x, x + width / columnNum, 125, 200);
noStroke();
fill (r, g, 0);
ellipse(ix + x, iy + y + yOffset, size, size);
}
}
}
function spiral(spiralX, spiralY, flip) { //small spiral ingrained into bamboo
var angle = 35 - (105 * flip);
var spiralSize = 200;
fill(255, 150);
noStroke();
push();
translate(spiralX, spiralY + 60);
rotate(radians(angle));
for(count = 0; count < spiralSize; count ++) { //made from many ellipses
push();
rotate(radians(flip * 6 * count));
translate (1, 1);
ellipse(count/15, count/15, 2, 2);
pop();
}
pop();
}
I was playing around with rectangular tiles that had randomly spaced heights when I thought it looked like bamboo! It then took me way too long to color the segments properly with a gradient, but it worked out in the end. I also wanted to make leaves, but it didn’t pan out, so I have the flowery-ish spirals instead — one of these days though, there will be leaves. Also, the bamboo heights and spiral directions randomize with each refresh.