0% found this document useful (0 votes)
2K views36 pages

Processing: Interface I

The document describes various mouse and drawing functions in Processing including: - Functions to get mouse position and button state like mouseX, mouseY, mousePressed. - Functions for drawing shapes that respond to mouse input like circles and rectangles called by mouse position. - Functions are used to draw random colored ellipses in a grid that shift based on mouse position. - Events like mousePressed and keyPressed are used to trigger drawing behaviors.

Uploaded by

Gene Kao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views36 pages

Processing: Interface I

The document describes various mouse and drawing functions in Processing including: - Functions to get mouse position and button state like mouseX, mouseY, mousePressed. - Functions for drawing shapes that respond to mouse input like circles and rectangles called by mouse position. - Functions are used to draw random colored ellipses in a grid that shift based on mouse position. - Events like mousePressed and keyPressed are used to trigger drawing behaviors.

Uploaded by

Gene Kao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 36

Processing

11
I nterface I
I
Input : Mouse I, II
mouseX, mouseY,
pmouseX, pmouseY,
mousePressed, mouseButton,
cursor(), noCursor().
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
}

void draw() {
noFill();
stroke(2);
circles(mouseX,mouseY);
}
void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50,50);
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
}

void draw() {
noFill();
stroke(2);
circles(mouseX,mouseY);
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50,50);
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
}

void draw() {
noFill();
stroke(2);
if (mousePressed == true) {
circles(mouseX,mouseY);
}
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50,50);
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
smooth();
strokeWeight(3);
}

void draw() {
noStroke();
fill(random(255),random(255),random(255),random(200));
if (mousePressed == true) {
circles(mouseX,mouseY);}
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50, 50);
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
smooth();
strokeWeight(3);
}

void draw() {
noStroke();
fill(random(255),random(255),random(255),random(200));
if (mousePressed == true) {
circles(mouseX,mouseY);}
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50,random(50));
}
void circles(int x, int y) {
translate(x,y);
ellipse(0,0,50,random(50));
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,random(100),random(100));
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
smooth();
strokeWeight(3);
}

void draw() {
noStroke();
fill(random(255),random(255),random(255),random(200));
if (mousePressed == true) {
circles(mouseX,mouseY);}
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,random(100),random(100));
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
smooth();
strokeWeight(3);
}

void draw() {
if (mousePressed == true) {
lines(mouseX,mouseY);}
}

void lines(int x, int y) {
translate(x,y);
line(0,0,random(100),random(100));
}
void lines(int x, int y) {
translate(x,y);
// stroke(random(255));
stroke(random(255),random(255),random(255));
float d = random(50);
line(0,0,d,d);
}
void setup() {
size(400,400);
background(255);
ellipseMode(CENTER);
smooth();
strokeWeight(3);
}

void draw() {
if (mousePressed == true) {
lines(mouseX,mouseY);}
}

void lines(int x, int y) {
translate(x,y);
// stroke(random(255));
stroke(random(255),random(255),random(255));
float d = random(50);
line(0,0,d,d);
}
void setup() {
size(400,400);
}
void draw() {
noFill();
stroke(1);
rectangles(mouseX,mouseY);
}
void rectangles(int x, int y) {
translate(x,y);
rect(-5,-5,10,10);
rect(-15,-15,30,30);
rect(-25,-25,50,50);
}
void setup() {
size(400,400);
}
void draw() {
noFill();
stroke(1);
if (mousePressed == true) {
rectangles(mouseX,mouseY);}
}
void rectangles(int x, int y) {
translate(x,y);
rect(-5,-5,10,10);
rect(-15,-15,30,30);
rect(-25,-25,50,50);
}
void setup() {
size(400,400);
ellipseMode(CENTER);
strokeWeight(2);
smooth();
}
void draw() {
noFill();
stroke(1);
if (mousePressed == true) {
Bulleye(mouseX,mouseY);}
}
void Bulleye(int x, int y) {
translate(x,y);
fill(255); ellipse(0,0,50,50);
fill(0); ellipse(0,0,30,30);
fill(255); ellipse(0,0,10,10);
}
void setup() {
size(400,400);
smooth();
}
void draw() {
noFill();
stroke(1);
if ((mousePressed == true) && (mouseButton == LEFT)) {
rectangles(mouseX,mouseY);}
if ((mousePressed == true) && (mouseButton == RIGHT)) {
circles(mouseX,mouseY);}
}
void rectangles(int x, int y) {
translate(x,y);
rect(-5,-5,10,10);
rect(-15,-15,30,30);
rect(-25,-25,50,50);
}

void circles(int x, int y) {
translate(x,y);
ellipse(0,0,10,10);
ellipse(0,0,30,30);
ellipse(0,0,50,50);
}
int num = 10;

void setup(){
size(400, 400); smooth(); noFill();
}

void draw() {
background(255);
for (int y = 0; y <= num; y ++) {
for (int x = 0; x <= num; x ++) {
stroke(random(255),random(255),random(255));
float posX = width / num * x;
float posY = height / num * y;
ellipse(posX, posY, 10, 10);
}}}
int num = 10;

void setup(){
size(400, 400); smooth(); noFill();
}

void draw() {
background(255);
randomSeed(0);
strokeWeight(mouseY / 50);
for (int y = 0; y <= num; y ++) {
for (int x = 0; x <= num; x ++) {
stroke(random(255),random(255),random(255));
float posX = width / num * x;
float posY = height / num * y;
float shiftX = random(-mouseX, mouseX) / 20;
float shiftY = random(-mouseX, mouseX) / 20;
ellipse(posX+shiftX, posY+shiftY, mouseY/5, mouseY/5);
}}}
void setup() {
size(100, 100);
noCursor();
}
void draw() {
background(204);
if (mousePressed == true) {
cursor();
}
}
void setup() {
size(100, 100);
strokeWeight(8);
smooth();
}
void draw() {
background(204);
line(mouseX, mouseY, pmouseX, pmouseY);
}
mousePressed(), mouseReleased(),
mouseMoved(), mouseDragged()
keyPressed(), keyReleased()
loop(), redraw()
Input 3:
Events (P.229)
constrain(),
dist(),
abs(),
atan2()
Input 4:
Mouse II (P.237)
Ch. 23, 27
06/07/2013

You might also like