Hello. I want to finish my processing paint program but I ran into some complications.
My goal is to take out the grey rectangle and move the squares on the right hand side of the GUI Screen on the Y axis in a single vertical column. Once thats done I want to include the circles and finaly the Eraser.
Please don't go totally overboard on this I am a newbie so when you want to make a suggestion show your code but
explain it so that I can comprehend this tnx.
Here is what I have so far...
class Button {
color c;
boolean isRect;
float h;
float w;
float x;
float y;
Button() {
h = 20;
w = 20;
}
Button(color cVal, boolean isRectVal, float xVal, float yVal) {
this(); // call base constructor
c = cVal;
isRect = isRectVal;
x = xVal;
y = yVal;
}
boolean within(float xVal, float yVal) {
if (isRect) {
return(xVal > x - w/2 && xVal < x + w/2 && yVal > y - h/2 && yVal < y + h/2);
} else {
// assume a circle
return(dist(xVal, yVal, x, y) < h/2);
}
}
void display() {
stroke(0);
strokeWeight(1);
fill(c);
if (isRect) {
rectMode(CENTER);
rect(x,y,w,h);
} else {
ellipseMode(CENTER);
ellipse(x,y,w,h);
}
}
}
int Yellow;
int Red;
int Green;
int Blue;
int black;
int LightGrey;
color currentColor;
boolean typeIsRect;
Button[] colorButton = new Button[8]; // allocate space for 8 buttons
void setup()
{
size(640,480);
background(0);
frameRate(59);
Yellow = color(255,255,0);
Red = color(255,0,0);
Green = color(0,255,0);
Blue = color(0,0,255);
Orange = color(247,173,12);
black = color(0);
LightGrey = color(200);
currentColor = color(102);
typeIsRect = true;
PFont font;
textAlign(CENTER);
fill(95, 245, 183);
text("Paint Pro 3000", 300, 60);
// rects
colorButton[0] = new Button(Yellow, true, 30, 30);
colorButton[1] = new Button(Red, true, 60, 30);
colorButton[2] = new Button(Green, true, 90, 30);
colorButton[3] = new Button(Blue, true, 120, 30);
colorButton[4] = new Button(Orange, true, 150, 30);
// circles
colorButton[4] = new Button(Yellow, false, 30, 60);
colorButton[5] = new Button(Red, false, 60, 60);
colorButton[6] = new Button(Green, false, 90, 60);
colorButton[7] = new Button(Blue, false, 120, 60);
colorButton[8] = new Button(Orange, false, 150, 60);
}
{
size(640,480);
background(0);
frameRate(59);
Yellow = color(255,255,0);
Red = color(255,0,0);
Green = color(0,255,0);
Blue = color(0,0,255);
Orange = color(247,173,12);
black = color(0);
LightGrey = color(200);
currentColor = color(102);
typeIsRect = true;
PFont font;
textAlign(CENTER);
fill(95, 245, 183);
text("Paint Pro 3000", 300, 60);
// rects
colorButton[0] = new Button(Yellow, true, 30, 30);
colorButton[1] = new Button(Red, true, 60, 30);
colorButton[2] = new Button(Green, true, 90, 30);
colorButton[3] = new Button(Blue, true, 120, 30);
colorButton[4] = new Button(Orange, true, 150, 30);
// circles
colorButton[4] = new Button(Yellow, false, 30, 60);
colorButton[5] = new Button(Red, false, 60, 60);
colorButton[6] = new Button(Green, false, 90, 60);
colorButton[7] = new Button(Blue, false, 120, 60);
colorButton[8] = new Button(Orange, false, 150, 60);
}
void draw()
{
rectMode(CORNER);
stroke(5);
smooth();
fill(LightGrey);
rect(10,10,600,70);
fill(black);
rect(140,20,50,50);
// display all buttons
boolean overButton = false;
for (int i = 0; i < colorButton.length; i++) {
colorButton[i].display();
if (colorButton[i].within(mouseX, mouseY)) overButton = true;
}
if (overButton) cursor(HAND); else cursor(CROSS);
if (mousePressed)
{
noStroke();
rectMode(CENTER);
fill(currentColor);
if (typeIsRect)
{
if ((mouseX>140) && (mouseY>20) && (mouseX<190) && (mouseY<70))
{
rect(mouseX-25,mouseY-25,50,50);
}
else
{
rect(mouseX-10,mouseY-10,20,20);
}
}
else
{
ellipse(mouseX,mouseY,20,20);
}
}
}
{
rectMode(CORNER);
stroke(5);
smooth();
fill(LightGrey);
rect(10,10,600,70);
fill(black);
rect(140,20,50,50);
// display all buttons
boolean overButton = false;
for (int i = 0; i < colorButton.length; i++) {
colorButton[i].display();
if (colorButton[i].within(mouseX, mouseY)) overButton = true;
}
if (overButton) cursor(HAND); else cursor(CROSS);
if (mousePressed)
{
noStroke();
rectMode(CENTER);
fill(currentColor);
if (typeIsRect)
{
if ((mouseX>140) && (mouseY>20) && (mouseX<190) && (mouseY<70))
{
rect(mouseX-25,mouseY-25,50,50);
}
else
{
rect(mouseX-10,mouseY-10,20,20);
}
}
else
{
ellipse(mouseX,mouseY,20,20);
}
}
}
void mousePressed() {
for (int i = 0; i < colorButton.length; i++) { // cycle through each button
if (colorButton[i].within(mouseX, mouseY)) { // is the mouse within the button's space
switch(i) { // is so hanle based on i, or the button
case 0:
currentColor = Yellow;
typeIsRect = true;
break;
case 1:
currentColor = Red;
typeIsRect = true;
break;
case 2:
currentColor = Green;
typeIsRect = true;
break;
case 3:
currentColor = Blue;
typeIsRect = true;
break;
case 4:
currentColor = Orange
typeIsRect = true
break;
case 5:
currentColor = Yellow;
typeIsRect = false;
break;
case 5:
currentColor = Red;
typeIsRect = false;
break;
case 6:
currentColor = Green;
typeIsRect = false;
break;
case 7:
currentColor = Blue;
typeIsRect = false;
break;
currentColor = Orange;
typeIsRect = false;
break;
}
}
}
}
}
for (int i = 0; i < colorButton.length; i++) { // cycle through each button
if (colorButton[i].within(mouseX, mouseY)) { // is the mouse within the button's space
switch(i) { // is so hanle based on i, or the button
case 0:
currentColor = Yellow;
typeIsRect = true;
break;
case 1:
currentColor = Red;
typeIsRect = true;
break;
case 2:
currentColor = Green;
typeIsRect = true;
break;
case 3:
currentColor = Blue;
typeIsRect = true;
break;
case 4:
currentColor = Orange
typeIsRect = true
break;
case 5:
currentColor = Yellow;
typeIsRect = false;
break;
case 5:
currentColor = Red;
typeIsRect = false;
break;
case 6:
currentColor = Green;
typeIsRect = false;
break;
case 7:
currentColor = Blue;
typeIsRect = false;
break;
currentColor = Orange;
typeIsRect = false;
break;
}
}
}
}
}
1