Просмотр исходного кода

fixed random oscillator mode

master
Victor Giers 1 год назад
Родитель
Сommit
baeea26410
5 измененных файлов: 98 добавлений и 55 удалений
  1. 1
    1
      data/saves.sav
  2. 68
    40
      effects.pde
  3. 21
    10
      oscillator.pde
  4. 6
    4
      secondapplet.pde
  5. 2
    0
      shader.pde

+ 1
- 1
data/saves.sav Просмотреть файл

//globals //globals
uptime = 116626470
uptime = 116628228

+ 68
- 40
effects.pde Просмотреть файл

ASDFPIXELSORT() { ASDFPIXELSORT() {
name = "fxASDFPixelSort"; name = "fxASDFPixelSort";
params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG})); 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; int previousMode;


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 == 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 == 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})); 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); previousMode = int(params.get(1).value);
row = 0; row = 0;
column = 0; column = 0;
*/ */



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; PImage buffer;



int[][] distort = new int[2][512]; int[][] distort = new int[2][512];
final static float tick = 1.0/512.0; 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 = { final int[] blends = {
ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN
}; };

// ALL Channels, Nxxx stand for negative (255-value) // ALL Channels, Nxxx stand for negative (255-value)
// channels to work with // channels to work with
final static int RED = 0; final static int RED = 0;
final static int NHUE = 9; final static int NHUE = 9;
final static int NSATURATION = 10; final static int NSATURATION = 10;
final static int NBRIGHTNESS = 11; 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() { void apply() {
buffer = renderer.get(); buffer = renderer.get();
buffer.resize(renderer.width, renderer.height); 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 totalnum = neww+newh;
float times = (totalnum/floor(totalnum/neww)); float times = (totalnum/floor(totalnum/neww));
float offx = (totalnum%neww)/times; float offx = (totalnum%neww)/times;
float ratiox = neww/buffer.width; float ratiox = neww/buffer.width;


renderer.beginDraw(); renderer.beginDraw();
renderer.colorMode(RGB);
colorMode(RGB);
renderer.noStroke(); renderer.noStroke();


for (int y=0; y<buffer.height; y++) { for (int y=0; y<buffer.height; y++) {
float cx = lerp(distort[0][no1], distort[0][no2], l); float cx = lerp(distort[0][no1], distort[0][no2], l);
float cy = lerp(distort[1][no1], distort[1][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); 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.fill(c);
renderer.rect(x, y, 1, 1); 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(); renderer.endDraw();
} }




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


} }

+ 21
- 10
oscillator.pde Просмотреть файл

int spawnMillis; int spawnMillis;
int pauseMillis; int pauseMillis;
int beatCount = 0; int beatCount = 0;
int[] possibleModes;
int mode; int mode;


//int function; //function to be called by bang-oscillators //int function; //function to be called by bang-oscillators
float high = 1.0; float high = 1.0;
boolean playing, pause, valInvert; boolean playing, pause, valInvert;


Oscillator(float bpm_) {
Oscillator(float bpm_, int[] osciModes_) {
bpm(bpm_); bpm(bpm_);
possibleModes = osciModes_;
mode = possibleModes[int(random(possibleModes.length))];
play(); play();
} }


value = 0; value = 0;
} }


boolean beat = false;
void update() { void update() {
if (playing) { if (playing) {
while (millis() - spawnMillis > speed*beatCount) { while (millis() - spawnMillis > speed*beatCount) {
beat = true;
beatCount++; beatCount++;
if (random(1) > .5) {
mode = possibleModes[int(random(possibleModes.length))];
bpm(int(random(2, 20)));
}
} }


float millisToBeat = millis() - spawnMillis - (speed*beatCount); 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) { switch(mode) {
case(SINE): case(SINE):
else if (sin(position) >= 1.6666666666) value = 1.6666666666; else if (sin(position) >= 1.6666666666) value = 1.6666666666;
value *= 1.5; value *= 1.5;
break; break;
case(RANDOM):
//value = random(-1,1);
break;
default: default:
break; 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);
} }
} }

+ 6
- 4
secondapplet.pde Просмотреть файл

pos = pos_; pos = pos_;
params = params_; params = params_;
for (int i = 0; i < params.size(); i++) { 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
} }
} }




class Slider { class Slider {
int x, y, w, h, mode; int x, y, w, h, mode;
int[] osciModes;
float minVal, maxVal, value; //should be private but doesnt work lol float minVal, maxVal, value; //should be private but doesnt work lol
boolean hovering, hovering_anim_btn, animated, randomized; boolean hovering, hovering_anim_btn, animated, randomized;
String label; String label;
Oscillator osci; 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_; x = x_;
y = y_; y = y_;
w = w_; w = w_;
maxVal = maxVal_; maxVal = maxVal_;
mode = mode_; mode = mode_;
label = label_ + (mode == INTVAL ? " (INT)" : " (FLOAT)"); 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); osci.amplitude(minVal, maxVal);


animated = true; animated = true;

+ 2
- 0
shader.pde Просмотреть файл

ArrayList<Param> params = new ArrayList<Param>(); ArrayList<Param> params = new ArrayList<Param>();
void getValuesFromGUI(){ void getValuesFromGUI(){
try{ //problematic
params = gui.bricks.get(pos).params; params = gui.bricks.get(pos).params;
} catch(Exception e){}
if(frameRate < 1) println("Rendering " + this + " on position " + pos + "..."); if(frameRate < 1) println("Rendering " + this + " on position " + pos + "...");
} }

Загрузка…
Отмена
Сохранить