Browse Source

initial commit

master
Victor Giers 2 years ago
commit
fa596c9f18
10 changed files with 1246 additions and 0 deletions
  1. BIN
      data/0.png
  2. BIN
      data/bin.png
  3. 2
    0
      data/saves.sav
  4. 439
    0
      effects.pde
  5. 18
    0
      keys_mouse.pde
  6. 108
    0
      mnglctrlr.pde
  7. 8
    0
      render.pde
  8. 521
    0
      secondapplet.pde
  9. 35
    0
      shader.pde
  10. 115
    0
      source.pde

BIN
data/0.png View File


BIN
data/bin.png View File


+ 2
- 0
data/saves.sav View File

@@ -0,0 +1,2 @@
//globals
uptime = 116625522

+ 439
- 0
effects.pde View File

@@ -0,0 +1,439 @@
final static int SINE = 0; //add 0.25 to phase to get cos
final static int SAWTOOTH = 1;
final static int SAWTOOTHINVERSE = 2;
final static int SQUARE = 3; //switches between -1 and 1, that's all
final static int TRIANGLE = 4;
final static int TAN = 5;
final static int TANINVERSE = 6;
final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPUPDOWN = 9; //line up, stay, line down, stay
final static int RANDOM = 10;

final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat



/*

ASDFPIXELSORT
*/

class ASDFPIXELSORT extends Shader {
ASDFPIXELSORT() {
name = "fxASDFPixelSort";
params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
params.add(new Param("mode", INTVAL, 0, 2, new int[]{RANDOM}));
}
int previousMode;

void apply() {
if (previousMode != int(params.get(1).value)) {
if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANGLE}));
}
previousMode = int(params.get(1).value);
row = 0;
column = 0;
renderer.beginDraw();
renderer.colorMode(RGB);
colorMode(RGB);
while (column < renderer.width-1) {
renderer.loadPixels();
sortColumn();
column++;
renderer.updatePixels();
}

while (row < renderer.height-1) {
renderer.loadPixels();
sortRow();
row++;
renderer.updatePixels();
}

renderer.endDraw();
}

int row = 0;
int column = 0;
void sortRow() {
int x = 0;
int y = row;
int xend = 0;
while (xend < renderer.width-1) {
switch((int)params.get(1).value) {
case 0:
x = getFirstNotBlackX(x, y);
xend = getNextBlackX(x, y);
break;
case 1:
x = getFirstBrightX(x, y);
xend = getNextDarkX(x, y);
break;
case 2:
x = getFirstNotWhiteX(x, y);
xend = getNextWhiteX(x, y);
break;
default:
break;
}

if (x < 0) break;

int sortLength = xend-x;

color[] unsorted = new color[sortLength];
color[] sorted = new color[sortLength];

for (int i=0; i<sortLength; i++) {
unsorted[i] = renderer.pixels[x + i + y * renderer.width];
}

sorted = sort(unsorted);

for (int i=0; i<sortLength; i++) {
renderer.pixels[x + i + y * renderer.width] = sorted[i];
}

x = xend+1;
}
}


void sortColumn() {
int x = column;
int y = 0;
int yend = 0;

while (yend < renderer.height-1) {
switch((int)params.get(1).value) {
case 0:
y = getFirstNotBlackY(x, y);
yend = getNextBlackY(x, y);
break;
case 1:
y = getFirstBrightY(x, y);
yend = getNextDarkY(x, y);
break;
case 2:
y = getFirstNotWhiteY(x, y);
yend = getNextWhiteY(x, y);
break;
default:
break;
}

if (y < 0) break;

int sortLength = yend-y;
color[] unsorted = new color[sortLength];
color[] sorted = new color[sortLength];
for (int i=0; i<sortLength; i++) {
unsorted[i] = renderer.pixels[x + (y+i) * renderer.width];
}

sorted = sort(unsorted);


for (int i=0; i<sortLength; i++) {
renderer.pixels[x + (y+i) * renderer.width] = sorted[i];
}

y = yend+1;
}
}


//BLACK
int getFirstNotBlackX(int _x, int _y) {
int x = _x;
int y = _y;
color c;
while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
x++;
if (x >= renderer.width) return -1;
}
return x;
}

int getNextBlackX(int _x, int _y) {
int x = _x+1;
int y = _y;
color c;
while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
x++;
if (x >= renderer.width) return renderer.width-1;
}
return x-1;
}

//BRIGHTNESS
int getFirstBrightX(int _x, int _y) {
int x = _x;
int y = _y;
color c;
while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
x++;
if (x >= renderer.width) return -1;
}
return x;
}

int getNextDarkX(int _x, int _y) {
int x = _x+1;
int y = _y;
color c;
while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
x++;
if (x >= renderer.width) return renderer.width-1;
}
return x-1;
}

//WHITE
int getFirstNotWhiteX(int _x, int _y) {
int x = _x;
int y = _y;
color c;
while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
x++;
if (x >= renderer.width) return -1;
}
return x;
}

int getNextWhiteX(int _x, int _y) {
int x = _x+1;
int y = _y;
color c;
while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
x++;
if (x >= renderer.width) return renderer.width-1;
}
return x-1;
}


//BLACK
int getFirstNotBlackY(int _x, int _y) {
int x = _x;
int y = _y;
color c;
if (y < renderer.height) {
while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
y++;
if (y >= renderer.height) return -1;
}
}
return y;
}

int getNextBlackY(int _x, int _y) {
int x = _x;
int y = _y+1;
color c;
if (y < renderer.height) {
while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
y++;
if (y >= renderer.height) return renderer.height-1;
}
}
return y-1;
}

//BRIGHTNESS
int getFirstBrightY(int _x, int _y) {
int x = _x;
int y = _y;
color c;
if (y < renderer.height) {
while (brightness (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
y++;
if (y >= renderer.height) return -1;
}
}
return y;
}

int getNextDarkY(int _x, int _y) {
int x = _x;
int y = _y+1;
color c;
if (y < renderer.height) {
while (brightness (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
y++;
if (y >= renderer.height) return renderer.height-1;
}
}
return y-1;
}

//WHITE
int getFirstNotWhiteY(int _x, int _y) {
int x = _x;
int y = _y;
color c;
if (y < renderer.height) {
while ( (c = renderer.pixels[x + y * renderer.width]) > params.get(0).value) {
y++;
if (y >= renderer.height) return -1;
}
}
return y;
}

int getNextWhiteY(int _x, int _y) {
int x = _x;
int y = _y+1;
color c;
if (y < renderer.height) {
while ( (c = renderer.pixels[x + y * renderer.width]) < params.get(0).value) {
y++;
if (y >= renderer.height) return renderer.height-1;
}
}
return y-1;
}
}


/*

DISTORTER
*/


class DISTORTER extends Shader {

PImage buffer;

int[][] distort = new int[2][512];
final static float tick = 1.0/512.0;
final int[] blends = {
ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
};
// ALL Channels, Nxxx stand for negative (255-value)
// channels to work with
final static int RED = 0;
final static int GREEN = 1;
final static int BLUE = 2;
final static int HUE = 3;
final static int SATURATION = 4;
final static int BRIGHTNESS = 5;
final static int NRED = 6;
final static int NGREEN = 7;
final static int NBLUE = 8;
final static int NHUE = 9;
final static int NSATURATION = 10;
final static int NBRIGHTNESS = 11;

DISTORTER() {
name = "fxDistorter";
/*
//params.add(new Param ("shifthue", 1)); //boolean shift_hue
params.add(new Param("hueshift", 0, 1)); //float shift_amt
params.add(new Param("scalex", 0.01, 1)); //float scalex
params.add(new Param("scaley", 0.01, 1)); //float scaley
//params.add(new Param ("blend", 1)); //boolean do_blend
params.add(new Param ("blendmode", blends.length)); //int blend_mode
params.add(new Param("channel", 12));*/

buffer = createImage(renderer.width, renderer.height, ARGB);

// prepare distortion pattern
for (int i=0; i<512; i++) {
distort[0][i] = (int)random(-128, 128);
distort[1][i] = (int)random(-128, 128);
}
}

void apply() {
buffer = renderer.get();
buffer.resize(renderer.width, renderer.height);

float neww = map(params.get(1).value, 0, 1, 1, buffer.width/4);
float newh = map(params.get(2).value, 0, 1, 1, buffer.height/4);

float totalnum = neww+newh;
float times = (totalnum/floor(totalnum/neww));
float offx = (totalnum%neww)/times;
float ratiox = neww/buffer.width;

renderer.beginDraw();
renderer.noStroke();

for (int y=0; y<buffer.height; y++) {
float yy = y/(float)buffer.height;
for (int x=0; x<buffer.width; x++) {
float xx = x/(float)buffer.width;

float offy = floor(newh*yy);
float fx = xx*ratiox+offx*offy;

float shift = fx%1.0;
float st = shift/tick;
int no1 = floor(st)%512;
int no2 = ceil(st)%512;
float l = st-(float)no1;

float cx = lerp(distort[0][no1], distort[0][no2], l);
float cy = lerp(distort[1][no1], distort[1][no2], l);

float rx =getChannel(buffer.get(x, y), (int)params.get(4).value);
int sx = (int)((buffer.width+x+cx*rx*params.get(1).value*0.1)%buffer.width);
int sy = (int)((buffer.height+y+cy*params.get(0).value)%buffer.height);

color c=buffer.get(sx, sy);

//if (boolean((int)(params.get(0).value))) {
colorMode(HSB, 255);
c = color((hue(c)+params.get(0).value*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
colorMode(RGB, 255);
//}
//renderer.fill(lerpColor(c,buffer.get(x,y),0.2));
renderer.fill(c);
renderer.rect(x, y, 1, 1);
}
}

//if (boolean((int)(params.get(4).value)))
renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, (int)params.get(3).value);

colorMode(RGB);
renderer.endDraw();
}



float getChannel(color c, int channel) {
int ch = channel>5?channel-6:channel;
float cc;

switch(ch) {
case RED:
cc = red(c);
break;
case GREEN:
cc = green(c);
break;
case BLUE:
cc = blue(c);
break;
case HUE:
cc = hue(c);
break;
case SATURATION:
cc = saturation(c);
break;
default:
cc= brightness(c);
break;
}

return channel>5?255-cc:cc;
}
}

+ 18
- 0
keys_mouse.pde View File

@@ -0,0 +1,18 @@
void mousePressed()
{
if (mouseButton == LEFT) {
if (sourceManager.dir != null) {
sourceManager.importURI(sourceManager.dir + "/" + sourceManager.selection[(int)random(sourceManager.selection.length)]);
}
}
if (mouseButton == RIGHT) {
snapshot();
}
}
void mouseWheel(MouseEvent event) {

if (event.getCount() < 0) renderSize += 8;
else renderSize -= 8;
renderSize = constrain(renderSize, 8, 15000);
println("Render size: " + renderSize);
}

+ 108
- 0
mnglctrlr.pde View File

@@ -0,0 +1,108 @@
import drop.*;
import test.*;
import controlP5.*;

import java.util.*;
import processing.net.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import processing.video.*;
import com.hamoid.*;

VideoExport videoExport;

int maxFx = 15; //possible amount of effect layers
SDrop drop;
PImage source;
PGraphics renderer;
PImage viewport;
SourceManager sourceManager;
String frameName; //to save frame as image
int uptime; //logs how many frames this software has rendered before (inaccurate, it's actually way, way more)
boolean recording; //save every frame?
int renderSize = 500; //px
String[] saveData;
int w, h;

boolean videoRecord;

String[] params;

PImage droppedImage;
void dropEvent(DropEvent theDropEvent) {

sourceManager.importURI(theDropEvent.filePath());
}

void settings() {
size(800, 600);
}

SecondApplet gui;

void setup() {
w = width;
h = height;
frameRate(60);
surface.setResizable(true);
surface.setLocation(570, 240);
noSmooth(); //saves resources but makes sum look shiddy
drop = new SDrop(this);
saveData = loadStrings(dataPath("saves.sav"));
println("Loading Savefile...");
for (int i = 0; i < saveData.length; i ++) {
String[] temp;
if (saveData[i].contains("uptime")) {
temp = split(saveData[i], " = ");
uptime = int(temp[1]);
println("Uptime: " + uptime);
}
}
fallbackImage = loadImage(dataPath("0.png"));
bin = loadImage(dataPath("bin.png"));


String[] args = {"SecondFrame"};
gui = new SecondApplet();
PApplet.runSketch(args, gui);
renderer = createGraphics(width, height);
viewport = createImage(renderer.width, renderer.height, ARGB);
sourceManager = new SourceManager();
//sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014");
}

void draw() {
uptime+=1;
background(255);

sourceManager.update(); //will write some image to the renderer
sourceManager.setSource();
gui.shaderManager.applyShader(); //boolean animate (iterative calcs), boolean apply (draw)
background(color(0));
imageMode(CENTER);
viewport = renderer.get();
if (renderer.width < renderer.height) {
viewport.resize(0, height);
if (viewport.width > width) viewport.resize(width, 0);
} else {
viewport.resize(width, 0);
if (viewport.height > height) viewport.resize(0, height);
}


//sourceManager.setSource();
image(viewport, width/2, height/2);

if (videoRecord) {
videoExport.saveFrame();
fill(#ff0000);
ellipse(width-100, height-100, 30, 30);
}


if (recording) {
snapshot();
}
}

+ 8
- 0
render.pde View File

@@ -0,0 +1,8 @@

void snapshot() {
frameName = str(uptime);
renderer.save(dataPath("")+"/snapshots/" + frameName + ".png");
saveData[1] = "uptime = " + frameName;
println("Rendered " + frameName + ".png at " + dataPath("")+"/snapshots/ with a resolution of " + renderer.width + " x " + renderer.height);
saveStrings(dataPath("saves.sav"), saveData);
}

+ 521
- 0
secondapplet.pde View File

@@ -0,0 +1,521 @@
PImage bin;
final static int INTVAL = 100;
final static int FLOATVAL = 101;

public class SecondApplet extends PApplet {
ControlP5 cp5;

final static int SINE = 0; //add 0.25 to phase to get cos
final static int SAWTOOTH = 1;
final static int SAWTOOTHINVERSE = 2;
final static int SQUARE = 3; //switches between -1 and 1, that's all
final static int TRIANGLE = 4;
final static int TAN = 5;
final static int TANINVERSE = 6;
final static int RAMP = 7; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPINVERSE = 8; //line for half the sequence up to 1, then stay at 1 for the other half
final static int RAMPUPDOWN = 9; //line up, stay, line down, stay
final static int RANDOM = 10;
final static int RANDOMIZE_ALL = 777; //not for wave-generation. meant for low frequency oscillator that calls a function after every beat
String availableFx[] = {
"fxASDFPixelSort",
"fxDistorter",
"fxWahWah",
"fxAuEcho",
"fxPhaser",
"fxWZIP",
"fxDarker",
"fxBrighter",
"fxMove",
"fxScale",
"fxEpilepsy",
"fxPosterize",
"fxCopyZoom",
"fxDual",
"fxScanker",
"fxPixelSort",
"fxHSB",
"fxEcho",
"fxSubtleSort",
"fxBlackWhite",
"fxDrawGenerative",
"fxDrawStrokes",
"fxFM",
"fxGrauzone",
"fxSlitScan"
};
shaderManager shaderManager = new shaderManager();
class shaderManager {
void addShader(Shader shader) {
shaderList.add(shader);
shader.pos = shaderList.size()-1;
bricks.add(new Brick(shaderList.size()-1, shaderList.get(shaderList.size()-1).params));
println("Added " + shader + " to fxList at spot. List length: " + shaderList.size());
}
void swapShader(int pos1, int pos2) {
if (pos1 >= 0 && pos2 < shaderList.size()) {
Collections.swap(shaderList, pos1, pos2);
Collections.swap(bricks, pos1, pos2);
shaderList.get(pos1).pos = pos1;
shaderList.get(pos2).pos = pos2;
bricks.get(pos1).setPosition(pos1);
bricks.get(pos2).setPosition(pos2);
}
}
void removeShader(int pos) {
if (pos >= 0 && shaderList.size() > pos) {
shaderList.remove(pos);
bricks.remove(pos);
for (int i = shaderList.size()-1; i > -1; i--) {
bricks.get(i).setPosition(i);
shaderList.get(i).pos = i;
}
}
}
void applyShader() {
for (int i = 0; i < shaderList.size(); i++) {
shaderList.get(i).getValuesFromGUI();
shaderList.get(i).apply();
if (i > maxFx) break;
}
}
}

ArrayList<Shader> shaderList = new ArrayList<Shader>();
ArrayList<Brick> bricks = new ArrayList<Brick>();

class Brick {
ArrayList<Slider> slider = new ArrayList<Slider>();
ArrayList<Param> params = new ArrayList<Param>();
int position;

Brick(int position_, ArrayList params_) {
position = position_;
params = params_;
for (int i = 0; i < params.size(); i++) {
slider.add(new Slider(10, 10+20*i+position*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider
}
}

void exchangeSlider(int sliderNo, Param param) {
slider.get(sliderNo).setMinMax(param.minValue, param.maxValue);
slider.get(sliderNo).setMode(param.type);
slider.get(sliderNo).setLabel(param.name);
}


void update() {
for (int i = 0; i < slider.size(); i++) {
slider.get(i).update();
params.get(i).value = slider.get(i).value;
}
}

void display() {
for (int i = 0; i < slider.size(); i++) {
slider.get(i).display();
}
}
}


ArrayList<Slider> slider;
int pressedSlider = -1;

class Slider {
int x, y, w, h, mode;
float minVal, maxVal, value; //should be private but doesnt work lol
boolean hovering, hovering_anim_btn, animated, randomized;
String label;
Oscillator osci;

Slider(int x_, int y_, int w_, int h_, float minVal_, float maxVal_, String label_, int mode_) {
x = x_;
y = y_;
w = w_;
h = h_;
minVal = minVal_;
maxVal = maxVal_;
mode = mode_;
label = label_ + (mode == INTVAL ? " (INT)" : " (FLOAT)");

osci = new Oscillator(int(random(2, 20)));
osci.amplitude(minVal, maxVal);

animated = true;
randomized = true;

slider.add(this);
}

void setPosX(int x_) {
x = x_;
}

void setMinMax(float min, float max) {
float cval = map(value, minVal, maxVal, 0, 10000);
minVal = min;
maxVal = max;
osci.amplitude(minVal, maxVal);
setValue(map(cval, 0, 10000, minVal, maxVal));
}
void setLabel(String lab) {
label = lab + (mode == INTVAL ? " (INT)" : " (FLOAT)");
}
void setMode(int mode_) {
mode = mode_;
}

void press(int myId_) {
pressedSlider = myId_;
animated = false;
setValue(map(mouseX, x, x+w, minVal, maxVal));
}

void setValue(float value_) {
value = value_;
value = constrain(value, minVal, maxVal);
if (mode == INTVAL) value = int(round(value));
}

float getValue() {
return(value);
}

void update() {
osci.update();

if (animated) {
setValue(osci.value);
}


if (mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h) {
hovering = true;
} else {
hovering = false;
}

if (mouseX >= x+w+5 && mouseX <= x+w+5+15 && mouseY >= y && mouseY <= y+h) {
hovering_anim_btn = true;
} else {
hovering_anim_btn = false;
}
}

void display() {
fill(100+(40*int(hovering)));
rect(x, y, w, h);
fill(185+(40*int(hovering)));
rect(x, y, map(value, minVal, maxVal, 0, w), h);
fill(255);
text(label, x+5, y+10, 10);

if (animated) {
fill(185+(40*int(hovering_anim_btn)));
} else {
fill(100+(40*int(hovering_anim_btn)));
}
rect(x+w+5, y, 15, 15);
}
}


public void settings() {
size(275, 500);
}

public void setup() {
slider = new ArrayList<Slider>(); //brick

cp5 = new ControlP5(this);
List l = Arrays.asList(availableFx);


cp5.addScrollableList("")
.setPosition(10, height-110)
.setSize(80, 100)
.setBarHeight(0)
.setItemHeight(20)
.plugTo(this, "liste")
.addItems(l)
.setType(ControlP5.LIST);


surface.setLocation(285, 240);
//surface.setSize(1000,100);

//testslider = new Slider(10, 10, 230, 15, 0, 5, "testslider", INTVAL);

randomizer = new Oscillator(5); //every 12 seconds;
randomizer.mode = RANDOMIZE_ALL;
}



public void draw() {
background(68, 68, 68);
image(bin, width-55, height-85, 40, 40);
stroke(255);
strokeWeight(1);
line(0, height-120, width, height-120);

randomizer.update();

//this goes to bricks



for (int i = 0; i < shaderList.size(); i++) {
bricks.get(i).update();
bricks.get(i).display();

//for (int j = 0; j < fxList.get(i).shader.params.size(); j++) {
//Slider s = fxList.get(i).shader.params.get(i);
//}
}
}

//CP5
void liste(int n) {
if (shaderList.size() < maxFx) {
switch(n) {
case(0):
shaderManager.addShader(new ASDFPIXELSORT());
break;
case(1):
shaderManager.addShader(new DISTORTER());
break;
/*
case(2):
shaderManager.addShader(new WAHWAH());
break;
case(3):
shaderManager.addShader(new AUECHO());
break;
case(4):
shaderManager.addShader(new PHASER());
break;
case(0):
shaderManager.addShader(new WZIP());
break;
case(0):
shaderManager.addShader(new DARKER());
break;
case(0):
shaderManager.addShader(new BRIGHTER());
break;
case(0):
shaderManager.addShader(new MOVE());
break;
case(0):
shaderManager.addShader(new SCALE());
break;
case(0):
shaderManager.addShader(new EPILEPSY());
break;
case(0):
shaderManager.addShader(new POSTERIZE());
break;
case(0):
shaderManager.addShader(new COPYZOOM());
break;
case(0):
shaderManager.addShader(new DUAL());
break;
case(0):
shaderManager.addShader(new SCANKER());
break;
case(0):
shaderManager.addShader(new PIXELSORT());
break;
case(0):
shaderManager.addShader(new HSB());
break;
case(0):
shaderManager.addShader(new ECHO());
break;
case(0):
shaderManager.addShader(new SUBTLESORT());
break;
case(0):
shaderManager.addShader(new BLACKWHITE());
break;
case(0):
shaderManager.addShader(new DRAWGENERATIVE());
break;
case(0):
shaderManager.addShader(new DRAWSTROKES());
break;
case(0):
shaderManager.addShader(new FM());
break;
case(0):
shaderManager.addShader(new GRAUZONE());
break;
case(0):
shaderManager.addShader(new SLITSCAN());
break;
*/
default:
break;
}
}
}




class Oscillator {
float speed; //in milliseconds
int spawnMillis;
int pauseMillis;
int beatCount = 0;
int mode;

//int function; //function to be called by bang-oscillators
float position; // between 0 and TWO_PI
float value; // is returned, constrained between "low" and "high"
float low = -1.0;
float high = 1.0;
boolean playing, pause, valInvert;

Oscillator(float bpm_) {
bpm(bpm_);
play();
}

void amplitude(float low_, float high_) {
low = low_;
high = high_;
}
void frequency(float hertz_) {
speed = 1000/hertz_;
}
void bpm(float bpm_) {
speed = int(60 / bpm_ * 1000);
}

void play() {
if (pause) {
float pauseTime = millis() - pauseMillis;
spawnMillis += pauseTime;
pause = false;
} else if (!playing) {
spawnMillis = millis();
}
playing = true;
}
void pause() {
if (playing) {
pauseMillis = millis();
pause = true;
playing = false;
}
}
void stop() {
beatCount = 0;
playing = false;
value = 0;
}


void update() {
if (playing) {
while (millis() - spawnMillis > speed*beatCount) {
beatCount++;
if (mode == RANDOMIZE_ALL) randomize_all();
}

float millisToBeat = millis() - spawnMillis - (speed*beatCount);
position = map(-millisToBeat, speed, 0, 0, TWO_PI);

switch(mode) {
case(SINE):
value = sin(position);
break;
case(SAWTOOTH):
value = ((position % TWO_PI)-PI)/PI;
break;
case(SAWTOOTHINVERSE):
value = (((position % TWO_PI)-PI)/PI)*-1;
break;
case(SQUARE):
value = sin(position > PI ? 1 : -1);
break;
case(TRIANGLE):
value = position-PI < 0 ? ((position % TWO_PI)-PI)/PI : (((position % TWO_PI)-PI)/PI)*-1;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
break;
case(TAN):
value = tan(position);
break;
case(TANINVERSE):
value = tan(position)*-1;
break;
case(RAMP):
value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
break;
case(RAMPINVERSE):
value = sin(position) > 0 ? ((position % TWO_PI)-PI)/PI : 0;
value+=0.5;
value*=2;
if (value == 3.0) value = -1;
value = value*-1;
break;
case(RAMPUPDOWN):
if (sin(position) <= -1.6666666666) value = -1.6666666666;
else if (sin(position) < 1.6666666666 && sin(position) > -1.6666666666) value = sin(position);
else if (sin(position) >= 1.6666666666) value = 1.6666666666;
value *= 1.5;
break;
default:
break;
}
value = constrain(value, -1.0, 1.0);

value = map(value, -1.0, 1.0, low, high);
//value = valInvert? map(value, 1.0, -1.0, low, high) : map(value, -1.0, 1.0, low, high);
}

//fill(0);
//ellipse(inc, height/2+value*height/4, 1, 1);
}
}


void randomize_all() {
for (int i = slider.size()-1; i >= 0; i--) {
Slider s = slider.get(i);
if (random(1) > .5) s.osci.mode = int(round(random(9)));
if (random(1) > .5) s.osci.play();
else pause();
if (random(1) > .5) s.osci.bpm(random(2, 10));
}
}


void mousePressed() {
for (int i = slider.size()-1; i >= 0; i--) {
Slider s = slider.get(i);
if (s.hovering) s.press(i);
if (s.hovering_anim_btn) s.animated = !s.animated;
}
}
void mouseDragged() {
if (pressedSlider != -1) {
Slider s = slider.get(pressedSlider);
s.setValue(map(mouseX, s.x, s.x+s.w, s.minVal, s.maxVal));
}
}

void mouseReleased() {
pressedSlider = -1;
}
}

+ 35
- 0
shader.pde View File

@@ -0,0 +1,35 @@
class Param {
String name;
int type;
float minValue, maxValue;
float value;
int[] osciModes;
Param(String name_, int type_, float minValue_, float maxValue_, int[] osciModes_) {
name = name_;
type = type_; //FLOATVAL or INTVAL
minValue = minValue_;
maxValue = maxValue_;
osciModes = osciModes_;
}
}

class Shader {
int id;
int pos;
String name;
ArrayList<Param> params = new ArrayList<Param>();
void getValuesFromGUI(){
params = gui.bricks.get(pos).params;
println("Rendering " + this + " on position " + pos + "...");
}
void changeParam(int paramNo, Param newParam){
gui.bricks.get(pos).params.remove(paramNo);
gui.bricks.get(pos).params.add(paramNo, newParam);
gui.bricks.get(pos).exchangeSlider(paramNo, newParam);
}
void apply() {
}; //override me
}

+ 115
- 0
source.pde View File

@@ -0,0 +1,115 @@

Capture cam;
Movie movie;
boolean moviePlaying;
PImage fallbackImage;

void movieEvent(Movie m) {
if (moviePlaying) {
m.read();
//if mode = 1..
sourceManager.setImage(movie.get());
movie.jump(random(movie.duration())); //??
}
}
void newMovie(String path) {
movie = new Movie(this, path);
}

boolean isVideo(String path) {
String fpl = path.toLowerCase();
if (fpl.endsWith(".mp4") || fpl.endsWith(".avi") || fpl.endsWith(".webm") || fpl.endsWith(".mkv") || fpl.endsWith(".mov")) return true;
else return false;
}
boolean isImage(String path) {
String fpl = path.toLowerCase();
if (fpl.endsWith(".bmp") || fpl.endsWith(".png") || fpl.endsWith(".jpg") || fpl.endsWith(".jpeg") || fpl.endsWith(".gif")) return true; //gif = special case!
else return false;
}

class SourceManager { //no constructor


void setSource() { //set source to renderer
renderer.beginDraw();
renderer.image(source, 0, 0, renderer.width, renderer.height);
renderer.endDraw();
}
void setImage(PImage img) { //set image to source
source = img.get();
fallbackImage = source;
}

void fallback() {
println("Fallback");
setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
}

void update() {
if (source == null) {
fallback();
}

int toW, toH;
if (source.width > source.height) {
toW = renderSize;
toH = int(map(source.height, 0, source.width, 0, renderSize));
} else {
toW = int(map(source.width, 0, source.height, 0, renderSize));
toH = renderSize;
}
toW = (toW % 2 == 0) ? toW : toW+1;
toH = (toH % 2 == 0) ? toH : toH+1;

renderer.setSize(toW, toH);
}


// This function returns all the files in a directory as an array of Strings
String[] listFileNames(String dir) {
File file = new File(dir);
if (file.isDirectory()) {
String names[] = file.list();
return names;
} else {
return null;
}
}


String dir;
String[] selection;
int selId;
void importURI(String path) {
File file = new File(path);
if (file.isDirectory()) {
dir = path;
String names[] = file.list();
ArrayList<String> usableFiles = new ArrayList<String>();
for (int i = 0; i < names.length; i++) {
if (isImage(names[i]) || isVideo(names[i])) {
usableFiles.add(names[i]);
}
}
selection = new String[usableFiles.size()];
for (int i = 0; i < usableFiles.size(); i++) selection[i] = usableFiles.get(i);
println("Got new selection from folder. " + selection.length + " usable files.");
path = dir + "/" + selection[(int)random(selection.length)];
}


if (isImage(path) || isVideo(path)) {
println("Importing file " + path);
if (moviePlaying) movie.stop();
if (isImage(path)) {
moviePlaying = false;
setImage(loadImage(path));
} else if (isVideo(path)) {
moviePlaying = true;
newMovie(path);
movie.loop();
}
}
}
}

Loading…
Cancel
Save