Forums > Javascript

creating jit.matrix in javascript…

January 16, 2008 | 11:12 pm

I am trying to create a jit.matrix in javascript and
then connect it to a jit.gl.render. It looks like I
am creating everything but my matrix does not show up
in my jit.window. I think the problem is that I am not
connecting my matrix to my jit.gl.render. How exactly
do I do this from javascript?

my javascript, plasma.js…

// create our window
var window = new JitterObject("jit.window","testwindow");
window.depthbuffer = 1;
window.idlemouse = 1;

// create our render object for our window
var render = new JitterObject("jit.gl.render","testwindow");
//render.ortho = 2; //2d mode

// create our matrix
var draw_matrix = new JitterObject("jit.matrix", 4, "float32", 256, 256);
draw_matrix.exprfill("hypot(norm[0]-0.5,norm[1]-0.5)");

var mousedown = 0;

// create our listener object for our window
var mylistener = new JitterListener("testwindow",callbackfun);

function callbackfun(event)
{
var x,y,button;

if (event.eventname=="mouse")
{
// arguments are (x,y,button,cmd,shift,capslock,option,ctrl)
x = event.args[0];
y = event.args[1];
button = event.args[2];
mousedown = button;
}
else if (event.eventname=="mouseidle")
{
x = event.args[0];
y = event.args[1];
}
//post("callback: " + event.subjectname + " sent "+ event.eventname + " with (" + event.args + ")n");
}
callbackfun.local = 1;

function bang()
{
if (mousedown)
render.depth_clear(); // note that
else
render.erase();

draw_matrix.bang;
render.drawclients();
render.swap();
}

my patch…

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 102 133 40 9109513 compile;
#P number 87 82 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P toggle 42 81 15 0;
#P newex 42 106 55 9109513 qmetro 20;
#P newex 42 161 58 9109513 js plasma.js;
#P comment 156 166 234 9109513 example of listening to a window for window events;
#P connect 4 0 2 1;
#P connect 2 0 1 0;
#P connect 5 0 1 0;
#P connect 3 0 2 0;
#P window clipboard copycount 6;



jp
January 17, 2008 | 4:50 am

If I understand you correctly, you’re trying to display the contents
of matrix in a window. I think there are (at least) two ways to do
this.

1) Using jit.render.draw_pixels method

//jit.window
var windowTitle = "Window Title";
var window = new JitterObject("jit.window", windowTitle);

//jit.gl.render
var renderer = new JitterObject("jit.gl.render", windowTitle);

//create a matrix
var matrix1 = new JitterMatrix(4, "char", 10, 10); //for draw_pixels,
must be 4-plane char (I think)

//create noise to fill matrix
var noise = new JitterObject("jit.noise");
noise.dim = [10, 10];
noise.planecount = 4;
noise.type = "char";

//fill matrix with random values
noise.matrixcalc(matrix1, matrix1);

function bang() {

//drawing call
renderer.erase();
renderer.draw_pixels(matrix1.name);
renderer.swap();
}

2) Use jit.gl.videoplane

//jit.window
var windowTitle = "Window Title";
var window = new JitterObject("jit.window", windowTitle);

//jit.gl.render
var renderer = new JitterObject("jit.gl.render", windowTitle);

//create a matrix
var matrix1 = new JitterMatrix(1, "float32", 10, 10); //for
videoplane, can be any kind

//create noise to fill matrix
var noise = new JitterObject("jit.noise");
noise.dim = [10, 10];
noise.planecount = 1;
noise.type = "float32";

//fill matrix with random values
noise.matrixcalc(matrix1, matrix1);

//create jit.gl.videoplane
var videoplane = JitterObject("jit.gl.videoplane", windowTitle);
videoplane.interp = 0; //or else you get interp, default = 1

function bang() {

videoplane.jit_matrix(matrix1.name);

//drawing call
renderer.erase();
renderer.drawclients();
renderer.swap();
}

Hope this helps.

jp

On Jan 16, 2008, at 4:12 PM, Anthony Palomba wrote:

>
> I am trying to create a jit.matrix in javascript and
> then connect it to a jit.gl.render. It looks like I
> am creating everything but my matrix does not show up
> in my jit.window. I think the problem is that I am not
> connecting my matrix to my jit.gl.render. How exactly
> do I do this from javascript?
>
>
> my javascript, plasma.js…
>
> // create our window
> var window = new JitterObject("jit.window","testwindow");
> window.depthbuffer = 1;
> window.idlemouse = 1;
>
> // create our render object for our window
> var render = new JitterObject("jit.gl.render","testwindow");
> //render.ortho = 2; //2d mode
>
> // create our matrix
> var draw_matrix = new JitterObject("jit.matrix", 4, "float32", 256,
> 256);
> draw_matrix.exprfill("hypot(norm[0]-0.5,norm[1]-0.5)");
>
>
> var mousedown = 0;
>
> // create our listener object for our window
> var mylistener = new JitterListener("testwindow",callbackfun);
>
> function callbackfun(event)
> {
> var x,y,button;
>
> if (event.eventname=="mouse")
> {
> // arguments are (x,y,button,cmd,shift,capslock,option,ctrl)
> x = event.args[0];
> y = event.args[1];
> button = event.args[2];
> mousedown = button;
> }
> else if (event.eventname=="mouseidle")
> {
> x = event.args[0];
> y = event.args[1];
> }
> //post("callback: " + event.subjectname + " sent "+ event.eventname
> + " with (" + event.args + ")
> ");
> }
> callbackfun.local = 1;
>
> function bang()
> {
> if (mousedown)
> render.depth_clear(); // note that
> else
> render.erase();
>
> draw_matrix.bang;
> render.drawclients();
> render.swap();
> }
>
>
>
>
> my patch…
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P message 102 133 40 9109513 compile;
> #P number 87 82 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
> #P toggle 42 81 15 0;
> #P newex 42 106 55 9109513 qmetro 20;
> #P newex 42 161 58 9109513 js plasma.js;
> #P comment 156 166 234 9109513 example of listening to a window for
> window events;
> #P connect 4 0 2 1;
> #P connect 2 0 1 0;
> #P connect 5 0 1 0;
> #P connect 3 0 2 0;
> #P window clipboard copycount 6;
>
>
>
>


January 18, 2008 | 4:32 pm

That worked! Thanks.


Viewing 3 posts - 1 through 3 (of 3 total)