Skip to content

Instantly share code, notes, and snippets.

@kasperkamperman
Created June 22, 2016 20:23
Show Gist options
  • Save kasperkamperman/425c140a4c60f8ddf5bdc358474a83cf to your computer and use it in GitHub Desktop.
Save kasperkamperman/425c140a4c60f8ddf5bdc358474a83cf to your computer and use it in GitHub Desktop.
Processing concept with a concept to draw on.
//https://processing.org/reference/clear_.html
// we use a canvas (PGraphics) to draw on.
// in this case we can erase it (now with keypress)
// and we can display our "pen" without that it draws itself on the canvas.
PGraphics canvas;
color selectedColor;
void setup() {
size(640, 360);
//background(102);
// make a smaller canvas then your window
// in this case 100 pixels less
canvas = createGraphics(width-100,height-100);
canvas.beginDraw();
canvas.background(255);
canvas.endDraw();
}
void draw() {
background(0);
drawSwatches();
// we are in the menu (top)
if(mouseY < 50) {
// sample the color
// and make the ellipse that color
selectedColor = get(mouseX, mouseY);
fill(selectedColor);
}
ellipse(mouseX,mouseY,10,10);
canvas.beginDraw();
if(mousePressed) {
canvas.stroke(selectedColor);
canvas.line(mouseX-50, mouseY-50, pmouseX-50, pmouseY-50);
}
canvas.endDraw();
image(canvas,50,50);
}
void drawSwatches() {
fill(255,0,0);
rect(0,0,50,50);
fill(0,255,0);
rect(50,0,50,50);
fill(0,0,255);
rect(100,0,50,50);
}
void keyPressed() {
// clean the canvas
canvas.beginDraw();
canvas.clear();
canvas.endDraw();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment