- here you can hit any key to make a new image
- better random number handling in if…else if…
- last bird has random angle
You could make more variety by using random size and random angle.
Remember to hit ctrl-t in the code to get auto-format for your Sketch (indents and the like). Nice.
Chrisir
void setup() {
size(1500, 500);
noFill();
drawBirds();
}
void draw() {
//
}
void keyPressed() {
drawBirds();
}
// -------------------------------------------------------------------------------------
void drawBirds() {
background (#79C3F0);// (#0DE4FA); // !!!!
final float dist=35; // from border // !!!!
float rightWingCenterX;
for (int i=0; i<100; i+=21) {
for (int j=0; j<100; j+=21) {
float x1 = random(dist, width-dist);
float y1 = random(dist, height-dist);
float x2 = random(dist, width-dist);
float y2 = random(dist, height-dist);
float x3 = random(dist, width-dist);
float y3 = random(dist, height-dist);
// make random number // !!!!!!
float numberRandom = random(1);
// evaluate the number
if (numberRandom >0.66) {
// Bird 1: wings in the middle, same angle value for both wings
// draw left wing
arc(x1, y1, 100, 100, radians(225), radians(315));
// get the right end point of the left wing
PVector pv1 = getPVectorOfPositionOnCircumferenceAtDegree (x1, y1, 315);
// calc center of the right wing from here
rightWingCenterX = pv1.x + cos( radians(315)) * 50;
arc(rightWingCenterX, y1, 100, 100, radians(225), radians(315));
} else if (numberRandom <0.3333) {
// Bird 2: wings are very high up
arc(x2, y2, 100, 100, radians(270), radians(360));
PVector pv2 = getPVectorOfPositionOnCircumferenceAtDegree (x2, y2, 360);
rightWingCenterX = pv2.x + cos( radians(360)) * 50;
arc(rightWingCenterX, y2, 100, 100, radians(180), radians(270));
} else {
// Bird 3: wings are low (can be low, can be high, random) // !!!
float add;
add = random(11, 28); // (17,88)
arc(x3, y3, 100, 100, radians(180+add), radians(270+add));
PVector pv3 = getPVectorOfPositionOnCircumferenceAtDegree (x3, y3, 270+add);
rightWingCenterX = pv3.x + cos(radians(270+add)) * 50;
arc(rightWingCenterX, y3, 100, 100, radians(270-add), radians(360-add));
}
}
}
}
// ----------------------------------------------------------------------------
PVector getPVectorOfPositionOnCircumferenceAtDegree ( float x_, float y_, // center
float angleDegree_ ) { // angle on Circumference in degrees
// returns start- or endpoint of an arc()
float angleRadians = radians(angleDegree_);
float rad = 50;
// calc pos x1,y1 of small circle on the circumference / at angleDegree_
float xOnCircumference = x_ + cos(angleRadians) * rad ;
float yOnCircumference = y_ + sin(angleRadians) * rad ;
return new PVector(xOnCircumference, yOnCircumference);
}
//