Category: Lessons

  • Exercise 25

    now let’s nest a while loop inside another while loop to give us a grid size(400, 400); noStroke(); background(50); float x = 0; while (x < width) { float y = 0; while (y < height) { rect(x, y, 30, 30); y = y + 40; } x = x + 50; }

  • Exercise 24

    Now let’s rotate but change the center point of our rotation. We do that using the translate() function. float r = 0; void setup() { size(400,400); background(10); smooth(); noStroke(); } void draw() { translate(width/2, height/2); fill(255); rotate(r); float circle_size = random(5, 15); ellipse(100 + r, 10, circle_size, circle_size); r = r + 0.2; println(r); }

  • Exercise 23

    Continuing our experiments with rotation Think of the rotate() function like sticking a pin into the top left (0,0) corner of our piece of paper (our canvas) and turning the paper around the pin axis. float r = 0; void setup() { size(400,400); background(10); smooth(); noStroke(); } void draw() { fill(255); rotate(r); float circle_size =…

  • Exercise 22

    Rotating Objects size(400,300); background(#6AA21E); noStroke(); smooth(); float c = 0; while(c < 100) { fill(random(255)); rect(200,10,50, 5); fill(255, 0, 0); rect(260,10,10, 5); rotate(0.02); c = c + 1; }

  • Exercise 21

    drawing circles with a While loop try changing the increment that i is increased by. size(400, 400); colorMode(HSB); // choose a random background color using Hue, Saturation and Brightness background(random(255), random(50, 100), random(50, 100)); noFill(); stroke(255, 100); float i = 0; while (i < 100) { ellipse(100 + i*2, 100 + i*2, 100+i, 100-i*2); //…

  • Exercise 20

    Making a starry night void setup() { size(600,400); background(0); noStroke(); } void draw() { //background(0); fill(0, 10); rect(0, 0, width, height); fill(255); ellipse(random(width), random(height), 2, 2); }

  • Exercise 19

    Improving our drawing app void draw() { if (mousePressed == true) { point(mouseX,mouseY); } } void keyPressed() { if (key == ‘s’) { save(“my_drawing.png”); } if (key == ‘b’) { background(random(255), random(255), random(255)); draw_top_line(); } if (key == ‘c’) { stroke(random(255), random(255), random(255)); draw_top_line(); } } void draw_top_line() { strokeWeight(7); line(0,0, width, 0); strokeWeight(2); }

  • Exercise 18

    Our very own drawing application void draw() { if (mousePressed == true) { point(mouseX,mouseY); } } void keyPressed() { save(“my_drawing.png”); }

  • Exercise 17

    Improving on our bar code generator float x = 0; void setup() { size(400, 400); background(255); stroke(255); } void change_line_color() { stroke(255, 0, 0); line(x, 100, x, 200); // now we decide if to use black or white if (random(100) > 50) { stroke(0); } else { stroke(255); } } void draw() { // draw…

  • Exercise 16

    Random Bar Code Generator float x = 0; void setup() { size(400, 400); background(255); stroke(255); } void draw() { line(x, 200, x, 100); x = x + 1; if (x > width) { x = 0; } // sometimes we decide to change the line color if (random(100) > 70) { // now we decide…