Here is my palm frond wallpaper. Vibes.
//sam rauch, section B, srauch@andrew.cmu.edu, project 05
//this code makes a wallpaper pattern with overlapping palm leaves
function setup() {
createCanvas(400, 400);
background(220);
text("p5.js vers 0.9.0 test.", 10, 15);
}
function draw() {
background(16, 28, 48);
//drawing pattern
var direction = 1 //flips direction leaves are facing as they're drawn in the j loop
for (var i = 0; i <= width+110; i+=110){
for (var j = 0; j<= height+100; j+=70){
stem(i,j, 45*direction);
direction = direction*-1;
}
}
noLoop();
}
function portLeaf(a,b,radius, spin){ //make left leaves. must be called at 0,0
push();
translate(a,b);
rotate(radians(spin));
noStroke();
push(); //bottom half
fill(20, 50, 23);
translate(a-(cos(radians(70))*radius), b-(sin(radians(70))*radius));
arc(0, 0, radius*2, radius*2, radians(70), radians(110), CHORD);
pop();
push(); //top half
fill(37, 87, 42);
translate(a+(cos(radians(250))*radius), b-(sin(radians(290))*radius));
arc(0,0, radius*2, radius*2, radians(250), radians(290), CHORD);
pop();
pop();
}
function starLeaf(a,b,radius,spin) { //make right leaves. must be called at 0,0
push();
translate(a,b);
rotate(radians(spin));
noStroke();
push(); //bottom half
fill(20, 50, 23);
translate(a+(cos(radians(70))*radius), b-(sin(radians(70))*radius));
arc(0, 0, radius*2, radius*2, radians(70), radians(110), CHORD);
pop();
push(); //top half
fill(37, 87, 42);
translate(a-(cos(radians(250))*radius), b-(sin(radians(290))*radius));
arc(0,0, radius*2, radius*2, radians(250), radians(290), CHORD);
pop();
pop();
}
function stem(stemX, stemY, spin) {//make a stem, and place leaves along it
push();
translate(stemX, stemY);
rotate(radians(spin));
//leaves at the tip
portLeaf(0,0,50,60);
starLeaf(0,0,50,-60);
portLeaf(0,0,50,80);
starLeaf(0,0,50,-80);
//put leaves along the stem
var radius = 45;
for(var i = 0; i<100; i+=10){
push();
translate(0,i);
portLeaf(0,0,radius, 30);
starLeaf(0,0,radius,-30);
radius += 3;
pop();
}
//line for stem
stroke(20, 60, 25);
strokeWeight(3);
line(0,0, 0, 100);
pop();
}