I’m trying to program something for my cs class.
I want to make a program that I can use to write notes with my Wacom tablet.
the problem is that I don’t know how not draw things on top of each other.
when I erased something I have drawn with the doodle() I simple set the color of to match the background, problem is, that I also “erase” de lines from grid() , if a call grid() again, it would Draw on top of the things y draw with doodle(). is there a way I could fix this??
I’ve tried calling background again, then grid() and finally a method that draws my oldPoints, but it must be a better solution.
problem:
my code:
float x1,y1,x2,y2 ;
int col, oldCol ;
float weight, oldWeight ;
int wallpaper ;
public void grid(){
float xMargin = width/16 ;
float dy = xMargin/2 ;
float n = height/dy ;
strokeWeight(2) ;
stroke(color(194,214,249)) ;
for(int i=1 ; i<n ; i++) line(0,dy*i,width,dy*i) ;
stroke(color(250,83,83)) ;
line(xMargin,0,xMargin,height);
}
public void doodle(float mx, float my, float pmx, float pmy, boolean mPressed, int col, float weight){
strokeWeight(weight) ;
stroke(col) ;
if(mPressed){
beginShape() ;
curveVertex(x2,y2) ;
curveVertex(x1,y1) ;
curveVertex(pmx,pmy) ;
curveVertex(mx,my) ;
endShape() ;
}
x2 = x1 ;
y2 = y1 ;
x1 = pmx ;
y1 = pmy ;
}
public void keyPressed(){
if(key=='e'){
col = wallpaper ;
weight = 10*oldWeight ;
}
if(key=='p'){
col = oldCol ;
weight = oldWeight ;
}
if(key=='l') grid() ;
}
public void setup(){
size(1280,720) ;
displayDensity(1) ;
wallpaper = color(255,253,239) ;
background(wallpaper) ;
col = color(10,100,255) ;
oldCol = col ;
weight = 4 ;
oldWeight = weight ;
grid() ;
x1 = 0 ;
y1 = 0 ;
x2 = 0 ;
y2 = 0 ;
}
public void draw(){
doodle(mouseX,mouseY,pmouseX,pmouseY,mousePressed,col,weight) ;
}
I’m sorry for my broken English, tried my best.
sorry for the ugly code, I’m a n00b :3