modularized functions .pde

master
Nova deViator 2015-09-11 15:19:06 +02:00
parent f6ada3fe18
commit 3399ae2b9f
4 changed files with 62 additions and 357 deletions

View File

@ -1,4 +1,4 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
/*
This file is part of "Interface Fractures III - Silicon".
Copyright (c) 2015 Luka Prinčič, All rights reserved.
@ -6,11 +6,6 @@
GNU General Public Licence. See COPYING for more info.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Interface Fractures III - Silicon
(c) Luka Prinčič / Nova deViator
nova@deviator.si
IF3Si.pde
*/

View File

@ -1,47 +1,17 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Interface Fractures III - SILICON
(c) nova@deviator.si
/*
functions.pde
This file is part of "Interface Fractures III - Silicon".
Copyright (c) 2015 Luka Prinčič, All rights reserved.
This program is free software distributed under
GNU General Public Licence. See COPYING for more info.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
functions.pde
*/
// loads all images into an array - - - - - - - - - - - - - - - - - - - - - - - - -
PImage[][] getImages(String folder) {
PImage[][] imgPool; // declare 2D array imgPool
File dir = new File(dataPath(sketchPath + folder)); // first folder
String[] dirlist = dir.list(); // an array of folders (strings)
dirlist = sort(dirlist); //
imgPool = new PImage[dirlist.length][10]; // create 2d array imgPool
for (int i = 0; i < dirlist.length; i++) {
String fulldir = dataPath(sketchPath + folder + dirlist[i]) + "/";
File dir2 = new File(fulldir);
String[] filelist = dir2.list(); // an array of image names
filelist = sort(filelist);
if (filelist.length != 0) {
for (int j = 0; j < filelist.length; j++) {
println("imgPool[" + i + "][" + j + "]: " + fulldir + filelist[j]);
imgPool[i][j] = loadImage(fulldir + filelist[j]);
}
} else {
println("No files in this folder: " + fulldir);
}
}
return imgPool;
}
// function to shuffle an array of integers - - - - - - - - - - - - - - - - - - - - -
// function to shuffle an array of integers
void shuffle(int[] a)
{
int temp, pick;
@ -55,124 +25,35 @@ void shuffle(int[] a)
}
}
void switchBlendMode(int blendMode) // - - - - - - - - - - - - - - - - - - - - - - -
{
switch(blendMode) {
case 0:
blendMode(ADD); // additive blending with white clip: C = min(A*factor + B, 255)
break;
case 1:
blendMode(SUBTRACT); // subtractive blend w/ black clip: C = max(B - A*factor, 0)
break;
case 2:
blendMode(LIGHTEST); // only the lightest colour succeeds: C = max(A*factor, B)
break;
case 3:
blendMode(DARKEST); // only the darkest colour succeeds: C = min(A*factor, B)
break;
case 4:
blendMode(SCREEN); // opposite multiply, uses inverse values of the colors.
break;
case 5:
blendMode(MULTIPLY); // multiply the colors, result will always be darker.
break;
case 6:
blendMode(EXCLUSION); // similar to DIFFERENCE, but less extreme.
break;
case 7:
blendMode(REPLACE); // pixels entirely replace others + don't utilize alpha values
break;
default:
blendMode(BLEND); // linear interp. of colours: C = A*factor + B. Default.
break;
} // DIFFERENCE: subtract colors from underlying image. NOT SUPPORTED BY P3D!! */
void screenClean(color c) { // -----------------------------------------
fill(c);
noStroke();
rect(0, 0, width, height);
}
void displayFps(boolean render) { // -----------------------------------
if (render){
// Display Fps
//fill(0); noStroke(); rect(width-80, 10, 80, 30, 4);
fill(255);
textFont(fpsFont);
textSize(16);
text(int(frameRate)+"fps", width-60, 20, 5);}
}
// TILES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* TODO:
- different zooms (random?)
- better rotation
- multiple instances of the same thing - with
different texture & some parameters + parameterize
- zoom variations
- ?amount of speed variations accross tiles
*/
void tiles( boolean render, // should we render or not?
color bgfill, // backgorund color
color tilecolor, // tile color
int huedist, // tile color distance for interpolation
int blendMode, // blending mode of tiles
int numx, // number of tiles on X
int numy, // number of tiles on Y
int texBank,
int texNum,
float texSpeedX,
float texSpeedY,
float overlap )
{
void autoSnap(boolean render) { // -------------------------------------
if (render) {
colorMode(HSB, 360, 100, 100, 100);
blendMode(BLEND);
fill(bgfill);
noStroke();
rect(0, 0, width, height);
switchBlendMode(blendMode); // blendMode function using integers
texSpeedX *= 0.01;
texSpeedY *= 0.01;
texX += sq(texSpeedX);
texY += sq(texSpeedY);
float numxfact = 1 / float(numx);
float numyfact = 1 / float(numy);
float aspectRatio = (height / float(numy)) / (width / float(numx));
float offsetPerc = overlap * (300/127);
float uniZoom = numxfact * (float(width)/1024);
float offsetX = width * numxfact * offsetPerc * 0.01;
float offsetY = height * numyfact * offsetPerc * 0.01;
float texoffsetX = 1 + 0.01 * offsetPerc ;
float texoffsetY = texoffsetX;
float huefactor = float(huedist) / (numx * numy);
for (int nx=0; nx < numx; nx++) {
for (int ny=0; ny < numy; ny++) {
int tileID = nx * numy + ny;
float randX = rands[ (tileID % rands.length) ] * 0.01;
float randY = rands[ ((tileID + 50) % rands.length) ] * 0.01;
float newhue = hue(tilecolor) + huefactor * tileID;
tint(newhue, saturation(tilecolor), brightness(tilecolor), alpha(tilecolor));
textureWrap(REPEAT);
textureMode(NORMAL);
beginShape();
texture(imgPool[texBank][texNum]);
vertex(width * numxfact * nx - offsetX, height * numyfact * ny - offsetY, 0 + texX * randX, 0 + texY * randY);
vertex(width * numxfact * (nx + 1) + offsetX, height * numyfact * ny - offsetY, 1 * uniZoom * texoffsetX + texX * randX, 0 + texY * randY);
vertex(width * numxfact * (nx + 1) + offsetX, height * numyfact * (ny + 1) + offsetY, 1 * uniZoom * texoffsetX + texX * randX, aspectRatio * uniZoom * texoffsetY + texY * randY);
vertex(width * numxfact * nx - offsetX, height * numyfact * (ny + 1) + offsetY, 0 + texX * randX, aspectRatio * uniZoom * texoffsetY + texY * randY);
endShape();
}
// auto-save snapshots
if (frameCount == 1000) {
saveFrame("../snapshots/"
+ year() + nf(month(),2)
+ nf(day(),2)
+ nf(hour(),2)
+ nf(minute(),2)
+ nf(second(),2)
+ "_.png");
}
}
}
@ -181,113 +62,6 @@ void tiles( boolean render, // should we render or not?
// TEST PICTURE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void testPicture(boolean render) {
if (render) {
fill(127);
stroke(255);
strokeWeight(1);
rect(1, 1, width-2, height-2);
ellipse(width/2, height/2, height-4, height-4);
ellipse(height/4, height/4, height/2-4, height/2-4);
ellipse(height/4, 3*height/4, height/2-4, height/2-4);
ellipse(width-height/4, height/4, height/2-4, height/2-4);
ellipse(width-height/4, 3*height/4, height/2-4, height/2-4);
line(width/2, 0, width/2, height);
line(0, height/2, width, height/2);
fill(0);
textFont(testFont);
textSize(50);
textAlign(CENTER,CENTER);
text("Interface Fractures III", width/2, height/2,4);
/* more tests:
- horizontal and vertical block, moving fast!
- flicker test, black&white, 60Hz
- color and gray stripes of interpolation
*/
}
}
// DRAW CUBE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void drawCube( boolean render, PGraphics cubes[],
int posX, int posY, int posZ,
int dimW, int dimH, int dimL,
float rotX, float rotY, float rotZ,
int blurAmount
//float xd, float yd
)
{
if (render) {
blendMode(BLEND);
fill(0);
rect(0, 0, width, height);
//blendMode(LIGHTEST);
for (int i=0; i < cubes.length; i++) {
posX += 100;
cubes[i].beginDraw();
cubes[i].clear();
cubes[i].smooth();
cubes[i].lights();
cubes[i].stroke(255);
cubes[i].strokeWeight(10);
cubes[i].fill(127);
//cubes[i].noFill();
cubes[i].translate(posX, posY, posZ);
cubes[i].rotateX(rotX);
cubes[i].rotateY(rotY);
cubes[i].rotateZ(rotZ);
cubes[i].box(dimW, dimH, dimL);
cubes[i].endDraw();
if (blurAmount != 0) { // this blur chokes graphic processor
blur.set("blurSize", blurAmount);
blur.set("sigma", 9.0f);
blur.set("horizontalPass", 0);
bpass1.beginDraw();
bpass1.clear();
//bpass1.noLights();
bpass1.shader(blur);
bpass1.image(cubes[i], 0, 0);
bpass1.endDraw();
blur.set("horizontalPass", 1);
cubes[i].beginDraw();
cubes[i].clear();
//cubes[i].noLights();
cubes[i].shader(blur);
cubes[i].image(bpass1, 0, 0);
cubes[i].endDraw();
}
image(cubes[i], 0, 0);
}
}
}
// SPHERES -----------------------------------------------------------
//offscreen render spheres
@ -359,55 +133,6 @@ void drawSpheres( boolean render
}
// TEST PATTERN - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/* TO BE ADDED:
- use quads
- add textures
>- more TO BE EXPANDED / REFINED!!! */
void testPattern( boolean render,
int imgBank, int imgID,
int imgAlpha,
int ylines,
int density,
int lwidth,
int lalpha,
int speed
)
{
if (render) {
tint(imgAlpha);
image(imgPool[imgBank][imgID], 0, 0);
blendMode(BLEND);
int yheight = height/ylines;
for (int y=0; y < ylines; y++) {
int yloc = int((y+1)*height/(ylines+1));
for (int x=0; x < width; x++) {
int index = x + (y * (width/ylines));
index = index % width;
if (randz.get(index) < density * 0.01 * randz.get((index + x + y) % randz.size())) {
int fx = (x + frameCount); // move!
fx = fx * speed * 1 * randz.get((abs(index - x + y) % randz.size())) / randz.size(); // speed!
fx %= width; // wrap at the right edge
color imgC = imgPool[imgBank][imgID].get(fx, yloc);
stroke(imgC, lalpha);
strokeWeight(1 + map(brightness(imgC), 0, 255, 0, lwidth));
line(fx, yheight * y + (yheight/30), fx, yheight * (y+1) - (yheight/30));
}
}
}
}
}
@ -495,35 +220,3 @@ void textureSphere(PGraphics pg, float rx, float ry, float rz, PImage t) {
// TOOLS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
void screenClean(color c) { // -----------------------------------------
fill(c);
noStroke();
rect(0, 0, width, height);
}
void displayFps(boolean render) { // -----------------------------------
if (render){
// Display Fps
//fill(0); noStroke(); rect(width-80, 10, 80, 30, 4);
fill(255);
textFont(fpsFont);
textSize(16);
text(int(frameRate)+"fps", width-60, 20, 5);}
}
void autoSnap(boolean render) { // -------------------------------------
if (render) {
// auto-save snapshots
if (frameCount == 1000) {
saveFrame("../snapshots/"
+ year() + nf(month(),2)
+ nf(day(),2)
+ nf(hour(),2)
+ nf(minute(),2)
+ nf(second(),2)
+ "_.png");
}
}
}

View File

@ -1,24 +1,17 @@
/*
This file is part of "Interface Fractures III - Silicon".
Copyright (c) 2015 Luka Prinčič, All rights reserved.
This program is free software distributed under
GNU General Public Licence. See COPYING for more info.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Interface Fractures III - Silicon
(c) Luka Prinčič / Nova deViator
nova@deviator.si
getLinesData.pde - process spectral lines
*/
ArrayList<FloatList> getLinesData() {
String[] siLinesData;
siLinesData = loadStrings(dataPath(sketchPath + "/silicon_lines.txt"));
@ -42,6 +35,9 @@ ArrayList<FloatList> getLinesData() {
for(int i = 0; i < siLinesList.size(); i ++) {
println(siLinesList.get(i).get(0));
float wavelength = siLinesList.get(i).get(0);
float intensity = siLinesList.get(i).get(1);
}
//printArray(siLinesList);

View File

@ -1,20 +1,41 @@
public void ctlin(int cc, int val) { // - - - - - - - - - - - - - - - - - - - - - - -
/*
This file is part of "Interface Fractures III - Silicon".
Copyright (c) 2015 Luka Prinčič, All rights reserved.
This program is free software distributed under
GNU General Public Licence. See COPYING for more info.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
osc.pde - open sound control communication
*/
void ctlin(int cc, int val) {
// public void ctlin(int cc, int val) {
// midi control values, from Renoise (via SC)
// debug
println("### OSC: /ctlin cc:" + cc + " value:" + val);
// patchbay
if (cc == 2) { tilesOverlap = val; }
// if (cc == 2) { flySpeedXfactor = (val - 64); } // FIXit!
// example:
// if (cc == 2) { flySpeedXfactor = (val - 64); }
}
public void scosc(String mount, int val) { // - - - - - - - - - - - - - - - - - - - - - - -
void scosc(String mount, int val) {
// public void scosc(String mount, int val) {
// stuff coming directly from SuperCollider
// debug
println("### OSC: /sc /mount: " + mount + " value: " + val);
println("### OSC: /sc mount:" + mount + " value:" + val);
// patchbay
if (mount.equals("testPatternToggle")) { testPatternToggle = boolean(val); }
if (mount.equals("testPictureToggle")) { testPictureToggle = boolean(val); }