Skip to content

Instantly share code, notes, and snippets.

@Trimad
Last active January 3, 2018 20:18
Show Gist options
  • Save Trimad/632af600ba6bee3c2a4ba79ffefd34a5 to your computer and use it in GitHub Desktop.
Save Trimad/632af600ba6bee3c2a4ba79ffefd34a5 to your computer and use it in GitHub Desktop.
/* * * * * * *
Main File
Tristan Madden
1/2/2018
* * * * * * * */
//ffmpeg -r 60 -f image2 -s 3840x2160 -i frame-%04d.tif -c:v libx264 -preset slow -profile:v high -crf 9 -coder 1 -pix_fmt yuv420p -movflags +faststart -g 30 -bf 2 -c:a aac -b:a 384k -profile:a aac_low test4.mp4
import ch.bildspur.postfx.builder.*;
import ch.bildspur.postfx.pass.*;
import ch.bildspur.postfx.*;
OpenSimplexNoise noise;
PostFX fx;
ArrayList<Itinerant> itinerant = new ArrayList<Itinerant>();
PImage img;
void setup() {
frameRate(60);
fullScreen(P3D);
//size(3840,2160,P3D);
fx = new PostFX(this);
//strokeCap(SQUARE);
noise = new OpenSimplexNoise();
img = loadImage("lips.jpg");
convertPixelsToObjects();
background(0);
translate(0, 0, 320);
image(img, width/2-img.width/2, height/2-img.height/2);
}
void draw() {
translate(0, 0, 320);
//background(0);
//image(img, width/2-img.width/2, height/2-img.height/2);
for (int i = 0; i < itinerant.size(); i++) {
itinerant.get(i).update();
}
/*
fx.render()
.bloom(0.2, 16, 32)
//.rgbSplit(50)
//.sobel()
//.brightPass(0.2)
.blur(3, 6)
.compose();
*/
// draw fps
//surface.setTitle("RENDERING [FPS: " + String.format("%.2f", frameRate) + ", COUNT: "+frameCount+"]");
saveFrame("frame-####.tif");
if (frameCount >= 1800) { //1 minute at 60FPS
exit();
}
}
public void convertPixelsToObjects() {
/*
for (int i = itinerant.size() - 1; i >= 0; i--) {
itinerant.remove(i);
}
*/
img.loadPixels();
for (int x = 0; x < img.width/vScale; x +=vScale) {
for (int y = 0; y < img.height/vScale; y +=vScale) {
int xModifier = (width/2-img.width/2);
int yModifier = (height/2-img.height/2);
int [] info = new int[4]; //Contains all information needed for the object
info[0] = img.get(x*vScale, y*vScale); //color
info[1] = round(brightness(info[0]));
info[2] = xModifier+(x*vScale);//x-position
info[3] = yModifier+(y*vScale); //y-position
//itinerant.add(new Itinerant(info));
if (brightness(info[0])>5) {
itinerant.add(new Itinerant(info));
}
}
}
}
/* * * * * * *
Class File
Tristan Madden
1/2/2018
* * * * * * * */
int vScale = 1;
int phases = 1;
int displacement = 8;
int numFrames = 60;
class Itinerant {
int col;
int bri;
float x;
float permaX;
float nX;
float y;
float permaY;
float nY;
float angle;
float ns;
Itinerant(int [] arr) {
this.col = arr[0];
this.bri = arr[1];
this.x = arr[2];
this.permaX = arr[2];
this.y = arr[3];
this.permaY = arr[3];
this.angle = map(bri, 0, 255, 0, phases); //Brighter moves more
//this.angle = map(bri, 255, 0, 0, phases); //Darker moves more
}
void update() {
float t = (0.4*frameCount/numFrames)%1;
float scale = 0.0005; //noise "zoom"
float ns = (float)noise.eval(scale*x, scale*y, this.angle*cos(TWO_PI*t), this.angle*sin(TWO_PI*t));
float nm = map(ns, -1, 1, -displacement, displacement);
this.x = permaX + displacement*(float)Math.cos(nm);
this.y = permaY + displacement*(float)Math.sin(nm);
//this.x = permaX + nX;
//this.y = permaY + nY;
stroke(this.col);
strokeWeight(3);
point(this.x, this.y);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment