fixed random oscillator mode
This commit is contained in:
@@ -1,2 +1,2 @@
|
||||
//globals
|
||||
uptime = 116626470
|
||||
uptime = 116628228
|
||||
|
||||
108
effects.pde
108
effects.pde
@@ -8,7 +8,7 @@ class ASDFPIXELSORT extends Shader {
|
||||
ASDFPIXELSORT() {
|
||||
name = "fxASDFPixelSort";
|
||||
params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("mode", INTVAL, 0, 2, new int[]{RANDOM}));
|
||||
params.add(new Param("target", INTVAL, 0, 2, new int[]{RANDOM}));
|
||||
}
|
||||
int previousMode;
|
||||
|
||||
@@ -17,7 +17,7 @@ class ASDFPIXELSORT extends Shader {
|
||||
if (params.get(1).value == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
if (params.get(1).value == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
if (params.get(1).value == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
}
|
||||
}
|
||||
previousMode = int(params.get(1).value);
|
||||
row = 0;
|
||||
column = 0;
|
||||
@@ -290,16 +290,53 @@ class ASDFPIXELSORT extends Shader {
|
||||
|
||||
*/
|
||||
|
||||
|
||||
class DISTORTER extends Shader {
|
||||
class DISTORTER extends Shader{
|
||||
boolean do_blend = false; // blend image after process
|
||||
int blend_mode = OVERLAY; // blend type
|
||||
int channel = BRIGHTNESS; // channel used in processing (R,G,B) or (H,S,B)
|
||||
float scalex = 0.05; // from 0.01 to 1
|
||||
float scaley = 0.1; // from 0.01 to 1
|
||||
boolean shift_hue = true;
|
||||
float shift_amt = 0.1; // from 0 to 1
|
||||
|
||||
PImage buffer;
|
||||
|
||||
|
||||
int[][] distort = new int[2][512];
|
||||
final static float tick = 1.0/512.0;
|
||||
|
||||
int mode = 0;
|
||||
|
||||
DISTORTER() {
|
||||
|
||||
buffer = createImage(renderer.width, renderer.height, ARGB);
|
||||
name = "fxDIstorter";
|
||||
params.add(new Param("width", FLOATVAL, 1, buffer.width/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("height", FLOATVAL, 1, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM,SQUAR}));
|
||||
params.add(new Param("shift hue amount", FLOATVAL, 0, 1, new int[]{SAWTOOTH, SAWTOOTHINVERSE, TAN, TANINVERSE, RAMP, RAMPINVERSE}));
|
||||
params.add(new Param("scale x", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("scale y", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("blend mode", INTVAL, 0, 11, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
params.add(new Param("channel", INTVAL, 0, 12, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
|
||||
// channel, blend_mode
|
||||
|
||||
//params.add(new Param("height", FLOATVAL, 1, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
|
||||
|
||||
|
||||
// prepare distortion pattern
|
||||
for (int i=0; i<512; i++) {
|
||||
distort[0][i] = (int)random(-128, 128);
|
||||
distort[1][i] = (int)random(-128, 128);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
@@ -314,40 +351,30 @@ class DISTORTER extends Shader {
|
||||
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 neww = params.get(0).value;
|
||||
float newh = params.get(1).value;
|
||||
do_blend = boolean(int(params.get(2).value));
|
||||
shift_amt = params.get(3).value;
|
||||
scalex = params.get(4).value;
|
||||
scaley = params.get(5).value;
|
||||
blend_mode = blends[(int)params.get(6).value];
|
||||
channel = (int)params.get(7).value;
|
||||
|
||||
|
||||
float totalnum = neww+newh;
|
||||
float times = (totalnum/floor(totalnum/neww));
|
||||
float offx = (totalnum%neww)/times;
|
||||
float ratiox = neww/buffer.width;
|
||||
|
||||
renderer.beginDraw();
|
||||
renderer.colorMode(RGB);
|
||||
colorMode(RGB);
|
||||
renderer.noStroke();
|
||||
|
||||
for (int y=0; y<buffer.height; y++) {
|
||||
@@ -367,27 +394,26 @@ class DISTORTER extends Shader {
|
||||
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);
|
||||
float rx =getChannel(buffer.get(x, y), channel);
|
||||
int sx = (int)((buffer.width+x+cx*rx*scalex*0.1)%buffer.width);
|
||||
int sy = (int)((buffer.height+y+cy*scaley)%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));
|
||||
if (shift_hue) {
|
||||
colorMode(HSB, 255);
|
||||
c = color((hue(c)+shift_amt*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
|
||||
colorMode(RGB, 255);
|
||||
}
|
||||
// buffer.fill(lerpColor(c,img.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);
|
||||
if (do_blend)
|
||||
renderer.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, renderer.width, renderer.height, blend_mode);
|
||||
|
||||
colorMode(RGB);
|
||||
renderer.endDraw();
|
||||
}
|
||||
|
||||
@@ -420,4 +446,6 @@ class DISTORTER extends Shader {
|
||||
|
||||
return channel>5?255-cc:cc;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ class Oscillator {
|
||||
int spawnMillis;
|
||||
int pauseMillis;
|
||||
int beatCount = 0;
|
||||
int[] possibleModes;
|
||||
int mode;
|
||||
|
||||
//int function; //function to be called by bang-oscillators
|
||||
@@ -12,8 +13,10 @@ class Oscillator {
|
||||
float high = 1.0;
|
||||
boolean playing, pause, valInvert;
|
||||
|
||||
Oscillator(float bpm_) {
|
||||
Oscillator(float bpm_, int[] osciModes_) {
|
||||
bpm(bpm_);
|
||||
possibleModes = osciModes_;
|
||||
mode = possibleModes[int(random(possibleModes.length))];
|
||||
play();
|
||||
}
|
||||
|
||||
@@ -51,15 +54,20 @@ class Oscillator {
|
||||
value = 0;
|
||||
}
|
||||
|
||||
|
||||
boolean beat = false;
|
||||
void update() {
|
||||
if (playing) {
|
||||
while (millis() - spawnMillis > speed*beatCount) {
|
||||
beat = true;
|
||||
beatCount++;
|
||||
if (random(1) > .5) {
|
||||
mode = possibleModes[int(random(possibleModes.length))];
|
||||
bpm(int(random(2, 20)));
|
||||
}
|
||||
}
|
||||
|
||||
float millisToBeat = millis() - spawnMillis - (speed*beatCount);
|
||||
position = map(-millisToBeat, speed, 0, 0, TWO_PI);
|
||||
position = map(-millisToBeat, speed, 0, 0, TWO_PI); //position in time between last beat and next beat
|
||||
|
||||
switch(mode) {
|
||||
case(SINE):
|
||||
@@ -105,16 +113,19 @@ class Oscillator {
|
||||
else if (sin(position) >= 1.6666666666) value = 1.6666666666;
|
||||
value *= 1.5;
|
||||
break;
|
||||
case(RANDOM):
|
||||
//value = random(-1,1);
|
||||
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);
|
||||
if (mode != RANDOM) {
|
||||
value = constrain(value, -1.0, 1.0);
|
||||
value = map(value, -1.0, 1.0, low, high);
|
||||
} else if (beat && mode == RANDOM) {
|
||||
beat = false;
|
||||
value = random(low, high);
|
||||
}
|
||||
}
|
||||
|
||||
//fill(0);
|
||||
//ellipse(inc, height/2+value*height/4, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ public class SecondApplet extends PApplet {
|
||||
pos = pos_;
|
||||
params = params_;
|
||||
for (int i = 0; i < params.size(); i++) {
|
||||
slider.add(new Slider(10, 10+20*i+pos*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type)); //add possible waves to slider
|
||||
slider.add(new Slider(10, 10+20*i+pos*75, 230, 12, params.get(i).minValue, params.get(i).maxValue, params.get(i).name, params.get(i).type, params.get(i).osciModes)); //add possible waves to slider
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,12 +121,13 @@ public class SecondApplet extends PApplet {
|
||||
|
||||
class Slider {
|
||||
int x, y, w, h, mode;
|
||||
int[] osciModes;
|
||||
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_) {
|
||||
Slider(int x_, int y_, int w_, int h_, float minVal_, float maxVal_, String label_, int mode_, int[] osciModes_) {
|
||||
x = x_;
|
||||
y = y_;
|
||||
w = w_;
|
||||
@@ -135,8 +136,9 @@ public class SecondApplet extends PApplet {
|
||||
maxVal = maxVal_;
|
||||
mode = mode_;
|
||||
label = label_ + (mode == INTVAL ? " (INT)" : " (FLOAT)");
|
||||
|
||||
osci = new Oscillator(int(random(2, 20)));
|
||||
osciModes = osciModes_;
|
||||
|
||||
osci = new Oscillator(int(random(2, 20)), osciModes);
|
||||
osci.amplitude(minVal, maxVal);
|
||||
|
||||
animated = true;
|
||||
|
||||
@@ -20,7 +20,9 @@ class Shader {
|
||||
ArrayList<Param> params = new ArrayList<Param>();
|
||||
|
||||
void getValuesFromGUI(){
|
||||
try{ //problematic
|
||||
params = gui.bricks.get(pos).params;
|
||||
} catch(Exception e){}
|
||||
if(frameRate < 1) println("Rendering " + this + " on position " + pos + "...");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user