Remove Puff example

This commit is contained in:
Casey Reas
2013-04-25 18:07:10 -07:00
parent 413d833aba
commit c89c3311f6
4 changed files with 14 additions and 200 deletions
@@ -16,7 +16,7 @@ void setup() {
size(640, 360);
// The background image must be the same size as the parameters
// into the size() method. In this program, the size of the image
// is 650 x 360 pixels.
// is 640 x 360 pixels.
bg = loadImage("moonwalk.jpg");
}
@@ -1,90 +0,0 @@
/**
* Scribble Plotter
* by Ira Greenberg.
*
* Using 2-dimensional arrays, record end points
* and replot scribbles between points.
*/
int SCRIBBLE = 0;
int HATCHING = 1;
void setup(){
size(640, 360);
background(0);
// Create arrays to hold x, y coords
float[]x = new float[4];
float[]y = new float[4];
// create a convenient 2-dimensional
// array to hold x, y arrays
float[][]xy = {x, y};
// Record points
// X positions
xy[0][0] = 125;
xy[0][1] = 475;
xy[0][2] = 475;
xy[0][3] = 125;
// Y positions
xy[1][0] = 100;
xy[1][1] = 100;
xy[1][2] = 260;
xy[1][3] = 260;
// Call plotting function
makeRect(xy);
}
void makeRect(float[][]pts){
stroke(255);
// Scribble variables, that get passed as arguments to the scribble function
int steps = 100;
float scribVal = 3.0;
for (int i = 0; i < pts[0].length; i++){
// Plots vertices
strokeWeight(5);
point(pts[0][i], pts[1][i]);
// Call scribble function
strokeWeight(.5);
if (i > 0){
scribble(pts[0][i], pts[1][i], pts[0][i-1], pts[1][i-1], steps, scribVal, SCRIBBLE);
}
if (i == pts[0].length-1){
// Show some hatching between last 2 points
scribble(pts[0][i], pts[1][i], pts[0][0], pts[1][0], steps, scribVal*2, HATCHING);
}
}
}
/*
Scribble function plots lines between end points,
determined by steps and scribVal arguments.
two styles are available: SCRIBBLE and HATCHING, which
are interestingly only dependent on parentheses
placement in the line() function calls.
*/
void scribble(float x1, float y1, float x2, float y2, int steps, float scribVal, int style){
float xStep = (x2-x1)/steps;
float yStep = (y2-y1)/steps;
for (int i = 0; i < steps; i++){
if(style == SCRIBBLE){
if (i < steps-1){
line(x1, y1, x1+=xStep+random(-scribVal, scribVal), y1+=yStep+random(-scribVal, scribVal));
}
else {
// extra line needed to attach line back to point- not necessary in HATCHING style
line(x1, y1, x2, y2);
}
}
else if (style == HATCHING){
line(x1, y1, (x1+=xStep)+random(-scribVal, scribVal), (y1+=yStep)+random(-scribVal, scribVal));
}
}
}
-92
View File
@@ -1,92 +0,0 @@
/**
* Puff
* by Ira Greenberg.
*
* Series of ellipses simulating a multi-segmented
* organism, utilizing a follow the leader algorithm.
* Collision detection occurs on the organism's head,
* controlling overall direction, and on the individual
* body segments, controlling body shape and jitter.
*/
// For puff head
float headX;
float headY;
float speedX = .7;
float speedY = .9;
// For puff body
int cells = 1000;
float[] px= new float[cells];
float[] py= new float[cells];
float[] radiiX = new float[cells];
float[] radiiY = new float[cells];
float[] angle = new float[cells];
float[] frequency = new float[cells];
float[] cellRadius = new float[cells];
void setup(){
size(640, 360);
// Begin in the center
headX = width/2;
headY = height/2;
// Fill body arrays
for (int i = 0; i < cells; i++){
radiiX[i] = random(-7, 7);
radiiY[i] = random(-4, 4);
frequency[i]= random(-9, 9);
cellRadius[i] = random(16, 30);
}
frameRate(30);
}
void draw(){
background(0);
noStroke();
fill(255, 255, 255, 5);
// Follow the leader
for (int i = 0; i < cells; i++){
if (i == 0){
px[i] = headX + sin(radians(angle[i]))*radiiX[i];
py[i] = headY + cos(radians(angle[i]))*radiiY[i];
}
else{
px[i] = px[i-1] + cos(radians(angle[i]))*radiiX[i];
py[i] = py[i-1] + sin(radians(angle[i]))*radiiY[i];
// Check collision of body
if ((px[i] >= width-cellRadius[i]/2) || (px[i] <= cellRadius[i]/2)){
radiiX[i]*=-1;
cellRadius[i] = random(1, 40);
frequency[i]= random(-13, 13);
}
if ((py[i] >= height-cellRadius[i]/2) || (py[i] <= cellRadius[i]/2)){
radiiY[i]*=-1;
cellRadius[i] = random(1, 40);
frequency[i]= random(-9, 9);
}
}
// Draw puff
ellipse(px[i], py[i], cellRadius[i], cellRadius[i]);
// Set speed of body
angle[i] += frequency[i];
}
// Set velocity of head
headX += speedX;
headY += speedY;
// Check boundary collision of head
if ((headX >= width-cellRadius[0]/2) || (headX <=cellRadius[0]/2)){
speedX*=-1;
}
if ((headY >= height-cellRadius[0]/2) || (headY <= cellRadius[0]/2)){
speedY*=-1;
}
}