MAX challenge: basic loops

jhdkfj39929's icon

jhdkfj39929

7月 28 2011 | 5:45 午前

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:

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

Thank you!

Anna

gwsounddsg's icon

gwsounddsg

7月 28 2011 | 7:16 午前

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

Peter Castine's icon

Peter Castine

7月 28 2011 | 9:16 午前

[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.

jhdkfj39929's icon

jhdkfj39929

7月 28 2011 | 10:40 午前

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.

:)

jhdkfj39929's icon

jhdkfj39929

7月 28 2011 | 12:00 午後

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

Max Patch
Copy patch and select New From Clipboard in Max.

Thanks!

Floating Point's icon

Floating Point

7月 28 2011 | 12:09 午後

Max Patch
Copy patch and select New From Clipboard in Max.

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

Floating Point's icon

Floating Point

7月 28 2011 | 12:16 午後

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

jhdkfj39929's icon

jhdkfj39929

7月 28 2011 | 12:43 午後

Max Patch
Copy patch and select New From Clipboard in Max.

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

jhdkfj39929's icon

jhdkfj39929

7月 28 2011 | 1:27 午後

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?

Chris Muir's icon

Chris Muir

7月 28 2011 | 6:49 午後

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

Max Patch
Copy patch and select New From Clipboard in Max.

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.

Christopher Dobrian's icon

Christopher Dobrian

7月 28 2011 | 6:50 午後

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

Max Patch
Copy patch and select New From Clipboard in Max.

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

jhdkfj39929's icon

jhdkfj39929

7月 30 2011 | 6:55 午前

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?

Max Patch
Copy patch and select New From Clipboard in Max.

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

Chris Muir's icon

Chris Muir

7月 30 2011 | 7:18 午前

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?

jhdkfj39929's icon

jhdkfj39929

7月 30 2011 | 7:52 午前

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...

Chris Muir's icon

Chris Muir

7月 30 2011 | 10:41 午前

Max Patch
Copy patch and select New From Clipboard in Max.

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

Floating Point's icon

Floating Point

7月 30 2011 | 10:47 午前

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'

Max Patch
Copy patch and select New From Clipboard in Max.

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

jhdkfj39929's icon

jhdkfj39929

7月 31 2011 | 1:32 午後

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...

Max Patch
Copy patch and select New From Clipboard in Max.

Anna

Floating Point's icon

Floating Point

7月 31 2011 | 2:28 午後

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

Max Patch
Copy patch and select New From Clipboard in Max.

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

Charles Baker's icon

Charles Baker

7月 31 2011 | 3:19 午後

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!;-)

jhdkfj39929's icon

jhdkfj39929

8月 01 2011 | 12:34 午前

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.

Floating Point's icon

Floating Point

8月 01 2011 | 1:15 午後

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

jhdkfj39929's icon

jhdkfj39929

8月 02 2011 | 4:11 午前

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