09 Functions 20130531
09 Functions 20130531
Functions
()
09
Structure 3: Functions
Function
Function
Function
()
()
()
void
defun
procedure
subroutine
sub
function
Processing
LISP
PASCAL
FORTRAN
BASIC
1.
2.
3.
4.
()
()
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
ellipseMode(CENTER);
smooth();
frameRate(10);
}
void draw() {
rect_circle(random(width),random(height));
}
void rect_circle (float x, float y) {
fill(0);
rect(x,y,100,100);
fill(255);
ellipse(x,y,100,100);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
ellipseMode(CENTER);
smooth();
frameRate(5);
}
void draw() {
rect_circle(random(width),random(height));
}
void rect_circle (float x, float y) {
fill(0);
rect(x,y,100,100);
fill(255);
ellipse(x,y,100,100);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
ellipseMode(CENTER);
smooth();
frameRate(5);
}
void draw() {
rect_circle(random(width),random(height));
}
void rect_circle (float x, float y) {
float w = random(60);
fill(0);
rect(x,y,w,w);
fill(255);
ellipse(x,y,w,w);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
ellipseMode(CENTER);
smooth();
frameRate(5);
}
void draw() {
rect_circle(random(width),random(height));
}
void rect_circle (float x, float y) {
float w = random(60);
fill(random(255),random(255),random(255));
rect(x,y,w,w);
fill(255);
ellipse(x,y,w,w);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
ellipseMode(CENTER);
smooth();
frameRate(20);
}
void draw() {
rect_circle(random(width),random(height));
}
void rect_circle (float x, float y) {
float w = random(20,60);
fill(random(255),random(255),random(255));
rect(x,y,w,w);
fill(255);
ellipse(x,y,w,w);
}
void setup() {
size(400,400);
background(255);
}
void draw() {
fill(0);
rect(50,50,100,100);
fill(255);
rect(50,50,80,80);
fill(0);
rect(50,50,60,60);
fill(255);
rect(50,50,40,40);
fill(0);
rect(50,50,20,20);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
}
void draw() {
fill(0);
rect(50,50,100,100);
fill(255);
rect(50,50,80,80);
fill(0);
rect(50,50,60,60);
fill(255);
rect(50,50,40,40);
fill(0);
rect(50,50,20,20);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
}
void draw() {
five_rects();
}
void draw() {
five_rects();
}
void five_rects() {
fill(0);
rect(50,50,100,100);
fill(255);
rect(50,50,80,80);
fill(0);
rect(50,50,60,60);
fill(255);
rect(50,50,40,40);
fill(0);
rect(50,50,20,20);
}
void five_rects() {
for (int i = 0; i < 5; i += 1) {
if ((i % 2) == 1) {fill(255);} else {fill(0);}
rect(50,50,100-20*i,100-20*i);
}
}
void draw() {
five_rects(random(width),random(height));
}
void setup() {
size(400,400);
background(255);
rectMode(CENTER);
}
void draw() {
five_rects(random(width),random(height));
}
void five_rects (float x, float y) {
for (int i = 0; i < 5; i += 1) {
if ((i % 2) == 1) {fill(255);} else {fill(0);}
rect(x,y,100-20*i,100-20*i);
}
}
void setup() {
size(400,400);
background(255);
//rectMode(CENTER);
}
void draw() {
five_rects(random(width),random(height));
}
void five_rects (float x, float y) {
for (int i = 0; i < 5; i += 1) {
if ((i % 2) == 1) {fill(255);} else {fill(0);}
rect(x,y,100-20*i,100-20*i);
}
}
void setup() {
size(400,400);
background(255);
//rectMode(CENTER);
frameRate(6);
}
void draw() {
five_rects(random(width),random(height));
}
void five_rects (float x, float y) {
if (random(1 ,3) >= 2) {rectMode(CENTER);}
else {rectMode(CORNER);}
for (int i = 0; i < 5; i += 1) {
if ((i % 2) == 1) {fill(255);} else {fill(0);}
rect(x,y,100-20*i,100-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
frameRate(5);
}
void draw() {
circles(random(width),random(height));
}
void circles (float x, float y) {
for (int i = 0; i < 5; i += 1) {
if ((i % 2) == 1) {fill(255);} else {fill(0);}
ellipse(x,y,100-20*i,100-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
frameRate(5);
}
void draw() {
circles(random(width),random(height));
}
void circles (float x, float y) {
for (int i = 0; i < 5; i += 1) {
fill(random(255),random(255),random(255));
ellipse(x,y,100-20*i,100-20*i);
}
}
void draw() {
int i;
circles(random(width),random(height),int(random(1,5)));
}
void circles (float x, float y, int step) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255));
ellipse(x,y,100-20*i,100-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
frameRate(5);
}
void draw() {
int i;
circles(random(width),random(height),
int(random(1,5)));
}
void circles (float x, float y, int step) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255));
ellipse(x,y,100-20*i,100-20*i);
}
}
void draw() {
int i;
circles(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void circles (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255));
ellipse(x,y,d-20*i,d-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
frameRate(5);
}
void draw() {
int i;
circles(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void circles (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255));
ellipse(x,y,d-20*i,d-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
frameRate(5);
}
void draw() {
int i;
circles(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void circles (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255),125);
ellipse(x,y,d-20*i,d-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
noStroke();
}
void draw() {
int i;
frameRate(5);
circles(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void circles (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255),150);
ellipse(x,y,d-20*i,d-20*i);
}}
void setup() {
size(400,400);
background(255);
smooth();
noStroke();
frameRate(5);
}
void draw() {
int i;
many_rects(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void many_rects (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255),255);
rect(x,y,d-20*i,d-20*i);
}
}
void setup() {
size(400,400);
background(255);
smooth();
noStroke();
rectMode(CENTER);
frameRate(5);
}
void draw() {
int i;
many_rects(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void setup() {
size(400,400);
background(255);
smooth();
noStroke();
rectMode(CENTER);
frameRate(5);
}
void draw() {
int i;
many_rects(random(width),random(height),
int(random(1,10)),int(random(100,200)));
}
void many_rects (float x, float y, int step, int d) {
for (int i = 0; i < step; i += 1) {
fill(random(255),random(255),random(255),
random(255));
rect(x,y,d-20*i,d-20*i);
}
}
Ch. 21
05/31/2013