// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 3-2: mouseX and mouseY
boolean mousePress = false;
void setup() {
size(640,360);
}
void draw() {
// Try moving background() to setup() and see the difference!
background(255);
// Body
stroke(0);
fill(175);
rectMode(CENTER);
// mouseX is a keyword that the sketch replaces with the horizontal position of the mouse.
// mouseY is a keyword that the sketch replaces with the vertical position of the mouse.
rect(mouseX,mouseY,50,50);
}
void mousePressed(){
stroke(255, 0, 0);
line(mouseX-10,mouseY, mouseX+10,mouseY);
line(mouseX,mouseY-10, mouseX,mouseY+10);
mousePress = true;
}
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 3-5: mousePressed and keyPressed
void setup() {
size(640, 360);
background(255);
}
void draw() {
// Nothing happens in draw() in this example!
}
// Whenever a user clicks the mouse the code written inside mousePressed() is executed.
void mousePressed() {
stroke(0);
fill(175);
rectMode(CENTER);
rect(mouseX,mouseY,16,16);
}
// Whenever a user presses a key the code written inside keyPressed() is executed.
void keyPressed() {
background(255);
}
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 3-5: mousePressed and keyPressed
void setup() {
size(640, 360);
background(255);
}
void draw() {
// Nothing happens in draw() in this example!
}
// Whenever a user clicks the mouse the code written inside mousePressed() is executed.
void mousePressed() {
stroke(255, 0, 0);
strokeWeight(2);
fill(175);
rectMode(CENTER);
//rect(mouseX,mouseY,16,16);
circle(int(mouseX),int(mouseY),16);
}
// Whenever a user presses a key the code written inside keyPressed() is executed.
void keyPressed() {
background(255);
}