Archive

Archive for the ‘code’ Category

Tutorial 46 to java

I had the impression that the only “official” particle system example on jitter( tutorial 46) was rather slow using javascript so I ported it to java. The porting was really straight forward and I think it might be a nice study source. Notice that the methods bang_expr() and bang_iter() are not implemented( yet!).
Hope someone finds this useful.


import com.cycling74.max.*;
import com.cycling74.jitter.*;
import java.io.*;

public class MxTutorial46b extends MaxObject{
int PARTICLE_COUNT = 1000;
int ATTRACTOR_COUNT = 3;
JitterObject noisegen;
JitterObject attgen;
JitterObject myexpr;
JitterObject myexpr2;
//matrices
JitterMatrix particlemat;
JitterMatrix velomat;
JitterMatrix attmat;
JitterMatrix distmat;
JitterMatrix tempmat;
JitterMatrix summat;
JitterMatrix summat2;
JitterMatrix scalarmat;
JitterMatrix amat;

float a = 0.001f;
float d = 0.01f;
//String perform_mode = “op”;
//String perform_mode;
int perform_mode;
//String draw_primitive = “points”;
String draw_primitive;

public MxTutorial46b(){
declareInlets(new int[]{DataTypes.ALL});
declareOutlets(new int[]{DataTypes.ALL});

//perform_mode = new String(“op”);
perform_mode = 0;
draw_primitive = new String(“points”);

//declare the noise objects
//noisegen = new JitterObject(“jit.noise”,”float32″);
noisegen = new JitterObject(“jit.noise”);
noisegen.setAttr(“dim”, PARTICLE_COUNT);
noisegen.setAttr(“planecount”,3);
noisegen.setAttr(“type”, “float32”);

attgen = new JitterObject(“jit.noise”);
attgen.setAttr(“dim”, ATTRACTOR_COUNT);
attgen.setAttr(“planecount”, 3);
attgen.setAttr(“type”, “float32”);

myexpr = new JitterObject(“jit.expr”);
myexpr.setAttr(“expr”, “in[0].p[0]+in[0].p[1]+in[0].p[2]”);
// second expression: evaluate a+((b-c)*d/e)

myexpr2 = new JitterObject(“jit.expr”);
myexpr2.setAttr(“expr”, “in[0]+((in[1]-in[2])*in[3]/in[4])”);

//matrices declaration
particlemat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
velomat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
attmat = new JitterMatrix(3,”float32″,ATTRACTOR_COUNT);
distmat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
tempmat = new JitterMatrix(3,”float32″, PARTICLE_COUNT);
summat = new JitterMatrix(3,”float32″, PARTICLE_COUNT);
summat2 = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
scalarmat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);
amat = new JitterMatrix(3,”float32″,PARTICLE_COUNT);

init();

post(“this is a port of tutorial 46!\n”);
}

public void init(){
noisegen.matrixcalc(particlemat, particlemat);
particlemat.op(“*”, 2.0f);
particlemat.op(“-“, 1.0f);
// generate a matrix of random velocities spread between -1 and 1
noisegen.matrixcalc(velomat, velomat);
velomat.op(“*”, 2.0);
velomat.op(“-“, 1.0);
// generate a matrix of random attractors spread between -1 and 1
attgen.matrixcalc(attmat, attmat);
attmat.op(“*”, 2.0);
}

public void bang(){
switch(perform_mode) { // choose from the following…
case 0: // use Jitter matrix operators
bang_op();
break;
case 1: // use [jit.expr] for the bulk of the algorithm
bang_expr();
break;
case 2: // iterate cell-by-cell through the matrices
bang_iter();
break;
default:
bang_op();
break;
}

outlet(0,”jit_matrix”,particlemat.getName());
}

public void bang_op(){
//int plane = 0;

for(int i =0;i<ATTRACTOR_COUNT;i++){
scalarmat.setall(attmat.getcell1d(i));
tempmat.op("-", scalarmat, particlemat);
distmat.op("*", tempmat, tempmat);

//summat.planemap = 0;
summat.setAttr("planemap", 0);
summat.frommatrix(distmat);
summat.setAttr("planemap", 1);
summat.frommatrix(distmat);
summat.setAttr("planemap", 2);
summat2.frommatrix(distmat);
summat.op("+", summat, summat2);

tempmat.op("*", a);
// divide our distances by the sum of the distances
// to derive gravity for this frame:
tempmat.op("/", summat);
// add to the current velocity bearings to get the
// amount of motion for this frame:
velomat.op("+", tempmat);
}

particlemat.op("+", velomat);
// reduce our velocities by the decay factor for the next frame:
velomat.op("*", d);
}

public void bang_expr(){
//not implemented yet

}

public void bang_iter(){
//not implemented yet

}

public void particles(int v){
PARTICLE_COUNT = v;

// resize matrices
noisegen.setAttr("dim", PARTICLE_COUNT);
particlemat.setAttr("dim", PARTICLE_COUNT);
velomat.setAttr("dim", PARTICLE_COUNT);
distmat.setAttr("dim", PARTICLE_COUNT);
attmat.setAttr("dim",PARTICLE_COUNT);
tempmat.setAttr("dim", PARTICLE_COUNT);
summat.setAttr("dim", PARTICLE_COUNT);
summat2.setAttr("dim", PARTICLE_COUNT);
scalarmat.setAttr("dim",PARTICLE_COUNT);
amat.setAttr("dim",PARTICLE_COUNT);

init(); // re-initialize particle system
}

public void attractors(int v){
ATTRACTOR_COUNT = v;

attgen.setAttr("dim", ATTRACTOR_COUNT);

init();
}

public void accel(int v){
a = v * 0.001f;
}

public void decay(int v){
d = v * 0.001f;
}

// public void mode(String v){
// perform_mode = v;
// }

public void mode(int v){
perform_mode = v;
}

public void primitive(String v){
draw_primitive = v;
}

/*
function smear(v) // turn on drawing smear by zeroing the alpha on the renderer's erase color
{
if(v) {
// smear on (alpha=0):
outlet(0, "erase_color", 1., 1., 1., 0.);
}
else {
// smear off (alpha=0.1):
outlet(0, "erase_color", 1., 1., 1., 0.1);
}
}
*/

}

NOTE: WORDPRESS SUCKS!!!, I HAVE TRIED TO UPLOAD THE MAX PATCH BUT SOMEHOW IT DOESN’T WORK ON COPY COMPRESSED FORMAT. I WILL MIGRATE MOST OF MY POSTS TO MY WEBPAGE AND WILL ZIP MOST OF THE MATERIALS. MEANWHILE YOU CAN REQUEST ME DIRECTLY THE MAX PATCH!

Categories: code, java, jitter

So the controversy continues…

For sure one of the most interesting and elusive topics I have dealt with the last months has been the idea of porting processing libraries to jitter. I’ve gotten a lot of feedback from different friends that are( by far) more proficient java users.
But first an important question: why bothering porting libraries from an applet-based programing language into jitter. Many possible answers can be given, some of them as simple as to say it is an interesting challenge. However, the tool of having java inside jitter provides an interesting window to some of the functionalities that are not ‘native’ to the way jitter handles visuals. Let’s put as a very simple example the traer physics engine: it is a very simple and elegant way to handle physical modeling. So why not using such nice facility within jitter?
Second interesting point to deal with is the way things should be implemented. As far as my understanding goes jitter manages only planar arrays( not multidimensional). There are two basic methods to assign the value of each one of the members:
-copyArrayToVectorPlanar
-setcell

so far I am not sure which one of the methods is better. Or even better, as both methods seem to be quite efficient their usage criteria falls more into specific needs.
Take the next example:
case 1-a random cluster of lines. Then to have something like this on the bang() method:

int plane=0;
int dim=0;
int[] offset=new int[]{0};
int count=amount;
int arrayoffset=0;

for(int i=0;i<amount;i++){
x[i]=(float)Math.random()-0.5f;
y[i]=(float)Math.random()-0.5f;
z[i]=(float)Math.random()-0.5f;
}

gl1.copyArrayToVectorPlanar(plane,dim,offset,x,count,arrayoffset);
plane=1;
gl1.copyArrayToVectorPlanar(plane,dim,offset,y,count,arrayoffset);
plane=2;
gl1.copyArrayToVectorPlanar(plane,dim,offset,z,count,arrayoffset);

from here it would be easier to use the sketch object providing ‘raw’ gl commands. Notice that each plane is filled with an array of values coming from the for loop( don’t forget to declare your arrays or containers!).

case 2- using a wrapper to gain a more ‘literal’ version of the processing original patch into jitter’s matrixland. So for instance:

public void toMatrix(JitterMatrix jm) {
if (jm == null) { return;}
final int size = (jm.getDim()[0] >= _particles.size()) ? _particles.size() : jm.getDim()[0] ;
if (_particles.isEmpty()) {
populateParticleList();
}
Vector3D vec = null;

for (int i = 0; i < size; i++) {
vec = _particles.get(i).position();
pos[0] = i;
jm.setcell(pos, 0,(vec.x() – 200.0f) / 200.0f );
jm.setcell(pos, 1,(vec.y() – 200.0f) / 200.0f );
jm.setcell(pos, 2,(vec.z() – 200.0f) / 200.0f );
}
}
/**
* run once in setup, after all elements of the system are created
*/
protected final void populateParticleList() {
for (int i = 0; i < _ps.numberOfParticles(); i++) {
//
_particles.add(i, _ps.getParticle(i));
}
}

So far I am still trying to put my hands on this approach( thanks Panos for the eye opener!). Not sure if this is more efficient or easier( this type of implementation relies deeply on overriding methods).

We will see, I will try to post more examples as soon as I can!

P.S.By opening the source of the traer physics I was kinda of amazed how old the java lang used on the package seemed to be. There are not even containers on them! Still the library is super cool!

Categories: code, jitter, processing

Wormer and wormer

Tweaking the last parts of the ‘Worm Songs’ project( music by Henry Vega). Trying to make the visuals look minimal and elegant. We have put a lot of love and work on this project.

Sketches for the 'worm songs'

Sketches for the 'worm songs'

Sketches for the 'worm songs'

Sketches for the 'worm songs'

worm songs

worm songs

worm songs

worm songs

worm songs

Studies on light and motion

Take light, make a photo, then break it. Just stay there, watching…

take light…

light motion

take light…

point wave

Categories: code, openGL

Glass surface projection test

February 19, 2011 Leave a comment

For a while I have been interested on the topic of projection over reflective surfaces. I have explored possibilities with different people. This week we tried a kind of ‘kaleidoscopic’ test pilling up different layers of glass. However, and this for most things in life, simplicity is better. After trying different things we finished just placing a glass with a certain angle to the scree. The result is nice, I like it…

Glass projection experiment from Emmanuel Flores Elías on Vimeo.

Categories: code

‘Imagine’ installation test#1

February 9, 2011 Leave a comment

Having lot of fun with Marcus Graf. Each meeting is like a masterclass. We are currently preparing the installation for the ‘Imagine’ performance this next monday at the Cadance festival. Herewith a small video of the testing:

‘Imagine’ test#1 from Emmanuel Flores Elías on Vimeo.

We are using a Kinect’s IR to detect the motion and distance. The cloth is designed using java and jitter. We have been playing a lot with the environmental texturing.

Categories: code

Florito++Flores = inspiration!

February 8, 2011 Leave a comment

We are currently preparing a foyer installation for the CaDance Festival in Den Haag, Netherlands:


http://www.cadance.nl/

I am having the enormous pleasure of working with my friend Marcus Graf:

http://www.marcusgraf.com/

http://www.florito.net

All i can say is that the level of inspiration is at the top. It is fantastic to have the chance to exchange code, view and good times with such a skilled and amazing software artist.
We have been playing with the Kinect and making vector fields with it. What you actually see is my hand waving around. We expect to have lot of nice code and fun the coming days!


Categories: code, jitter