Final touches to paint program
in
Programming Questions
•
3 years ago
so im working on a paint app and its going good so far
got all the the color i want for now
now im adding buttons to save and start new picture, etc
when i click the save button, if save the picture to the sketch folder but doesnt let you continue to draw.
also i was wondering how i could center text in an ellipse,
and when i click on one of the ellipse buttons it draws a dot on it, id like that not to happen
int x=10;
int y=10;
int rsize = 30;
int csize=40;
int[] rectX = new int[20];
int[] rectY = new int[20];
int[] rectCol = new int [20];
int[] circX = new int[6];
int[] circY = new int[6];
PFont font;
void setup(){
background(135);
size(1675,980);
for (int i= 0; i < 20; i++){
rectX[i] = x +45 *i;
rectY[i] = y;
}
for (int o= 0; o < 6; o++){
circX[o] = 1000 +45 *o;
circY[o] = 25;
}
rectCol[0] = color(0); //black
rectCol[1] = color(255); //white
rectCol[2] = color(46,11,11); //brown
rectCol[3] = color(120,10,10); // dark red
rectCol[4] = color(255,0,0); //red
rectCol[5] = color(250,71,74); // light red
rectCol[6] = color(245,59,255); //pinkish
rectCol[7] = color(232,0,245); // pink
rectCol[8] = color(129,3,137); //purple
rectCol[9] = color(55,55,250); //light blue
rectCol[10] = color(0,0,255); //blue
rectCol[11] = color(0,0,150); //dark blue
rectCol[12] = color(95,247,101); //light green
rectCol[13] = color(0,247,10); //lime green
rectCol[14] = color(0,103,4); //dark green
rectCol[15] = color(58,103,0); //yellow green
rectCol[16] = color(255,255,0); //yellow
rectCol[17] = color(255,100,0); //orange
rectCol[18] = color(155); // gray
rectCol[19] = color(55); //grayer
font = loadFont("font1.vlw");
textFont(font);
}
void draw(){
text("New",1030,20, circX[1],circY[1]);
text("Save",983,20, circX[0],circY[0]);
pushStyle(); // preserve current drawing settings
stroke(0);
strokeWeight(2);
for(int i = 0; i < 20; i++){
fill(rectCol[i]);
rect(rectX[i], rectY[i], rsize,rsize);
}
for(int o = 0; o < 6; o++){
noFill();
ellipse(circX[o], circY[o], csize,csize);
}
// restore the drawing style back
popStyle();
if((mousePressed==true)&&(mouseButton==LEFT)){
strokeCap(ROUND);
strokeWeight(10);
smooth();
line(pmouseX,pmouseY,mouseX,mouseY);
}
}
void mousePressed() {
for (int i = 0; i < rectX.length; i++) {
if (overRect(rectX[i], rectY[i], rsize, rsize)) { // Better define constants to replace 50
stroke(rectCol[i]);
line(pmouseX, pmouseY, mouseX, mouseY);
// No need to test the other rects
}
for (int o = 0; o < circX.length; o++) {
if (overCirc(circX[0], circY[0], csize)) { //save picture to sketch folder
saveFrame("picture.jpg");
continue;
}
if (overCirc(circX[1], circY[1], csize)) { // start picture over
background(135);
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
}
}
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
boolean overCirc(int x, int y, int diameter)
{
float disX = x - mouseX;
float disY = y - mouseY;
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}
got all the the color i want for now
now im adding buttons to save and start new picture, etc
when i click the save button, if save the picture to the sketch folder but doesnt let you continue to draw.
also i was wondering how i could center text in an ellipse,
and when i click on one of the ellipse buttons it draws a dot on it, id like that not to happen
int x=10;
int y=10;
int rsize = 30;
int csize=40;
int[] rectX = new int[20];
int[] rectY = new int[20];
int[] rectCol = new int [20];
int[] circX = new int[6];
int[] circY = new int[6];
PFont font;
void setup(){
background(135);
size(1675,980);
for (int i= 0; i < 20; i++){
rectX[i] = x +45 *i;
rectY[i] = y;
}
for (int o= 0; o < 6; o++){
circX[o] = 1000 +45 *o;
circY[o] = 25;
}
rectCol[0] = color(0); //black
rectCol[1] = color(255); //white
rectCol[2] = color(46,11,11); //brown
rectCol[3] = color(120,10,10); // dark red
rectCol[4] = color(255,0,0); //red
rectCol[5] = color(250,71,74); // light red
rectCol[6] = color(245,59,255); //pinkish
rectCol[7] = color(232,0,245); // pink
rectCol[8] = color(129,3,137); //purple
rectCol[9] = color(55,55,250); //light blue
rectCol[10] = color(0,0,255); //blue
rectCol[11] = color(0,0,150); //dark blue
rectCol[12] = color(95,247,101); //light green
rectCol[13] = color(0,247,10); //lime green
rectCol[14] = color(0,103,4); //dark green
rectCol[15] = color(58,103,0); //yellow green
rectCol[16] = color(255,255,0); //yellow
rectCol[17] = color(255,100,0); //orange
rectCol[18] = color(155); // gray
rectCol[19] = color(55); //grayer
font = loadFont("font1.vlw");
textFont(font);
}
void draw(){
text("New",1030,20, circX[1],circY[1]);
text("Save",983,20, circX[0],circY[0]);
pushStyle(); // preserve current drawing settings
stroke(0);
strokeWeight(2);
for(int i = 0; i < 20; i++){
fill(rectCol[i]);
rect(rectX[i], rectY[i], rsize,rsize);
}
for(int o = 0; o < 6; o++){
noFill();
ellipse(circX[o], circY[o], csize,csize);
}
// restore the drawing style back
popStyle();
if((mousePressed==true)&&(mouseButton==LEFT)){
strokeCap(ROUND);
strokeWeight(10);
smooth();
line(pmouseX,pmouseY,mouseX,mouseY);
}
}
void mousePressed() {
for (int i = 0; i < rectX.length; i++) {
if (overRect(rectX[i], rectY[i], rsize, rsize)) { // Better define constants to replace 50
stroke(rectCol[i]);
line(pmouseX, pmouseY, mouseX, mouseY);
// No need to test the other rects
}
for (int o = 0; o < circX.length; o++) {
if (overCirc(circX[0], circY[0], csize)) { //save picture to sketch folder
saveFrame("picture.jpg");
continue;
}
if (overCirc(circX[1], circY[1], csize)) { // start picture over
background(135);
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
}
}
boolean overRect(int x, int y, int width, int height)
{
if (mouseX >= x && mouseX <= x+width &&
mouseY >= y && mouseY <= y+height) {
return true;
} else {
return false;
}
}
boolean overCirc(int x, int y, int diameter)
{
float disX = x - mouseX;
float disY = y - mouseY;
if(sqrt(sq(disX) + sq(disY)) < diameter/2 ) {
return true;
} else {
return false;
}
}
1