Last active
March 8, 2019 19:01
-
-
Save Lana-chan/bc0e78d7dccdce14137886f1cb1f8b52 to your computer and use it in GitHub Desktop.
Random Processing sketches
This file contains hidden or 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
// Animated falling paw shapes | |
// originally posted as gist May 10, 2016 | |
int pawcount = 50; | |
Paw[] paws = new Paw[pawcount]; | |
float ang1, ang2; | |
void setup() { | |
size(800,600); | |
randomSeed(1994); | |
colorMode(HSB, 255); | |
noStroke(); | |
for(int i = 0; i < pawcount; i++) { | |
paws[i] = new Paw(); | |
} | |
} | |
void draw() { | |
background(color(200,80,255)); | |
for(int i = 0; i < pawcount; i++) { | |
paws[i].display(); | |
} | |
} | |
class Paw { | |
color col; | |
float x; | |
float y; | |
float ang; | |
float size; | |
float fallSpeed; | |
float spinSpeed; | |
float boundary; | |
Paw() { | |
fallSpeed = random(0.2, 1); | |
size = random(1,3); | |
spinSpeed = (int(random(0,2))*2-1)*(1/size/15); | |
col = color(random(0,255),190,random(180,255)); | |
boundary = 30*size; | |
y = random(0 - boundary - 100, 0 - boundary); | |
x = random(boundary, width - boundary); | |
} | |
void display() { | |
pushMatrix(); | |
fill(col); | |
translate(x, y); | |
rotate(ang); | |
scale(size); | |
pushMatrix(); | |
ellipse(0,0,23,23); | |
ellipse(0,-17,8,8); | |
rotate(radians(-38)); | |
ellipse(0,-17,8,8); | |
rotate(radians(76)); | |
ellipse(0,-17,8,8); | |
popMatrix(); | |
popMatrix(); | |
y += fallSpeed; | |
if(y > height + boundary) y = 0 - boundary; | |
ang += spinSpeed; | |
} | |
} |
This file contains hidden or 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 Demoscene Plasma for Processing | |
// originally posted as gist in Jul 17, 2017 | |
//based off http://www.bidouille.org/prog/plasma | |
int t; | |
int[] fast_sine = new int[360]; | |
void setup() { | |
size(800,600); | |
background(color(20,20,20)); | |
// precalculated sine for speed | |
for(int i = 0; i < 360; i++) fast_sine[i] = (int)((sin(radians(i))+1)*127.0); | |
} | |
// function for automatic 360 degree wrap | |
int fsine(float deg) { | |
return fast_sine[(int)deg%360]; | |
} | |
void draw() { | |
loadPixels(); | |
for(int y = 0; y < height; y+=2) { // only draw every other line for speed improvement | |
int line = y*width; | |
for(int x = 0; x < width; x+=5) { // only draw every 5 columns for speed improvement | |
// plasma magic (see website for more info) | |
int v1 = fsine(x*1.5+t); | |
int v2 = fsine(0.005*(x*fsine(t/1.5)+y*fsine(t/2+180))+t); | |
float cx = x+fsine(t*2)-width/1.5; | |
float cy = y+fsine(t+180)-height/1.5; | |
int v3 = fsine(sqrt((cx*cx+cy*cy)+1)*0.6+t*3)*2; | |
int v = v1+v2+v3; | |
// rgb color gradient | |
color c = color(fsine(v),fsine(v+90),fsine(v+180)); | |
// blit 5 pixels | |
pixels[line + x] = c; | |
pixels[line + x+1] = c; | |
pixels[line + x+2] = c; | |
pixels[line + x+3] = c; | |
pixels[line + x+4] = c; | |
} | |
} | |
updatePixels(); | |
t+=1; | |
} |
This file contains hidden or 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
// Magnetic field-like display, interactive with mouse position | |
// originally posted as gist in Mar 5, 2016 | |
int countx = 20; | |
int county = 20; | |
void setup() { | |
size(800,600); | |
} | |
void draw() { | |
background(255); | |
for(int x = countx; x < width; x+=width/countx) { | |
for(int y = county; y < height; y+=height/county) { | |
float targetAng = atan2(mouseY-y,mouseX-x); | |
pushMatrix(); | |
translate(x,y); | |
stroke(sqrt(pow(mouseX-x,2)+pow(mouseY-y,2))); | |
rotate(targetAng); | |
line(0,0,countx,0); | |
popMatrix(); | |
} | |
} | |
} |
This file contains hidden or 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
// tartan generator | |
// maple (c) 2019-03-08 | |
int PATTERN_SIZE = 6; | |
int MULTIPLIER = 3; | |
float Y_MUL = 0.02; | |
float X_MUL = 0.03; | |
Tartan[] tar = new Tartan[2]; | |
color bg; | |
int t; | |
int sum(int[] array) { | |
int s = 0; | |
for(int n : array) { | |
s += n; | |
} | |
return s; | |
} | |
class Tartan { | |
int[] widths; | |
color stripes; | |
PGraphics pattern; | |
PGraphics render; | |
int id; | |
Tartan(int id, int size) { | |
this.id = id; | |
widths = new int[PATTERN_SIZE]; | |
int remaining = size; | |
for(int i = 0; i < PATTERN_SIZE; i++) { | |
widths[i] = min(int(random(1,9))*MULTIPLIER, remaining); | |
remaining -= widths[i]; | |
} | |
if(remaining > 0) | |
widths[PATTERN_SIZE-1] += remaining; | |
stripes = color(int(random(255)), int(random(255)), int(random(255))); | |
pattern = createGraphics(sum(widths)*2, sum(widths)*2); | |
pattern.beginDraw(); | |
pattern.noStroke(); | |
pattern.fill(stripes, 150); | |
//render.translate(render.width/2, render.height/2); | |
int offset = 0; | |
for(int i = 0; i < PATTERN_SIZE; i+=2) { | |
pattern.rect(0,offset,pattern.width,widths[i]); | |
pattern.rect(0,pattern.height-offset,pattern.width,-widths[i]); | |
pattern.rect(offset,0,widths[i],pattern.height); | |
pattern.rect(pattern.width-offset,0,-widths[i],pattern.height); | |
offset += widths[i] + widths[i+1]; | |
} | |
pattern.endDraw(); | |
render = createGraphics(width*2, height*2, P2D); | |
render.beginDraw(); | |
for(int y = (id%2)*(-pattern.height/2); y <= render.height; y += pattern.height) { | |
for(int x = (id%2)*(-pattern.width/2); x <= render.width; x += pattern.width) { | |
render.image(pattern, x, y); | |
} | |
} | |
render.endDraw(); | |
} | |
void draw() { | |
imageMode(CENTER); | |
image(render, (width/2), (height/2)); | |
} | |
} | |
void init() { | |
t = 0; | |
int size = int(random(1,9))*MULTIPLIER*PATTERN_SIZE; | |
for(int i = 0; i < tar.length; i++) | |
tar[i] = new Tartan(i, size); | |
bg = color(int(random(255)), int(random(255)), int(random(255))); | |
} | |
void setup() { | |
size(480,272,P2D); | |
//fullScreen(P2D); | |
init(); | |
} | |
void draw() { | |
background(bg); | |
float cam_x = (sin(t*X_MUL)*height/2); | |
float cam_y = (sin(t*Y_MUL)*height/2); | |
translate(cam_x, cam_y); | |
for(int i = 0; i < tar.length; i++) | |
tar[i].draw(); | |
t += 1; | |
if(t >= TWO_PI*100) init(); | |
} | |
void mouseClicked() { | |
init(); | |
} |
This file contains hidden or 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
// Recursive waving tree | |
// originally posted as gist in Mar 2, 2016 | |
// sorry about the magic numbers | |
int t; | |
float[] fast_sine = new float[360]; | |
int steps = 11; //fractal steps | |
float ang = 35; //angle between branches | |
float oang; //offset angle (swing animation) | |
int noisecount; //counter for branch randomness | |
void setup() { | |
size(800,600); | |
background(color(255)); | |
noiseSeed((long)random(65535)); | |
for(int i = 0; i < 360; i++) fast_sine[i] = sin(radians(i)); | |
} | |
void draw() { | |
oang = (fsine(t)*2); // wave with time | |
background(color(255)); // clear screen | |
branch(w*0.5,h*0.9,h*0.2,0,steps); // fun | |
t+=1; | |
noisecount = 0; | |
} | |
float fsine(float deg) { | |
//return fast_sine[(int)(deg+3600)%360]; // whoops i didn't use this at all | |
return sin(radians(deg)); | |
} | |
// home point x, y, line height, line angle, step | |
void branch(float bx,float by,float bh,float bang,int bstep) { | |
if(bstep > 0) { | |
float nx = bx+bh*fsine(bang); // calculates second point of the line | |
float ny = by-bh*fsine(bang+90); | |
stroke(240-240*bstep/steps); // fades out to branches | |
line(bx,by,nx,ny); | |
branch(nx,ny,bh*0.8,bang-ang+oang+(noise(noisecount++)-0.5)*50,bstep-1); // recursion | |
branch(nx,ny,bh*0.8,bang+ang+oang+(noise(noisecount++)-0.5)*50,bstep-1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment