Processing: Interface I
Processing: Interface I
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