Hello,
Just wondering if someone could help me (still extremely new to processing)
Ive created a sketch and im just trying to create a reset, so the user can press the space bar and everything will reset to normal.
Ive currently created a scene where on mouseclick the image changes to something else. After that though i want the user to be able to keyPress to get back to the beginning and start again.
Ive been looking through all the other posts and your responses trying to figure out what to do. Ive tried to create a "reset_sketch" but i cant work out what to declare for the code to work.
anyways so far this is what ive got.
int[] starX = new int[1000];
int[] starY = new int[1000];
color[] starColor = new color[1000];
int starSize = 3;
int[] shootX = new int[30];
int[] shootY = new int[30];
int METEOR_SIZE = 10;
float meteorSize = METEOR_SIZE;
float ssDeltaX, ssDeltaY;
int ssTimer = -1;
int startX, startY;
PImage landscape;
PImage image2;
PImage image1;
boolean mouseHasBeenPressed = false;
float easing = 0.05; float offset = 0;
void reset_sketch(){ //no idea what to put in here????
}
void setup() {
size(850, 709);
for (int i = 0; i < starX.length; i++) {
starX[i] =(int)random(width);
starY[i] = (int)random(height);
starColor[i] = color((int)random(100,255));
landscape = loadImage("b5.png");
image1 = loadImage("HIPPO.png");
image2 = loadImage("HIPPOBD.png");
reset_sketch();
}
}
void draw() {
background(61,213,250);
image(landscape, 0, 0);
float targetOffset = map(mouseY, 0, height, -10, 100); offset += (targetOffset - offset) * easing;
if (mouseHasBeenPressed == false) {
image(image1, 300 + offset,200);
} else {
background(2,8,57);
stroke(0);
strokeWeight(1);
for (int i = 0; i < starX.length; i++) {
fill(random(50,255)); // makes them twinkle
if (random(10) < 1) {
starColor[i] = (int)random(100,255);
}
fill(starColor[i]);
ellipse(starX[i], starY[i], starSize, starSize);
}
for (int i = 0; i < shootX.length-1; i++) {
int shooterSize = max(0,int(meteorSize*i/shootX.length));
if (shooterSize > 0) {
strokeWeight(shooterSize);
stroke(255);
}
else
noStroke();
line(shootX[i], shootY[i], shootX[i+1], shootY[i+1]);
}
meteorSize*=0.9;
for (int i = 0; i < shootX.length-1; i++) {
shootX[i] = shootX[i+1];
shootY[i] = shootY[i+1];
}
if (ssTimer >= 0 && ssTimer < shootX.length) {
shootX[shootX.length-1] = int(startX + ssDeltaX*(ssTimer));
shootY[shootY.length-1] = int(startY + ssDeltaY*(ssTimer));
ssTimer++;
if (ssTimer >= shootX.length) {
ssTimer = -1;
}
}
if (random(5) < 1 && ssTimer == -1) {
newShootingStar();
}
image(landscape, 0, 0);
image(image2, 300 + offset,200);
}
}
void newShootingStar() {
int endX, endY;
startX = (int)random(width);
startY = (int)random(height);
endX = (int)random(width);
endY = (int)random(height);
ssDeltaX = (endX - startX)/(float)(shootX.length);
ssDeltaY = (endY - startY)/(float)(shootY.length);
ssTimer = 0; // starts the timer which ends when it reaches shootX.length
meteorSize = METEOR_SIZE;
// by filling the array with the start point all lines will essentially form a point initialy
for (int i = 0; i < shootX.length; i++) {
shootX[i] = startX;
shootY[i] = startY;
}
}
void mousePressed() {
// Set mouseHasBeenPressed to true when mousePressed() is called
mouseHasBeenPressed = true;
}
void keyReleased(){
if( key == ' ' ){
reset_sketch();
}
}
1