Month: June 2015

  • 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); //…

  • The While Loop

    The ‘While’ structure is similar to an if statement, but there is an important difference. With an if statement, the code inside the curly braces will run 0 or 1 times (0 times if the condition is false, 1 time if the condition is true). But with the while loop code can run many times,…

  • 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…

  • Exercise 15

    Rainbows in a different colour mode void setup() { size(300, 300); background(#04B1CE); noFill(); colorMode(HSB); } void draw() { strokeWeight(random(3, 10)); stroke(random(255), 255, 255); // HSB Hue Saturation Brightness float rainbow_size = random(200, 270); ellipse(150, 350, rainbow_size, rainbow_size); }

  • Exercise 14

    Making Rainbows void setup() { size(300, 300); background(#04B1CE); noFill(); } void draw() { strokeWeight(random(3, 10)); stroke(random(255), random(255), random(255)); float rainbow_size = random(200, 270); ellipse(150, 350, rainbow_size, rainbow_size); }

  • Exercise 13

    Making Rainbows // initial position for our circle float circle_x = 300; float circle_y = 20; // how much to move the circle on each frame float move_x = 2; float move_y = -2; void setup() { size(400, 200); stroke(#D60DFF); strokeWeight(7); } void draw() { background(#21EA73); ellipse(circle_x, circle_y, 40, 40); circle_x = circle_x + move_x;…