## Percentages

Feb 1, 2011 at 3:17pm

# Percentages

How do you set up a patch so that there is an object that gives you a percentage of squares that are white or black for a matrix displayed in a jit.pwindow for example

Ideally in a number box that updates as the program runs

#54708
Feb 1, 2011 at 5:56pm

look at jit.3m. If it’s just b&w image, the mean value of any color should be representative of the % white vs. black (scale 0-255 to 0. – 100.).

David

#197043
Feb 2, 2011 at 1:45pm

thanks David thats a nice simple solution. Cheers.

If I wanted to develop this further I ahve a question about maths. Awesome I know,

Now that I have a % of ‘life’ (white squares at a given time I want to write a mathematical expression that says something like:

‘if life = <25% tell oscillator, midinote, etc to play note A, (could be c1)
‘if life = >25% but <50%tel osc, midinote etc to play not B (could be c2)
…..etc for >50% and less than 75% = c3, and >75% = c4

To wirte an instruction/statement/message like this my head says if I put it between the two objects in question it will act as a sort of ‘check’ before produceing the outcome.

is this the case or is it better to have some sort of global message that applies to the patch as a whole? Also im trying to work through some examples with vexpr to try to acheive this – is this the right object to use?

#197044
Feb 2, 2011 at 7:51pm

Hi Ali,
There are a couple ways deal with conditions in Max. Start with if/then, e.g.:

[if \$f1 < 25. then bang]

– Pasted Max Patch, click to expand. –

Check out the if/then help for more syntax, multiple conditions, etc.

David

#197045

You must be logged in to reply to this topic.