Upload
hawping-yap
View
226
Download
4
Tags:
Embed Size (px)
DESCRIPTION
NATURAL SYSTEM STUDIO
Citation preview
natural system studioYap Haw Ping 575513
A set of dots move from side to side. The frequency of the oscillation increases from top to bottom. The effect is a series of unfolding structures including spirals and beats.
int howManyOscillators = 30;Oscillator[] osSet = new Oscillator[howManyOscillators];
int beginY = 0;int endY = 800;
float Ylocation = beginY;float Yincrement = (endY - beginY) / (howManyOscillators-1);
float beginFrequency = 1;float frequencyValue = beginFrequency;
float frequencyIncrement = 0.02;void setup() {
for (int i=0;i<howManyOscillators;i++) { osSet[i] = new Oscillator(Ylocation,frequencyValue);
Ylocation += Yincrement; frequencyValue += frequencyIncrement;
}
size(400,800); smooth();
frameRate(30);
//noLoop();}
void draw() { background(1);
for (int i = 0;i<howManyOscillators;i++) { osSet[i].update();
}}
class Oscillator { float angle = 0;
float angleIncrement = TWO_PI / 360; float centre, maximumDisplacement, frequency, verticalPosition;
int dotRadius; float xPosition;
Oscillator(float verticalPositionIn, float frequencyIn) { centre = 200;
maximumDisplacement = 150; frequency = frequencyIn;
dotRadius = 15; verticalPosition = verticalPositionIn;
}
void update() { xPosition = centre + maximumDisplacement * sin(angle * frequency);
fill(255,255,255); stroke(255,255,255);
ellipse(xPosition,verticalPosition,dotRadius,dotRadius); angle += angleIncrement;
if (angle == (TWO_PI - angleIncrement)) angle = 0; }}
Oscillation exercise
ArrayList agents;ArrayList attrPoints;ArrayList repPoints;
int agentsAmount=17000;
int attrAmount=7;int repAmount=7;
void setup(){
size(900,600,P2D); stroke(0);
agents=new ArrayList(); attrPoints=new ArrayList(); repPoints=new ArrayList();
for(int i=0;i<attrAmount;i++){
attrPoints.add(new PVector(round(random(10,width-10)),round(random(10,height-10))));//create attraction points
} for(int i=0;i<repAmount;i++){
repPoints.add(new PVector(round(random(10,width-10)),round(random(10,height-10))));//create repulsion points
}
for(int i=0;i<agentsAmount;i++){ agents.add(new Agent(round(random(10,width-10)),
round(random(10,height-10))));//create agents }}
void draw(){ background(70);
for(int i=0;i<agents.size();i++){ Agent a =(Agent)agents.get(i);
a.move(); a.display();
}
for(int i=0;i<attrPoints.size();i++){//display attraction points PVector aPt=(PVector)attrPoints.get(i);
fill(0,100,200); ellipse(aPt.x,aPt.y,10,10);
}
for(int i=0;i<repPoints.size();i++){//display repulsion points PVector rPt=(PVector)repPoints.get(i);
fill(200,0,100); ellipse(rPt.x,rPt.y,10,10);
} }
class Agent{ PVector pos, vel, followSum, escapeSum;
color c;
Agent(int _x, int _y){ pos=new PVector(_x,_y);
vel=new PVector(0,0); followSum=new PVector(0,0);
escapeSum=new PVector(0,0); c=color(random(255),random(255),random(255));
} void move(){
vel.add(follow()); vel.add(escape());
vel.limit(1); pos.add(vel);
}
void display(){ set((int)pos.x,(int)pos.y,c);
}
PVector follow(){///////////attraction force followSum.mult(0);
int count=0; for(int i=0; i<attrPoints.size();i++){
PVector aPt=(PVector)attrPoints.get(i); float d=pos.dist(aPt);
if (d<450){//attraction distance PVector dir = PVector.sub(aPt,pos);
dir.normalize(); dir.div(d);
followSum.add(dir); count++;
} }
if (count > 0) { followSum.div(count);
} return followSum;
} PVector escape(){///////////repulsion force
escapeSum.mult(0); int count=0;
for(int i=0; i<repPoints.size();i++){ PVector rPt=(PVector)repPoints.get(i);
float d=pos.dist(rPt); if (d<450){//repulsion distance
PVector dir = PVector.sub(rPt,pos); dir.normalize();
dir.div(d); escapeSum.sub(dir);
count++; } }
if (count > 0) { escapeSum.div(count);
} return escapeSum;
}}
Movement People + Attraction/Repulsion
Particle System - Bright Chaser
World world;ArrayList<Mover> pop = new ArrayList<Mover>();
//Mover global propertiesint numMovers = 5000;
int searchRad = 5;float maxSpeed =2;
a//world global properties
float fadeSpeed = 1;
void setup(){ size(800,800);
smooth();
world = new World( gradient.png );
//populate the sketch for (int i = 0; i<numMovers;i++){
Mover m = new Mover(new PVector(random(width),random(height)), new
PVector(random(-maxSpeed,maxSpeed),random(-maxSpeed,maxSpeed)), 1);
pop.add(m); }}
void draw(){ background(255);
world.drawImage(); world.fade(); //run the pop
for (Mover m:pop){ m.run();
}}
void keyPressed(){ if(key== s ){
saveFrame(hour()+minute()+second()+ .png ); } }
class World {
PImage loadedImage; // image to store float[][] vals;
int w,h;
World(String toImg){ loadedImage=loadImage(toImg); //load the source image
loadedImage.resize(width,height); loadedImage.loadPixels(); //load the pixel array
w = loadedImage.width; h = loadedImage.height;
vals = new float[w][h];
loadVals(); //loadBlank();
}
void loadVals(){ //fill up the brightness values array
for (int i = 0;i<w;i++){ for (int j = 0;j<h;j++){
vals[i][j]=brightness(loadedImage.pixels[(j*w)+i]); } } }
void loadBlank(){ for (int i = 0;i<w;i++){
for (int j = 0;j<h;j++){ vals[i][j]=0;
} //get a value from the image
float getAt(int x, int y){ return vals[x][y];
} //fade the image
void fade(){ for (int i = 0;i<w;i++){
for (int j = 0;j<h;j++){ if(vals[i][j]>fadeSpeed) vals[i][j]=vals[i][j]-fadeSpeed;
} } }
//write a new value to the image void setAt(int x, int y, float v){
v = constrain(v,0,255); vals[x][y]=v;
}
void modAt(int x, int y, float v){ float mod = constrain(vals[x][y]+v,0,255);
vals[x][y]=mod; }
void drawImage(){ loadPixels();
for (int i = 0;i<w;i++){ for (int j = 0;j<h;j++){
float b= constrain(vals[i][j],0,255); pixels[(j*w)+i] = color(b);
} }
updatePixels(); }}
Social Interaction between people in Queen Victoria Markethybridisation
int CheckpointNumber = 50; // Number of checkpointsint PersonNumber = 200; // Number of person(s)
float CheckpointX; // Distance among checkpoints (in X-axis)
ArrayList Checkpoint;ArrayList Person;
void setup(){ size(720, 480); background(255); smooth(); ellipseMode(RADIUS); Checkpoint = new ArrayList(); for(int i = 0; i < CheckpointNumber; i++) { CheckpointX += width/CheckpointNumber; // Make a checkpoint every [CheckpointX] pixels Checkpoint.add(new Checkpoint(CheckpointX, noise(CheckpointX) * height)); // Add checkpoints and randomize the height of the checkpoints } BuildPath(); // Build the paths for the person(s) Person = new ArrayList(); for(int i = 0; i < PersonNumber; i++) { Person.add(new Person()); } }
void draw(){ background(0); stroke(255, 0); DrawLines(); // Display the paths for(int i = 0; i < Person.size(); i++) { Person P = (Person) Person.get(i); P.Update(); P.Display(); } }
void keyPressed(){ if(key==’s’){ saveFrame(hour()+minute()+second()+ “.png”); } }
// Create paths between the checkpointsvoid BuildPath(){ boolean bIsInRange; for(int i = 0; i < CheckpointNumber; i++) { Checkpoint CP = (Checkpoint) Checkpoint.get(i); for(int j = 0; j < CheckpointNumber; j++) { Checkpoint OCP = (Checkpoint) Checkpoint.get(j); bIsInRange = dist(CP.X, CP.Y, OCP.X, OCP.Y) > 0 && dist(CP.X, CP.Y, OCP.X, OCP.Y) < 150; if(bIsInRange == true) // Make paths with checkpoints within range { CP.OpenCP[CP.OpenCPNumber] = j; CP.OpenCPNumber += 1; }void DrawLines(){ for(int i = 0; i < CheckpointNumber; i++) { Checkpoint CP = (Checkpoint) Checkpoint.get(i); for(int j = 0; j < CP.OpenCPNumber; j++) { Checkpoint OCP = (Checkpoint) Checkpoint.get(CP.OpenCP[j]); line(CP.X, CP.Y, OCP.X, OCP.Y); } }}