tutorial 46 external matrix in js

Jun 11, 2008 at 8:58am

tutorial 46 external matrix in js

hello
i am new to javascript, and i would like to know if someone could help
me with this
in the tutorial 46 the attractors are created inside the js object by
a jit.noise object, i would like to replace that jit.noise by a matrix
created outside the javascript object, so i can change the position of
the attractors, but i don’t know how to call that matrix in the js
object. could someone help or direct me for a patch that does that?

#38333
Jun 11, 2008 at 7:28pm

i don’t believe you would control the jit.matrix from inside the javascript, but instead pass the jit.matrix too the javascript and handle it with a function called jit_matrix.

a better approach might be to send x,y,z position information to the jit.matrices inside the javascript (for instance with a function called position(x,y,z).

otherwise, i think you can access named objects in your max patches from inside the javascript. look at the maxpatcher and maxbox js objects. my js is rusty, so this may be wrong.

-rob

#133427
Jan 22, 2014 at 5:07am

Old topic, but for other people coming in…
I’ve tried this and it works:

js code:

var myMatrix;

function bang() {
    myMatrix.setall(127);
}

function anything() {
    if (messagename=="setMyMatrix") {
        myMatrix = new JitterMatrix(arguments[1]);
        post("JS set matrix "+myMatrix.name+"\n");
    }
}

See the attached file (patch screenshot at end of post)
First click A: pWindow is black. Then click B (look at max window) and again A: pWindow is noisy. Then click C and again A: pWindow is grey.

———-begin_max6_patcher———-
{
“patcher” : {
“fileversion” : 1,
“appversion” : {
“major” : 6,
“minor” : 1,
“revision” : 6,
“architecture” : “x86″
}
,
“rect” : [ 29.0, 69.0, 378.0, 240.0 ],
“bglocked” : 0,
“openinpresentation” : 0,
“default_fontsize” : 12.0,
“default_fontface” : 0,
“default_fontname” : “Arial”,
“gridonopen” : 0,
“gridsize” : [ 15.0, 15.0 ],
“gridsnaponopen” : 0,
“statusbarvisible” : 2,
“toolbarvisible” : 1,
“boxanimatetime” : 200,
“imprint” : 0,
“enablehscroll” : 1,
“enablevscroll” : 1,
“devicewidth” : 0.0,
“description” : “”,
“digest” : “”,
“tags” : “”,
“boxes” : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 12.0,
"frgb" : 0.0,
"id" : "obj-42",
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 17.583313, 15.0, 19.0, 20.0 ],
“text” : “C”
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 12.0,
“frgb” : 0.0,
“id” : “obj-40″,
“maxclass” : “comment”,
“numinlets” : 1,
“numoutlets” : 0,
“patching_rect” : [ 63.583313, 15.0, 19.0, 20.0 ],
“text” : “B”
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 12.0,
“frgb” : 0.0,
“id” : “obj-39″,
“maxclass” : “comment”,
“numinlets” : 1,
“numoutlets” : 0,
“patching_rect” : [ 238.083313, 15.0, 19.0, 20.0 ],
“text” : “A”
}

}
, {
“box” : {
“id” : “obj-37″,
“maxclass” : “button”,
“numinlets” : 1,
“numoutlets” : 1,
“outlettype” : [ "bang" ],
“patching_rect” : [ 17.583313, 41.0, 20.0, 20.0 ]
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-35″,
“maxclass” : “message”,
“numinlets” : 2,
“numoutlets” : 1,
“outlettype” : [ "" ],
“patching_rect” : [ 102.083313, 151.0, 55.0, 19.0 ],
“text” : “compile”
}

}
, {
“box” : {
“color” : [ 1.0, 0.0, 0.0, 1.0 ],
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-34″,
“maxclass” : “newobj”,
“numinlets” : 1,
“numoutlets” : 1,
“outlettype” : [ "" ],
“patching_rect” : [ 63.583313, 193.0, 89.0, 21.0 ],
“saved_object_attributes” : {
“filename” : “setMatrix.js”,
“parameter_enable” : 0
}
,
“text” : “js setMatrix.js”
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-33″,
“maxclass” : “newobj”,
“numinlets” : 1,
“numoutlets” : 2,
“outlettype” : [ "jit_matrix", "" ],
“patching_rect” : [ 237.083313, 67.0, 91.0, 21.0 ],
“text” : “jit.matrix FOO”
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-32″,
“maxclass” : “newobj”,
“numinlets” : 1,
“numoutlets” : 1,
“outlettype” : [ "" ],
“patching_rect” : [ 63.583313, 123.0, 132.0, 21.0 ],
“text” : “prepend setMyMatrix”
}

}
, {
“box” : {
“id” : “obj-31″,
“maxclass” : “button”,
“numinlets” : 1,
“numoutlets” : 1,
“outlettype” : [ "bang" ],
“patching_rect” : [ 237.083313, 41.0, 20.0, 20.0 ]
}

}
, {
“box” : {
“id” : “obj-29″,
“maxclass” : “jit.pwindow”,
“numinlets” : 1,
“numoutlets” : 2,
“outlettype” : [ "", "" ],
“patching_rect” : [ 237.083313, 95.0, 80.0, 60.0 ]
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-14″,
“maxclass” : “newobj”,
“numinlets” : 1,
“numoutlets” : 2,
“outlettype” : [ "jit_matrix", "" ],
“patching_rect” : [ 63.583313, 95.0, 91.0, 21.0 ],
“text” : “jit.matrix FOO”
}

}
, {
“box” : {
“id” : “obj-12″,
“maxclass” : “button”,
“numinlets” : 1,
“numoutlets” : 1,
“outlettype” : [ "bang" ],
“patching_rect” : [ 63.583313, 41.0, 20.0, 20.0 ]
}

}
, {
“box” : {
“fontname” : “Arial”,
“fontsize” : 13.0,
“id” : “obj-5″,
“maxclass” : “newobj”,
“numinlets” : 1,
“numoutlets” : 2,
“outlettype” : [ "jit_matrix", "" ],
“patching_rect” : [ 63.583313, 67.0, 130.0, 21.0 ],
“text” : “jit.noise 1 char 10 10″
}

}
],
“lines” : [ {
"patchline" : {
"destination" : [ "obj-5", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-12", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-32", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-14", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-33", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-31", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-34", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-32", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-29", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-33", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-34", 0 ],
“disabled” : 0,
“hidden” : 0,
“midpoints” : [ 111.583313, 186.0, 73.083313, 186.0 ],
“source” : [ "obj-35", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-34", 0 ],
“disabled” : 0,
“hidden” : 0,
“midpoints” : [ 27.083313, 185.5, 73.083313, 185.5 ],
“source” : [ "obj-37", 0 ]
}

}
, {
“patchline” : {
“destination” : [ "obj-14", 0 ],
“disabled” : 0,
“hidden” : 0,
“source” : [ "obj-5", 0 ]
}

}
],
“dependency_cache” : [ ]
}

}
———–end_max6_patcher———–

Attachments:
  1. SetMatrixPatch
#278847

You must be logged in to reply to this topic.