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
// which part of the screen is my mouse in? | |
int grid; | |
void setup () | |
{ | |
size( 500, 500 ); | |
grid = 3; | |
} | |
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
// dashed and dotted lines in Processing | |
// by Josh Nimoy, Based on Bresenham | |
void dashedLine ( float x0, float y0, float x1, float y1 ) | |
{ | |
dashedLine( (int)x0, (int)y0, (int)x1, (int)y1 ); | |
} | |
void dashedLine ( int x0, int y0, int x1, int y1 ) | |
{ |
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
// quickly find out if an int is even or uneven with: | |
// (i & 1) == 0 | |
// ... which "extracts" the last bit. | |
for ( int i = 0; i < 10; i++ ) | |
println( i + " " + (i & 1) + ( (i & 1) == 0 ? " even" : " uneven" ) ); |
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
// simple line algorithm to draw / read along a line. | |
// | |
// assumes x1 < x2 and y1 < y2 | |
int x1=10,x2=100; | |
int y1=20,y2=40; | |
// assumes xdiff > ydiff | |
float xdiff = x2-x1; | |
float ydiff = y2-y1; |
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
// simple-trace pixel-images | |
// | |
int w2,h2; | |
int[] values; | |
int[][] pairs; | |
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
// extracting single channels from Processings color type | |
// | |
color c = color( 123, 234, 95, 125 ); // this is: color ( red, green, blue, alpha ) | |
println( "Color in Hex:\t0x" + Integer.toHexString( c ).toUpperCase() ); | |
int alpha = ( c >> 24 ) & 0xFF; | |
int red = ( c >> 16 ) & 0xFF; | |
int green = ( c >> 8 ) & 0xFF; |
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
// benchmark to see if right-shift is faster than floor( / ). | |
// this is to quickly find which grid-element a location belongs to. | |
// test is in 1D only. | |
void draw () | |
{ | |
//setup | |
int grid = 3; | |
float gridP = pow(2,grid); // 16 >> 4 == 16 / 2^4 | |
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
// manually setting the window (frame) title in Processing | |
void setup() | |
{ | |
size( 200, 200 ); // needs to be first! | |
if ( this.frame != null ) | |
this.frame.setTitle( "my funky title" ); | |
} |
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
// benchmark different sqrt implementations | |
void setup () | |
{ | |
int runs = 100000; | |
long ts = System.currentTimeMillis(); | |
for ( int i=0; i < runs; 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
// gradient fill using PImage and texture() | |
Gradient gradient; | |
void setup () | |
{ | |
size(100, 100, P3D); // needs to be P3D / OPENGL since we use texture() | |
// create a Gradient size 100 x 100 px with two colors | |
gradient = new Gradient( 100, 100, 0xFF880000, 0xFFFFFFFF ); |
OlderNewer