We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im making a "guestbook" data visualization for a project im working on. I have the home screen where users can choose a colour and sign their name but im looking to create a button to change the screen into the next stage of the guestbook which will ask the user questions. Im stuck on creating a new screen and a simple button to click and change the screens. PLS HELP
PImage bg;
PImage refresh;
int y;
int shade1;
int shade2;
int shade3;
int shade4;
int shade5;
int shade6;
int shade7;
color currentColor;
boolean typeIsRect;
void setup() {
size(900, 600);
background(255);
bg = loadImage("test.png");
image(bg, 0, height-150, width, 150);
refresh = loadImage("refresh.png");
image(refresh, 10, 10, 50, 50);
frameRate(60);
shade1 = color(#CBEBF4);
shade2 = color( #7B8EC4);
shade3= color( #394C9F);
shade4= color( #59426E);
shade5= color( #72312F);
shade6= color(#A04647 );
shade7= color(#E1B9D7);
currentColor = color(255);
typeIsRect = true;
}
void draw() {
smooth();
//Light Blue
stroke(150);
strokeWeight(1.2);
fill(shade1);
rect(100, 30, 90, 50, 2);
//Pale blue
stroke(150);
strokeWeight(1.2);
fill(#7B8EC4);
rect(200, 30, 90, 50, 2);
////////////////////////////
//Dark Blue
stroke(150);
strokeWeight(1.2);
fill(#394C9F);
rect(300, 30, 90, 50, 2);
////////////////////////////
//purple
stroke(150);
strokeWeight(1.2);
fill(#59426E);
rect(400, 30, 90, 50, 2);
////////////////////////////
//purply red
stroke(150);
strokeWeight(1.2);
fill(#72312F);
rect(500, 30, 90, 50, 2);
////////////////////////////
//pale red
stroke(150);
strokeWeight(1.2);
fill(#A04647);
rect(600, 30, 90, 50, 2);
////////////////////////////
//light pink
stroke(150);
strokeWeight(1.2);
fill(#E1B9D7);
rect(700, 30, 90, 50, 2);
if (mousePressed) {
stroke(currentColor);
strokeWeight(2);
line(pmouseX, pmouseY, mouseX, mouseY);
println("Previous mouse postion x: " + pmouseX + " y; " +
pmouseY + " current mouse postion x : " + mouseX + " y " + mouseY);
}
}
void mousePressed() {
//REFRESH THE BACKGROUND TO WHITE
if ((mouseX>0) && (mouseY>0) && (mouseX<60) && (mouseY<60))
{
background(255);
currentColor=(255);
image(bg, 0, height-150, width, 150);
image(refresh, 10, 10, 50, 50);
}
//SHADE 1
if ((mouseX>100) && (mouseY>20) && (mouseX<190) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade1);
line(pmouseX, pmouseY, mouseX, mouseY);
}
//SHADE 2
if ((mouseX>200) && (mouseY>20) && (mouseX<290) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade2);
}
//SHADE 3
if ((mouseX>300) && (mouseY>20) && (mouseX<390) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade3);
}
//SHADE 4
if ((mouseX>400) && (mouseY>20) && (mouseX<490) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade4);
}
//SHADE 5
if ((mouseX>500) && (mouseY>20) && (mouseX<590) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade5);
}
//SHADE 6
if ((mouseX>600) && (mouseY>20) && (mouseX<690) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade6);
}
//SHADE 7
if ((mouseX>700) && (mouseY>20) && (mouseX<790) && (mouseY<70))
{
typeIsRect = false;
currentColor = color(shade7);
}
}
Answers
Have a new variable
state
or page of type int defined beforesetup()
In draw() use
to evaluate state.
state
tells you on which page you areRULE: Outside this switch() nothing is allowed in draw(). This means, everything that happens in your sketch must happen in a defined state. So for a help page just create a new state.
Now when user presses enter or mouse just say state = 1; or state=2...
you can also name the states, so instead of 0 you can write stateGame.
The switch code of draw() must also be applied in mousePressed and keyPressed, because the mouse and key inputs mean different things on different pages of your sketch.
example:
How to post in the processing forum.
Best is to hit ctrl-t in processing first before copy paste into the forum (https://forum.processing.org).
You can edit your post (click the small gear and the 'Edit').
How to format Code:
Please don't start new questions for things that obviously follow on from previous code. Especially when you haven't responded once to the previous question.
So here's the place to pose your second question. Post the current code and say what else you want it to do (ie loop back to the beginning)
Go back edit your post
Format your code better
See above
(done)
Sorry, when my previous sketch was too long.
I made a shorter version now.
The idea is that you have a variable
state
that indicates which screen you are on. You can even give the states names such as stateGame or statePause.By using a variable state you can
evaluate the variable to know which screen must be shown in draw().
You can do this evaluation with
switch()
or withif(state==stateGame) {...} else if (state==statePause ) {...}
which is essentially the same.You can set state to whatever value you need - see function keyPressed below
Since the information on which screen we are is stored in ONE variable, all parts of the program know the current screen.
Best, Chrisir ;-)
As a bonus I worked on with your sketch and have added a new screen where 2 questions are being asked.
I don't have you images (bg and refresh) so that's missing.
If you have questions do not hesitate to ask me.
Some parts are over my head, they are from gotoloop.
Chrisir ;-)