Run part of code inside draw() once
in
Programming Questions
•
1 year ago
Hello
Just a quick question?
how can you run just a part of the code within draw() just once, but the rest of the code continuously ?
I've looked into redraw() and loop() but it doesn't seem work.
I would like the code in red to be run once, and the rest of it inside draw to run continuously.
thanks
- void setup() {
- size(screenWidth, screenHeight);
- smooth();
- ellipseMode(RADIUS);
- noStroke();
- }
- void draw() {
- float x = screenWidth/2;
- float y = screenHeight/3;
- float x1 = screenWidth/2;
- float y1 = screenHeight/1.5;
- int radius = 100;
- int radius1 = 100;
- background(255);
- float d = dist(mouseX, mouseY, x, y);
- float d1 = dist(mouseX, mouseY, x1, y1);
- if (mousePressed && (d < radius)) {
- x = random(screenWidth);
- y = random(screenHeight);
- radius++;
- radius1--;
- fill(0);
- }else{
- fill(0);
- }
- ellipse (x, y, radius, radius);
- if (mousePressed && (d1 < radius1)) {
- x1 = random(screenWidth);
- y1 = random(screenHeight);
- radius1++;
- radius--;
- fill(0);
- }else{
- fill(0);
- }
- fill(255, 0, 0);
- ellipse (x1, y1, radius1, radius1);
- }
1