I am having troubles with my image popping up right away. I was trying to make it where once you press spacebar the image pops up for 10 seconds then goes away after. Also, I wanted to add a timer using the controlP5 library, but I don't know where to place it in my code. I don't want it following the mouse I just want it to be above the drawing area and have a button to activate it and it turns off once it hits 1:30 seconds. Here is my code so far below:
import controlP5.*;
ControlP5 cp5;
int brushSize = 5;
boolean brushType = false;
boolean eraserType = false;
color c = color(128, 0, 255);
ControlTimer t;
Textlabel l;
PImage Celtic_Pattern;
/*******************************/
void setup() {
size(800, 800);
frameRate(60);
cp5 = new ControlP5( this );
cp5.addColorWheel("c", 596, 3, 200 ).setRGB(c);
noStroke();
background(0, 255, 255);
t = new ControlTimer();
l = new Textlabel(cp5,"--",100,100);
t.setSpeedOfTime(1);
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() {
l.setValue(t.toString());
l.draw(this);
l.setPosition(mouseX, mouseY);
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); // Call fill() before drawing so the previous frame's fill() doesn't overlap.
ellipse(mouseX, mouseY, brushSize, brushSize);
} else if (eraserType) {
fill(255);
ellipse(pmouseX, mouseY, brushSize, brushSize);
}
}
}
/*******************************/
void mousePressed() {
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() {
t.reset();
}