Hello guys,
I’ve a question : The thing is that I have 2 codes and I want to combine them like this ; the basic code would be the image of DVD mooving across the screen and then put a mousePressed line so when we press the mouse the other codes appears but I really don’t know how to combine 2 void draw and setup into one and evreything so if someone understood what I’ve said and would be able to change my code or to help me it would be amazing ^^.
The code :
PImage dvd;
float b;
float d = 1;
float speedX = 3;
float speedY = 3;
float x = random(width);
float y = random(height);
void setup (){
fullScreen();
dvd = loadImage ("dvd.png");
}
void draw () { background (255);
bouger();
couleurs();
}
void couleurs() {
b = b + d;
tint (b, 255-b, b);
if (b > 255 || b < 0) { d = d * -1;}
}
void bouger() {
x = x + speedX;
y = y + speedY;
if (x < 0 || x > width - 339) { speedX = speedX * -1;}
if (y < 0 || y > height - 149) { speedY = speedY * -1;}
image (dvd,x,y);
}
And the second :
bug[] bugs = new bug[2000];
void setup() {
fullScreen();
for (int i = 0; i < bugs.length; i++) {
bugs[i] = new bug();
}
}
void draw() {
for (int i = 0; i < bugs.length; i++) {
bugs[i].fall();
bugs[i].show();
}
}
And on the other outlet of the same code the class “bug” :
class bug {
float x = random(width);
float y = random(-200,-100);
float speedY = random(4,10);
float taille = random (50, 70);
void fall() {
y = y+speedY;
if (y > height) {
y = random (-200,-100);
}
}
void show() {
fill(0);
line(x,y,x,y+taille);
}
}