Cleaning up code
in
Programming Questions
•
1 year ago
Hey guys,
I've been having some trouble with my program and getting it to do a few things.. basically i need each seperate ellipse (4 of them) to fade out when a diameter of 200 is reached, and also, if possible, for the latter ellipse drawn be thinner than the previous ones.. (for example - first ellipse has a strokeWeight(5) second one has a strokeWeight(4), etc..)
I've managed to get the fade & strokeWeight to work - although my code seems... bulky. I've tried endlessly to convert it into a loop but have failed :(. Below is my code: (Yes, its really messy - Sorry about that!)
boolean start = false;
float dia;
int Xco;
int Yco;
int fade;
void setup() {
size (400, 400);
background(255);
smooth();
}
void mousePressed() {
start = true;
dia = 0;
Xco = mouseX;
Yco = mouseY;
fade = 255;
strokeWeight(0);
}
void draw() {
background(255);
if (start == true) {
{
strokeWeight(5); //Circle 1
stroke(0, fade);
ellipse( Xco, Yco, dia, dia);
if (dia > 50) { // Circle 2
strokeWeight(4);
stroke(0, fade);
fade--;
ellipse( Xco, Yco, dia-50, dia-50);
}
if (dia > 100) { //Circle 3
strokeWeight(3);
stroke(0, fade);
fade--;
ellipse( Xco, Yco, dia-100, dia-100);
}
if (dia > 150) { //Circle 4
strokeWeight(2);
stroke(0, fade);
fade--;
ellipse( Xco, Yco, dia-150, dia-150);
}
dia+=2;
}
}
}
Yes this is for an assignment - and just as a side note to my classmates who've been copying the adjusted code off of here every week and handing it in as your own... shame on you!
Thanks for your help! :)
1