Skip to content

Instantly share code, notes, and snippets.

@Introscopia
Introscopia / input_event_monitor.pde
Last active June 5, 2017 21:03
displays a kind of graph of input event timings.
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] );
@Introscopia
Introscopia / Grav.pde
Last active September 19, 2017 19:23
finished gravitational particle system sketch.
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; //
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);
}
@Introscopia
Introscopia / Tori.txt
Created April 28, 2017 22:27
explaining the topology of screens that warp top-to-bottom and left-to-right,
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.
//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.
@Introscopia
Introscopia / OOP.pde
Last active May 5, 2017 17:19
bouncing ball demo LVL.3
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.
// Object of Arrays
Particle_system the_system;
Class Particle_system{
PVector[] positions, velocities;
}
// Array of Objects
Particle[] particle_system;
@Introscopia
Introscopia / vectors.pde
Created April 28, 2017 22:03
bouncing ball demo LVL.2
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;
@Introscopia
Introscopia / bounce.pde
Created April 21, 2017 20:27
bouncing ball demo in 20 line of (actual) code.
/*
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...