Skip to content

Instantly share code, notes, and snippets.

@technogeek
Created April 10, 2010 17:16
Show Gist options
  • Save technogeek/362174 to your computer and use it in GitHub Desktop.
Save technogeek/362174 to your computer and use it in GitHub Desktop.
Processing example code
// -----------------------------doodle pad-----------------------------
// to draw, click and drag the mouse
// click on the palette to change color
// to adjust stroke weight use the up/down arrows
int guiX = 400;
int guiBtnWidth = 80;
int guiBtnHeight = 20;
PImage GUI;
int strokeWeight = 4;
String fileName = "doodle.png";
void setup() {
size(500, 400);
background(255);
smooth();
strokeWeight(strokeWeight);
GUI =loadImage("GUI.png");
}
void keyPressed() {
if (keyCode == UP) {
if (strokeWeight > 50) {
strokeWeight++;
strokeWeight(strokeWeight);
}
}
else if (keyCode == DOWN) {
if (strokeWeight > 1) {
strokeWeight--;
strokeWeight(strokeWeight);
}
}
}
void draw() {
if (mousePressed == true) {
if (mouseX < 400) {
line(pmouseX, pmouseY, mouseX, mouseY);
}
}
image(GUI, guiX, 0);
}
void mousePressed() {
// check that the mouse is horizontally within the GUI buttons area
if (mouseX > guiX + 10 && mouseX < guiX + 10 + guiBtnWidth) {
// save button
if (mouseY > 300 && mouseY < 300 + guiBtnHeight) {
saveDoodle();
}
// open button
if (mouseY > 335 && mouseY < 335 + guiBtnHeight) {
openDoodle();
}
// clear button
if (mouseY > 370 && mouseY < 370 + guiBtnHeight) {
background(255);
}
// color palette
if (mouseY > 10 && mouseY < 185) {
color c = get(mouseX, mouseY);
stroke(c);
}
}
}
void saveDoodle() {
save(fileName);
}
void openDoodle() {
PImage doodle;
doodle = loadImage("../" + fileName);
image(doodle, 0, 0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment