MAX challenge: basic loops

Jul 28, 2011 at 5:45am

MAX challenge: basic loops

I am trying to understand how to go about things in MAX and was wondering if someone could point out a good way (or a couple? – I suspect one can loop through a number of elements in more than one way in MAX) to implement something like this:

http://crida.net/stan/Downloads/temp/PAS/processing_task_001/processing_task_001.html

Feel free to point to the relevant points in the docs if this is as easy as that.

Thank you!

Anna

#58221
Jul 28, 2011 at 7:16am

Well thinking about this in a pure basic (not the language) programming way, the size of the circle is based on the distance of the mouse to the said circle. mousestate will tell you the current location of the mouse.which can be switched to a relative location on the max patcher window.

If I were you I would start with that object and trying to scale a single circle in the middle of a patcher window. Once you get it to work with one, duplicating that should be simple.

GW

#209168
Jul 28, 2011 at 9:16am

[counter] and [uzi] are the objects typically used to implement loops in Max/MSP

There are plenty of archived threads on this subject, although you may need to be creative to find a good search term to turn them up.

I’m wondering if Gregory has written a vignette or something on this. The early Max tutorials will also have a bit of coverage.

#209169
Jul 28, 2011 at 10:40am

Thank you both.

I can do it in standard programming. It just takes two “for” loops, nested. It is MAX I am not familiar with. Uzi is hardly a standard term, so who knew.

I tried searching for loops but this is too general a term. Hence the question.

I am off to look at uzi then. But further pointers are welcome.

:)

#209170
Jul 28, 2011 at 12:00pm

Here are my feeble attempts. The questions are in the patch.

Thanks!

– Pasted Max Patch, click to expand. –
#209171
Jul 28, 2011 at 12:09pm

this is how I do nested loops in max using uzi:

– Pasted Max Patch, click to expand. –
#209172
Jul 28, 2011 at 12:16pm

ok just saw your new post after I posted my thing– I’m no open gl (or jitter) guru, sorry!

#209173
Jul 28, 2011 at 12:43pm

No, Terry – super helpful! Here is my GL progess so far. Shall implement your loops next.

– Pasted Max Patch, click to expand. –
#209174
Jul 28, 2011 at 1:27pm

Terry, how can I output floats from your loop? Unless I am mistaken, they are integers and with small numbers they become zeros… Is there “cast” in MAX?

#209175
Jul 28, 2011 at 6:49pm

By default, mousestate reports global coordinates, but when you send the zero message, it uses the current mouse position as 0, 0.

For historical reasons, numbers are integers by default in Max. If you want calculations carried out in floating point numbers, most things take a float as an argument, which will cause calculations to be floating point. The int number box essentially does a cast to int.

– Pasted Max Patch, click to expand. –
#209176
Jul 28, 2011 at 6:50pm

For “casting” to float, check out float, flonum, trigger, and / (with a float argument).

For real basic tutorials on timed counting and stepping through an array of values, see
Timed Counting
and
Counting through a List

– Pasted Max Patch, click to expand. –
#209177
Jul 30, 2011 at 6:55am

Thank you all. Here is my progress so far. This is a non-GL version. I am trying to make both, for the learning purposes.

It would be great to hear an advise on how to proceed. Especially, on how to get to my objects and scale them relative to their centers and relative to the mouse position. Which objects would you use?

A couple of other questions are in the patch. Thank you for the advice!

– Pasted Max Patch, click to expand. –
#209178
Jul 30, 2011 at 7:18am

The “Why does this not look like a message?” question is easy. Somehow the background color of that message got set to white.

As far as the “This is supposed to be calculating the distance but I am not sure how to get to the “current” object. ” I’m not sure what you mean. What current object are you talking about?

#209179
Jul 30, 2011 at 7:52am

Thanks for looking into this. If you see the video int he very first post – this is my goal. I would like my circles to be scaling in proportion to their distance to the mouse position. Elsewhere, I would make them into classes and set their positions/sizes this way. I am not sure how to do this in MAX.

My patch is constantly redrawing them so I thought I should be able to draw them at the appropriate size within the loop. But how do I get into the uzi loop?

Sorry if I am sounding confused. It is because I am.

Here is something I am imagining:

for (int j=1; j

But MAX does things differently...

#209180
Jul 30, 2011 at 10:41am

There’s some bug in this that creates ovals instead of circles, but it at least illustrates one approach:

– Pasted Max Patch, click to expand. –
#209181
Jul 30, 2011 at 10:47am

I slightly changed your patch so it does what you want in principle– it needs some tweaking but I’m sure you can work that out.
the problem was your distance calculation result wasn’t going anywhere (see red patch cord), so now its modified to be part of the ‘uzi loop’

EDIT: gazumped by chris- I shouldn’t bother posting when he’s online; I’m sure it’s happened at least once before…

– Pasted Max Patch, click to expand. –
#209182
Jul 31, 2011 at 1:32pm

Thank you both for looking into it. Below is my latest effort based on your suggestions and some further improvements. I have commented it more fully and included the questions. I feel (but not sure) that the way looping works is responsible for the weird non-uniform scaling. See the comment in the patch.

If you could have a look again, it’d be super. I feel rather stuck…

Anna

– Pasted Max Patch, click to expand. –
#209183
Jul 31, 2011 at 2:28pm

I put a trigger in the scale circles bit of your patch, which now eliminates the ellipse distortion, so evidently it was an order of operation problem

also:
QUESTION: why is this number not changing? should it not be cycling through the values?
if you connect up a print object to the outputs of uzi you’ll see it’s doing what it is supposed to do

– Pasted Max Patch, click to expand. –
#209184
Jul 31, 2011 at 3:19pm

Order of operation issues and proper use of the trigger objects is one of the odder things people coming from standard programming languages have to get used to. The uzi/counter approaches to loops are odd, but until a newbie starts to ‘trace out’ patches, consider actual program flow in MaxMsp and have to use trigger to get what they want…well, it was a learning moment for me, as they say.

Remember if timed order of execution is critical, you can enforce order in a data flow language like Max with “trigger” (metaphorically, the dataflow equivalent of a CommonLisp PROG statement). Check it out! It’s so common in Max programming that they allow use of the alias ‘t’ when typing it’s name into the object box…
using trigger also helps you become aware of the Max datatypes you use…
l b i s f (list bang int symbol float) !

(& u ltr become aware that every one of those symbols (s) you create are in the running patch memory forever!;-)

#209185
Aug 1, 2011 at 12:34am

Thank you. As suspected then. Terry, can you possibly explain why you bang what you bang when you bang? I.e., why is it necessary to bang y in “scale circles” but not x? Is it because the bangs from the second uzi are coming through “distance”, etc. already and the values from the first uzi are only passed (banged) every 10th time?

If there are any materials specifically on the order of operation for me to read – please direct me there. Tutorials or documents.

Thanks.

#209186
Aug 1, 2011 at 1:15pm

Is it because the bangs from the second uzi are coming through “distance”, etc. already and the values from the first uzi are only passed (banged) every 10th time?

Yes, I think so.

Maybe if you search for ‘right to left order’ that might unearth something in the documentation, but probably the most instructive thing to do is put you patch through the debugger using the tracing utility, and see how the order of messaging works slowed down.
T

#209187
Aug 2, 2011 at 4:11am

This is a great suggestion. I was not even actively aware MAX had a debugger.

#209188

You must be logged in to reply to this topic.