Functions

icm04-functions

This sketch enhances the previous code by re-organizing it into functions. Each function takes parameters so I can use them multiple times and re-use them in a different sketch.

I decided to play with my previous sketches, so I turned the beetle from the first two assignments into a function as well and mixed it with the new one.

icm04-functionsb

Code:

void setup() { size(800, 800); colorMode(HSB); frameRate(10); } void draw() { background(0); rays(); object(100, 100); object(600, 200); object(200, 700); object(600, 600); object(400, 400); } void object(float x, float y) { if (mousePressed) { fill(255, 200); } else { fill(0, 200); stroke(255); } triangle(mouseX, mouseY, x, y, x+50, y); } void rays() { for (int x = -50; x < width; x+=50) { for (int y = -50; y < height; y+=50) { fill( random(255), 100, 255, 50); float var=random(10, 100); if (mousePressed) { fill( random(255), 50); frameRate(60); } else { frameRate(10); } noStroke(); triangle(mouseX, mouseY, x, y+var, x+var, y+var); } } }

Leave a Reply