A Colourful Dartboard §
void setup() {
// caleb b
// a colourful dartboard
size(600, 600); // set screen size
for(int i = 10; i > 0 ; i--) { // for loop starts from 10 and counts down so the smaller circles get drawn on top of the larger ones.
fill((float) (Math.random() * 255), (float) Math.random() * 255, (float) Math.random() * 255); // generate random colours
ellipse(300, 300, i*50, i*50); // create the circle
}
}
Draw a Clock §
void setup() {
// caleb b
// drawing a clock
size(550, 550);
fill(255, 255, 255);
ellipse(275, 275, 500, 500); // create the clock
int centerX = 275;
int centerY = 275;
int radius = 250;
for (int i = 0; i < 60; i++) {
float angle = radians(map(i, 0, 60, 0, 360));
// line start points
float x1 = centerX + cos(angle) * (radius - 10);
float y1 = centerY + sin(angle) * (radius - 10);
// line end points
float x2 = centerX + cos(angle) * radius;
float y2 = centerY + sin(angle) * radius;
if (i % 5 == 0) {
// hour ticks
strokeWeight(4);
stroke(0, 0, 0);
line(x1, y1, x2, y2);
} else {
// minute ticks
strokeWeight(2);
stroke(0, 255, 0);
line(x1, y1, x2, y2);
}
}
}