Hello,
Is there anyway to put a void statement into a PGraphics layer? I mean something like this.
circles.beginDraw();
circles.noStroke()
circles.fill(col);
circles.myArc(mouseX, mouseY);
circles.endDraw();
Here is my full code (sorry it is a bit long)
//Add possibility to change shapes (square, circle, arc, triangle)
PGraphics circles;
boolean randomCol;
int size = 50;
color circleColor;
color col;
float stop = 95;
int toDraw = 0;
float r = size / 2;
float yOffset = (4*r) / (3*PI);
float x1 = size;
float y1 = 0;
float x2 = size * cos(TWO_PI / 3);
float y2 = size * sin(TWO_PI / 3);
float x3 = size * cos(-TWO_PI / 3);
float y3 = size * sin(-TWO_PI / 3);
void setup()
{
fullScreen();
background(255);
fill(0);
circles = createGraphics(2000, 2000);
randomCol = false;
}
void draw()
{
background(255);
noStroke();
noCursor();
if (randomCol)
{
col = color(random(255), random(255), random(255));
}
if (mousePressed) //If mouse is pressed then draw
{
if (mouseY > stop) //If mouseY variable is underneath the text, then you can draw
{
drawCircles();
}
}
image(circles, 0, 0); //Print the second plane
fill(col);
if (toDraw == 0)
{
fill(col);
rect(mouseX-(size/2), mouseY-(size/2), size, size);
}
else if (toDraw == 1)
{
fill(col);
ellipse(mouseX, mouseY, size, size);
}
else if (toDraw == 2)
{
fill(col);
myArc(mouseX, mouseY);
}
else if (toDraw == 3)
{
fill(col);
myTriangle(mouseX, mouseY);
}
}
void drawCircles()
{
if (toDraw == 0)
{
circles.beginDraw();
circles.noStroke();
circles.fill(col);
circles.rect(mouseX-(size/2), mouseY-(size/2), size, size);
circles.endDraw();
}
else if (toDraw == 1)
{
circles.beginDraw();
circles.noStroke();
circles.fill(col);
circles.ellipse(mouseX, mouseY, size, size);
circles.endDraw();
}
else if (toDraw == 2)
{
circles.beginDraw();
circles.noStroke();
circles.fill(col);
circles.myArc(mouseX, mouseY);
circles.endDraw();
}
else if (toDraw == 3)
{
circles.beginDraw();
circles.noStroke();
circles.fill(col);
circles.myTriangle(mouseX, mouseY);
circles.endDraw();
}
}
void keyPressed()
{
if (key == CODED)
{
if (keyCode == UP)
{
toDraw = 0;
}
if (keyCode == DOWN)
{
toDraw = 1;
}
if (keyCode == RIGHT)
{
toDraw = 2;
}
if (keyCode == LEFT)
{
toDraw = 3;
}
}
if (key == TAB) //If tab is pressed, random colors
{
randomCol = !randomCol;
}
if (key == '1') //Press keys 0-9 to change size of the paint brush
{
size = 10;
stop = 75;
}
if (key == '2')
{
size = 20;
stop = 80;
}
if (key == '3')
{
size = 30;
stop = 85;
}
if (key == '4')
{
size = 40;
stop = 90;
}
if (key == '5')
{
size = 50;
stop = 95;
}
if (key == '6')
{
size = 60;
stop = 100;
}
if (key == '7')
{
size = 70;
stop = 105;
}
if (key == '8')
{
size = 80;
stop = 110;
}
if (key == '9')
{
size = 90;
stop = 115;
}
if (key == '0')
{
size = 0;
stop = 0;
}
if (key == 'b') //If statements make different keys activate different colors
{
randomCol = false; //We don't want random colors anymore
col = color(0, 0, 255);
}
if (key == 'B')
{
randomCol = false;
col = color(0);
}
if (key == 'c')
{
randomCol = false;
col = color(0, 255, 255);
}
if (key == 'g')
{
randomCol = false;
col = color(0, 255, 0);
}
if (key == 'G')
{
randomCol = false;
col = color(128, 128, 128);
}
if (key == 'm')
{
randomCol = false;
col = color(255, 0, 255);
}
if (key == 'M')
{
randomCol = false;
col = color(139, 69, 19);
}
if (key == 'o')
{
randomCol = false;
col = color(255, 140, 0);
}
if (key == 'p')
{
randomCol = false;
col = color(148, 0, 211);
}
if (key == 'P')
{
randomCol = false;
col = color(255, 192, 203);
}
if (key == 'r')
{
randomCol = false;
col = color(255, 0, 0);
}
if (key == 'w')
{
randomCol = false;
col = color(255);
}
if (key == 'y')
{
randomCol = false;
col = color(255, 255, 0);
}
//If you press the spacebar it clears the screen
if (key == ' ')
{
circles.beginDraw();
circles.background(255);
circles.endDraw();
}
if (key == ESC) //If you press escape it stops the program
{
exit();
}
}
void myTriangle(float cx, float cy)
{
circles.beginDraw();
circles.pushMatrix();
circles.translate(cx, cy);
circles.rotate(-PI/2);
circles.triangle(x1, y1, x2, y2, x3, y3);
circles.popMatrix();
circles.endDraw();
pushMatrix();
translate(cx, cy);
rotate(-PI/2);
triangle(x1, y1, x2, y2, x3, y3);
popMatrix();
}
void myArc(float cx, float cy)
{
circles.beginDraw();
circles.pushMatrix();
circles.translate(cx, cy - yOffset);
circles.arc(0, 0, size, size, 0, PI, CHORD);
circles.popMatrix();
circles.endDraw();
pushMatrix();
translate(cx, cy - yOffset);
arc(0, 0, size, size, 0, PI, CHORD);
popMatrix();
}
If you need me to be more specific of have any questions feel free to ask.