Skip to content

Instantly share code, notes, and snippets.

View rect_clipper.c
#include <stdlib.h>
#include <stdio.h>
#include <SDL.h>
#define min(a,b) (((a)<(b))?(a):(b))
#define max(a,b) (((a)>(b))?(a):(b))
typedef int bool;
typedef struct{
View binary_search_VS_division.c
/*
Testing Binary tree searches against straight floating point multiplication
specifically for the purpose of placing coordinates into 'zones' (grid cells)
*/
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <string.h>
@Introscopia
Introscopia / approximate_heading.c
Created March 4, 2023 10:18
Calculate the approximate heading of a 2D vector at 3 different levels of precision using binary trees
View approximate_heading.c
typedef struct vec2d_struct{
double x, y;
} vec2d;
double v2d_rough_heading8(vec2d v){
if( v.x > 0 ){
if( v.y > 0 ){
if( v.x < v.y ) return 1.1780972450961724;// 3/8 PI
else return 0.3926990816987241;// 1/8 PI;
}
@Introscopia
Introscopia / mazes.c
Created December 27, 2022 02:54
maze generation
View mazes.c
#define UP 1
#define RIGHT 2
#define DOWN 4
#define LEFT 8
#define DEAD 16
#define MASKED 32
#define white 0xffffffff
#define black 0xff000000
#define transparent 0x00000000
View Drawing_Order_Planets.pde
float theta;
boolean over;
void setup() {
size(400, 400);
theta = HALF_PI;
over = true;
}
void draw() {
background(0);
View Binary_Clock.pde
/*
Simple Binary Clock in Processing.
Relogio Binario simples em Processing.
*/
float tx, ty, dx, dy;
void setup() {
size(400, 350);
tx = width / 9f;
ty = height / 3f;
@Introscopia
Introscopia / input_event_monitor.pde
Last active June 5, 2017 21:03
displays a kind of graph of input event timings.
View input_event_monitor.pde
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.
View Grav.pde
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; //
View Basic Gravity.txt
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,
View Tori.txt
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.