This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Z, W; | |
String[] titles = { "frame", "mousePressed()", "mouseDragged()", "mouseReleased()", "mouseClicked()", "mouseWheel()", "keyPressed()", "keyReleased()", "keyTyped()" }; | |
float x, h, M; | |
float[] y; | |
void setup(){ | |
size(1200, 300); | |
x = 0; | |
for( int i = 0; i < titles.length; ++i ) if( textWidth( titles[i] ) > x ) x = textWidth( titles[i] ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ArrayList<Particle> PS; //Here's our array of objects | |
IntList marked; | |
float G = 0.2, one_over_pi = 1/PI; | |
float cx, cy; | |
float torus_x, torus_y, torus_l, torus_b, torus_w, torus_h; // position and dimensions of the torus box. | |
byte background_mode = 0; | |
boolean record = false; //true; // |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void gravitate( Particle p ){ | |
PVector grav = new PVector(1,0); | |
grav.setMag( G*(p.area()) / sq( constrain(dist(pos.x, pos.y, p.pos.x, p.pos.y), 1, 100000) ) ); | |
grav.rotate(atan2(p.pos.y - pos.y, p.pos.x - pos.x )); | |
acc.add(grav); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This creates a toroidal topology, | |
hence the name of the method and variables I used to accomplish this. | |
A torus is a doughnut shape, we say that these top-bottom and right-left | |
"warps" form a toroidal topology because | |
the only way to take a piece of paper and fold it such that | |
it actually connects those edges in that way | |
is to make a doughnut shape with it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//rudimentary inelastic collisions | |
for(int i = 1; i < PS.length; ++i){ // loop through the particle array | |
for(int j = 0; j < i; j++){ // only checking each pair of objects once. | |
if( PS[i].alive && PS[j].alive ){ | |
if( PS[i].pos.dist( PS[j].pos ) < PS[i].R + PS[j].R ){ | |
int a = ( PS[i].R > PS[j].R )? i : j; // the larger one | |
int b = ( a == i )? j : i; // absorbs the smaller one. | |
PS[a].vel.set( PS[b].vel.mult( (PI*sq(PS[b].R)) / (PI*sq(PS[a].R)) ) ); // gains it's kinetic energy | |
PS[a].R = sqrt( sq(PS[a].R) + sq(PS[b].R) ); // and it's area. | |
PS[a].D = PS[a].R * 2; // refresh the diameter. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Particle[] PS; //Here's our array of objects | |
float G = 0.2; | |
void setup(){ | |
size(800, 600); | |
// initialization for the array... | |
PS = new Particle[60]; | |
// and for each object. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Object of Arrays | |
Particle_system the_system; | |
Class Particle_system{ | |
PVector[] positions, velocities; | |
} | |
// Array of Objects | |
Particle[] particle_system; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PVector pos, vel; | |
float R, D; | |
void setup(){ | |
size(400, 400); | |
pos = new PVector( 200, 200 ); | |
vel = new PVector( random(-3, 3), random(-3, 3) ); | |
R = 10; | |
D = 2 * R; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
bouncing ball demo in 20 line of (actual) code. | |
first up we're declaring all our variables. | |
( We're telling the computer how much memory we're gonna use and we're making up names for the each memory chunk ) | |
they're all float(floating point numbers), which means they can be decimals, as well as whole numbers. | |
*/ | |
float ball_X, ball_Y, ball_VX, ball_VY, ball_R, ball_D; | |
// Setup is the function which runs once when the program starts up, it's where we... |
NewerOlder