Project 05: Wallpaper

The biggest challenge in this project was dealing with drawing the spines on the cactus. It turns out P5.js doesn’t really like nested loops in functions and it crashed the program when I tried to use it, so I had to do the inefficient solution of manually drawing the points.

cactus







function setup() {
    createCanvas(600, 600);
    strokeWeight(3)
   
   


}

function draw() {
for (x = 120; x <= width - 120; x += 120) {
    
    for (y = 120; y <= height - 120; y += 120) {
        
        createCactus(x, y, 60, 80)
    }
}
    
  




}

function createCactus(cactusx, cactusy, cactusw, cactush) { 
    push()
    rotate(radians(random(-PI * 2, PI * 2)))
    translate(cactusx,cactusy) 
    fill(35, 117, 67)
    ellipse(0, 0, cactusw, cactush)
    body()
    arms(45)
    flower()
    pop()
    noLoop()
    



}

function body() {
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      point((random(-20, 20)), random(-30, 30))
      noLoop()


}

function arms (x) {
    push()
    translate(x,0)
    rotate(degrees(90))
    ellipse(0, 0, 20, 40)
    pop()
    push()
    translate(-x,0)
    rotate(degrees(230))
    ellipse(0, 0, 20, 40)
    pop()
    }

function flower() {
        noStroke()
        push()
        translate(0, -40)
        for (r = 90; r <= 270; r += 180) {
            rotate(degrees(r))
            fill(245, 110, 191)
            ellipse(0, 0, 10, 20)
            
        }

        pop()    
    }



    //// for (x = 0; x <= cactusw/2.75; x += 10) {
        //for (y = 0; y <= cactush/2.25; y += 10) {
             //point(x,y)
            
        //}
    //}
    ///for (x = -(cactusw/3); x <= 0; x += 10) {
        ///for (y = 0; y <= cactush/2.25; y += 10) {
             //point(x,y)
            
        //}
    //}
    //for (x = -(cactusw/3); x <= 0; x += 10) {
        //for (y = (-cactush/2.75); y <= 0; y += 10) {
             //point(x,y)
            
        //}
    //}
    //for (x = 0; x <= cactusw/2.75; x += 10) {
        //for (y = (-cactush/2.75); y <= 0; y += 10) {
             //point(x,y)
            
        //}
    //}

Leave a Reply