rectangle coords

Brodie Matthews's icon

Hii, looking for some advice..If i send in an array, could i dynamically set the coordinates of this rectangle? Im just hacking at this so any advice is appeciated.Im still new to js so graphics is a bit of leaning curve.Thanks

Brodie Matthews's icon

Im aiming to run some loops, and sequnce some trails genrally just curious.

Brodie Matthews's icon

Id have to write the array first and generate var values, can i input the array/list through a message?

tyler mazaika's icon

Yes. I'd probably just store the rect coords as an array outside your paint function. Set the values using some function like:

// This is a pretty bad function but you should get the idea?
function setrect() {
    rect = [ arguments[0], arguments[1], arguments[2], arguments[3] ]
    mgraphics.redraw()
}


FWIW There's an excellent set of 30 example patches for mgraphics usage. I wish this were easier to find on the site: https://cycling74.com/tutorials/november-patch-a-day

Brodie Matthews's icon

id like to set var

w = setrect[0]; //etc.. and then assign them some how ? like

rect = w, x, y, z

i thought i had to use list() or anything() so i can input a list with a symbol as a function name?

Brodie Matthews's icon

okeyyy awesome setrect is woriking..always thought anything() was the only way

Brodie Matthews's icon

Thanks Tyler pretty awesome, very basic.be cool to add mouse drag..

tyler mazaika's icon

Glad it helped. You mean ondrag()? https://docs.cycling74.com/max8/vignettes/jsuiobject

Brodie Matthews's icon

Yeh im working toward that thanks also thanks for the link to the other references they will be a huge help.

what about setTimeout?

function newcolor(){ setTimeout (setrect, 1000, arguments[0] = random(), arguments[1] = random(), arguments[2] = random() );

tyler mazaika's icon

I'd start another thread to get better chance of more responses (since setTimeout is tangential to the initial question here). But I don't think it's available in JS in Max and you need to use the Task object. Would love to be proved wrong on that.

Brodie Matthews's icon

ok, ill see what the community says.

Brodie Matthews's icon

post is here Ill check out Task now

Brodie Matthews's icon


Task looks good, can i generate new arguments for setrect with task

function newcolor() {
var tsk = new Task(setrect, Math.random(), Math.random(), Math.random());
tsk.schedule(600)
  }

or

var tsk = new Task(setrect, arguments[0] = Math.random());

jsui_timeout1.js
text/javascript 0.65 KB