Hello, I need help with adding a timer in my code for processing. This time need
ID: 3691207 • Letter: H
Question
Hello, I need help with adding a timer in my code for processing. This time needs to count from 1min to 1:30 seconds. I want to be able to start it off and on by using a keypressed method or using the middle scroll button clicked turning it on or off. I also have an image imported, but it isn't working properly. I want it to pop up for 10 seconds after being clicked each time I press spacebar. Here is what I have so far for my code below. It is going to be a time memory based game where the user has to draw the image and test their memory on how to complete the drawing in said time.
Here is the code I made so far below.
// EDSFinalGroup46
import controlP5.*;
ControlP5 cp5;
int brushSize = 5;
boolean brushType = false;
boolean eraserType = false;
boolean imageDisplay = false;
boolean frameSaved = false;
color c = color(128, 0, 255);
PImage Celtic_Pattern;
int s = 0;
int m = 0;
/*******************************/
void setup() {
size(800, 800);
frameRate(60);
cp5 = new ControlP5( this );
cp5.addColorWheel("c", 596, 3, 200 ).setRGB(c);
noStroke();
background(0, 255, 255);
Celtic_Pattern = loadImage("Celtic_Pattern.png");
//Below is the drawing area black border.
stroke(0);
strokeWeight(8);
rect(10, 220, 780, 570);
rect(600, 260, 170, 180);
fill(255);
PFont font;
font = loadFont("UrbanClass-10.vlw");
//Instructions are below in this code.
String s = "Your objective is to complete the following drawing in 1 minute 30 seconds. If you don't finish then restart and try again! This is only a beta. Draw freely too if you just want to create a cool image of your own.";
fill(50);
text(s, 10, 10, 400, 200); // Text wraps within text box
//Below is "Draw Here!" inside of rect.
textFont(font, 13);
fill(0);
text("Draw Here!", 360, 240);
text("Draw this image below!", 595, 240 );
noStroke();
noLoop();
}
/*******************************/
void draw() {
if (imageDisplay) {
if (keyPressed == true) {
if (key == ' ') {
image(Celtic_Pattern, 605, 265, 160, 170);
}
}
}
println(mouseX + " " + mouseY);
if ( mouseX < 780 && mouseX > 21 )
if ( mouseY > 235 && mouseY < 780 ) {
if (brushType) {
fill(c);
ellipse(mouseX, mouseY, brushSize, brushSize);
} else if (eraserType) {
fill(255);
ellipse(pmouseX, mouseY, brushSize, brushSize);
}
}
frameSaved = false;
if(keyPressed == true) {
if(key == 115 && frameSaved == false) {
saveFrame("Sketch_Made.png");
frameSaved = true;
}
} else{
frameSaved = false;
}
}
/*******************************/
void mousePressed() { // When we click, it changes.
if (mouseButton == RIGHT) {
eraserType = true;
} else if (mouseButton == LEFT) {
brushType = true;
}
loop();
}
/*******************************/
void mouseReleased() {
eraserType = brushType = false;
noLoop();
}
/*******************************/
void mouseWheel(MouseEvent event) {
int g = int(event.getCount());
if (g < 0) {
if (brushSize >= 1)
brushSize += g;
println(g + " -- " + brushSize);
} else {
brushSize += g;
println(g + " ++ " + brushSize);
}
}
void keyPressed(){
textAlign(200, 30);
textSize(12);
delay(1000);
if(s<=59){
text(m+":"+s,width/2,height/2);
}
}
Explanation / Answer
Ans :
if(ImageDisplay)
Image(.....
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.