Forums > MaxMSP

Pi

February 19, 2008 | 5:27 pm


February 19, 2008 | 5:49 pm



kjg
February 19, 2008 | 6:03 pm


February 19, 2008 | 6:09 pm


February 19, 2008 | 6:21 pm



kjg
February 19, 2008 | 6:55 pm

Quote: notyouraveragejoe wrote on Tue, 19 February 2008 19:21
—————————————————-
> What I didn’t explain was the purpose of this, sorry I should have explained
> this earlier. I’m putting this code into an arduino to control the PWM pins
> so it needs tobe something I can convert into simple C coding.
>

still comes down to mapping right? or am i not understanding you?

i’m not sure if you need ints or floats for the 0-255 range. in case you need floats take out the int() parts.

hope this helps.

#P origin 418 0;
#P window setfont "Sans Serif" 9.;
#P number 31 173 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 31 151 254 196617 expr int(((359.*($i1/255.)+90.)%360.)/360.*255.);
#P number 31 129 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 31 107 254 196617 expr int(((359.*($i1/255.)+60.)%360.)/360.*255.);
#P number 31 85 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 31 63 254 196617 expr int(((359.*($i1/255.)+30.)%360.)/360.*255.);
#P number 31 41 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden connect 0 0 1 0;
#P connect 1 0 2 0;
#P hidden connect 0 0 3 0;
#P connect 3 0 4 0;
#P hidden connect 0 0 5 0;
#P connect 5 0 6 0;



kjg
February 19, 2008 | 7:03 pm

correction(/359 instead of 360):

#P origin 418 0;
#P window setfont "Sans Serif" 9.;
#P number 31 173 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 31 151 254 196617 expr int(((359.*($i1/255.)+90.)%360.)/359.*255.);
#P number 31 129 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 31 107 254 196617 expr int(((359.*($i1/255.)+60.)%360.)/359.*255.);
#P number 31 85 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 31 63 254 196617 expr int(((359.*($i1/255.)+30.)%360.)/359.*255.);
#P number 31 41 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden connect 0 0 1 0;
#P connect 1 0 2 0;
#P hidden connect 0 0 3 0;
#P connect 3 0 4 0;
#P hidden connect 0 0 5 0;
#P connect 5 0 6 0;


February 19, 2008 | 8:46 pm

maybe this is a theoretical question, but I think you have to use
zmap 0 256 0 360
otherwise with 0 255 0 359 the last step (from 255 back to 0(=256))
would be unproportionally smaller in the mapped values (from 359 to 360/0).
therefore: expr int(((360.*($i1/256.)+90.)%360.)/360.*256.).
or am I wrong???
marius.

Klaas-Jan Govaart wrote:
> correction(/359 instead of 360):
>
> #P origin 418 0;
> #P window setfont "Sans Serif" 9.;
> #P number 31 173 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window linecount 1;
> #P newex 31 151 254 196617 expr int(((359.*($i1/255.)+90.)%360.)/359.*255.);
> #P number 31 129 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 31 107 254 196617 expr int(((359.*($i1/255.)+60.)%360.)/359.*255.);
> #P number 31 85 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 31 63 254 196617 expr int(((359.*($i1/255.)+30.)%360.)/359.*255.);
> #P number 31 41 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P hidden connect 0 0 1 0;
> #P connect 1 0 2 0;
> #P hidden connect 0 0 3 0;
> #P connect 3 0 4 0;
> #P hidden connect 0 0 5 0;
> #P connect 5 0 6 0;
>



kjg
February 19, 2008 | 11:25 pm

Quote: marius.schebella wrote on Tue, 19 February 2008 21:46
—————————————————-
> maybe this is a theoretical question, but I think you have to use
> zmap 0 256 0 360

Hi Marius,

I think you have to divide/multiply by the maximum value in the new range.

Or when using zmap: old minimum to new minimum and old maximum to new maximum.

Anybody please correct me if I’m wrong.

Regards,
kjg

This is my take at it:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 202 246 43 196617 % 360.;
#P comment 134 541 67 196617 or use floats;
#P newex 131 246 29 196617 t b f;
#P comment 317 192 149 196617 offset in degrees (-360 – 360);
#P comment 342 209 20 196617 ==;
#P message 85 46 26 196617 513;
#P message 35 24 14 196617 0;
#P message 52 40 26 196617 256;
#P comment 244 248 221 196617 no negative values for modulo..;
#P number 360 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 307 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user hslider 162 207 18 128 721 1 -360 0;
#P newex 162 246 40 196617 + 360.;
#P newex 232 184 72 196617 loadmess 390;
#P comment 218 398 242 196617 multiply by maximum value in new range (0-255);
#P flonum 54 541 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 143 416 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 49 416 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 10.;
#P newex 54 514 272 196618 expr ($i1 /255. * 359. + $f2) %360. /359. *255.;
#P window setfont "Sans Serif" 9.;
#P number 8 517 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 116 88 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 79 88 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window setfont "Sans Serif" 10.;
#P newex 8 492 326 196618 expr int(($i1 /255. * 359. + $f2) %360. /359. *255. +0.5);
#P window setfont "Sans Serif" 9.;
#P newex 129 434 34 196617 + 0.5;
#P newex 35 434 34 196617 + 0.5;
#P comment 212 457 217 196617 round and convert back to ints;
#P number 129 470 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 35 470 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 129 452 27 196617 i;
#P newex 35 452 27 196617 i;
#P comment 212 340 141 196617 divide by the maximum value;
#P newex 129 395 41 196617 * 255.;
#P newex 35 395 84 196617 zmap 0 1 0 255.;
#P comment 212 360 131 196617 range of 256 values (0-1.);
#P flonum 143 359 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 129 337 40 196617 / 359.;
#P flonum 49 359 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 337 84 196617 zmap 0 359 0 1.;
#P comment 212 91 289 196617 % to make 256 wrap back to 0 – range of 256 values (0-255);
#P newex 35 86 40 196617 % 256;
#P flonum 143 295 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 49 295 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P comment 212 272 221 196617 modulo to make 360 wrap back to 0 (or offset);
#P newex 35 272 43 196617 % 360.;
#P newex 129 272 43 196617 % 360.;
#P comment 171 230 149 196617 offset in degrees (-360 – 360);
#P newex 35 207 27 196617 + 0.;
#P newex 129 207 27 196617 + 0.;
#P comment 212 163 242 196617 multiply by maximum value in new range (0-359);
#P flonum 143 184 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 49 184 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 129 161 41 196617 * 359.;
#P newex 35 161 87 196617 zmap 0 1. 0 359.;
#P comment 212 135 131 196617 range of 256 values (0-1.);
#P comment 212 114 277 196617 divide by the maximum value (not by the number of values);
#P flonum 143 134 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 129 112 40 196617 / 255.;
#P flonum 49 134 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 112 84 196617 zmap 0 255 0 1.;
#P user hslider 35 64 18 128 513 1 0 0;
#P comment 212 69 138 196617 range of 513 values (0-512);
#P comment 57 23 193 196617 value number 0 256 or 513 (0 , 0 and 0);
#P connect 59 0 39 0;
#P fasten 2 0 39 0 40 84 13 84;
#P connect 39 0 42 0;
#P connect 56 0 2 0;
#P connect 55 0 2 0;
#P connect 54 0 2 0;
#P connect 2 0 22 0;
#P connect 22 0 3 0;
#P connect 3 0 9 0;
#P connect 59 0 15 0;
#P connect 9 0 15 0;
#P connect 15 0 18 0;
#P connect 18 0 24 0;
#P connect 24 0 29 0;
#P connect 29 0 37 0;
#P connect 37 0 32 0;
#P connect 32 0 34 0;
#P connect 3 0 4 0;
#P connect 9 0 11 0;
#P connect 18 0 20 0;
#P connect 24 0 25 0;
#P connect 29 0 44 0;
#P connect 59 1 15 1;
#P connect 59 0 43 0;
#P fasten 2 0 43 0 40 84 22 84 22 434 59 434;
#P connect 43 0 46 0;
#P connect 2 0 40 0;
#P connect 22 0 41 0;
#P connect 22 0 5 0;
#P connect 5 0 10 0;
#P connect 59 0 14 0;
#P connect 10 0 14 0;
#P connect 14 0 17 0;
#P connect 17 0 26 0;
#P connect 26 0 30 0;
#P connect 30 0 38 0;
#P connect 38 0 33 0;
#P connect 33 0 35 0;
#P connect 49 0 59 0;
#P connect 5 0 6 0;
#P connect 10 0 12 0;
#P connect 17 0 21 0;
#P connect 26 0 27 0;
#P connect 30 0 45 0;
#P connect 59 1 14 1;
#P connect 48 0 50 0;
#P connect 50 0 49 0;
#P hidden connect 49 0 61 0;
#P hidden connect 50 0 51 0;
#P connect 59 1 43 1;
#P connect 59 1 39 1;
#P hidden connect 61 0 52 0;



kjg
February 19, 2008 | 11:47 pm

Quote: kjg wrote on Wed, 20 February 2008 00:25
—————————————————-
> Quote: marius.schebella wrote on Tue, 19 February 2008 21:46
> —————————————————-
> > maybe this is a theoretical question, but I think you have to use
> > zmap 0 256 0 360
>
> Hi Marius,
>
> I think you have to divide/multiply by the maximum value in the new range.

sorry, that is not correct:

you have to divide by the maximum value in the old range to scale to the range 0-1, then multiply by the maximum value in the new range to get the range 0-newmax.

Or in one go: multiply by newmax/oldmax

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P comment 331 218 88 196617 newmax /oldmax;
#P comment 331 99 88 196617 newmax /oldmax;
#P number 300 321 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 300 298 34 196617 + 0.5;
#P number 181 321 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 181 298 34 196617 + 0.5;
#P number 32 321 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 32 298 34 196617 + 0.5;
#P flonum 300 251 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 398 58 26 196617 255;
#P message 349 58 26 196617 359;
#P message 398 175 26 196617 359;
#P message 349 175 26 196617 255;
#P newex 300 199 108 196617 expr $i1 * ($f2/$f3);
#P newex 300 80 108 196617 expr $i1 * ($f2/$f3);
#P hidden newex 497 27 48 196617 loadbang;
#P flonum 181 251 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 181 199 99 196617 zmap 0 359. 0 255.;
#P newex 181 80 96 196617 zmap 0 255 0 359.;
#P flonum 32 251 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P comment 102 180 50 196617 newmax /oldmax;
#P window linecount 1;
#P newex 32 227 29 196617 * 1.;
#P message 51 177 26 196617 255;
#P message 68 193 26 196617 359;
#P newex 51 209 27 196617 / 1.;
#P flonum 32 149 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 32 124 29 196617 * 1.;
#P message 51 74 26 196617 359;
#P message 68 90 29 196617 255;
#P newex 51 106 27 196617 / 1.;
#P number 32 36 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P comment 102 79 50 196617 newmax /oldmax;
#P connect 1 0 5 0;
#P connect 5 0 6 0;
#P connect 6 0 10 0;
#P connect 10 0 12 0;
#P connect 12 0 24 0;
#P connect 24 0 25 0;
#P hidden connect 16 0 4 0;
#P connect 4 0 2 0;
#P connect 2 0 5 1;
#P hidden connect 16 0 9 0;
#P connect 9 0 7 0;
#P connect 7 0 10 1;
#P hidden connect 16 0 3 0;
#P connect 3 0 2 1;
#P hidden connect 16 0 8 0;
#P connect 8 0 7 1;
#P connect 1 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 15 0;
#P connect 15 0 26 0;
#P connect 26 0 27 0;
#P connect 1 0 17 0;
#P connect 17 0 18 0;
#P connect 18 0 23 0;
#P connect 23 0 28 0;
#P connect 28 0 29 0;
#P hidden connect 16 0 21 0;
#P connect 21 0 17 1;
#P hidden connect 16 0 19 0;
#P connect 19 0 18 1;
#P hidden connect 16 0 22 0;
#P connect 22 0 17 2;
#P hidden connect 16 0 20 0;
#P connect 20 0 18 2;


February 20, 2008 | 1:23 am

as I said before, it is only a very small differenced, but the maximum
values are 360 and 256.
in a distance from 0 to 1 your highest integer number is 0, in a
distance from 0 to 2, it is 1…

0———————–(1)
0———–1———–(2)
0——-1——-2——-(3)
0—–1—–2—–3—–(4)
0—1—2—3—4—5—(6)
0–1–2–3–4–5–6–7–(8)
0-1-2-3-4-5-6-7-8-9-0-1-(12)

and if you have a circle circumference from 0 to 2pi and divide it into
360 parts then they are labeled 0/360*2pi, 1/360*2pi, 2/360*2pi,
3/360*2pi, …, 357/360*2pi, 358/360*2pi, 359/360*2pi.
but 359 is not the maximum, it is 360, the last step is back to
360/360*2pi or 0/360*2pi. if you divide by 359 or 255 then the last
distance (to close the circle has a wrong value).
marius.

Klaas-Jan Govaart wrote:
> Quote: marius.schebella wrote on Tue, 19 February 2008 21:46
> —————————————————-
>> maybe this is a theoretical question, but I think you have to use
>> zmap 0 256 0 360
>
> Hi Marius,
>
> I think you have to divide/multiply by the maximum value in the new range.
>
> Or when using zmap: old minimum to new minimum and old maximum to new maximum.
>
> Anybody please correct me if I’m wrong.
>
> Regards,
> kjg
>
>
> This is my take at it:
>
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 202 246 43 196617 % 360.;
> #P comment 134 541 67 196617 or use floats;
> #P newex 131 246 29 196617 t b f;
> #P comment 317 192 149 196617 offset in degrees (-360 – 360);
> #P comment 342 209 20 196617 ==;
> #P message 85 46 26 196617 513;
> #P message 35 24 14 196617 0;
> #P message 52 40 26 196617 256;
> #P comment 244 248 221 196617 no negative values for modulo..;
> #P number 360 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 307 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P user hslider 162 207 18 128 721 1 -360 0;
> #P newex 162 246 40 196617 + 360.;
> #P newex 232 184 72 196617 loadmess 390;
> #P comment 218 398 242 196617 multiply by maximum value in new range (0-255);
> #P flonum 54 541 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 143 416 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 49 416 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont "Sans Serif" 10.;
> #P newex 54 514 272 196618 expr ($i1 /255. * 359. + $f2) %360. /359. *255.;
> #P window setfont "Sans Serif" 9.;
> #P number 8 517 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 116 88 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 79 88 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P window setfont "Sans Serif" 10.;
> #P newex 8 492 326 196618 expr int(($i1 /255. * 359. + $f2) %360. /359. *255. +0.5);
> #P window setfont "Sans Serif" 9.;
> #P newex 129 434 34 196617 + 0.5;
> #P newex 35 434 34 196617 + 0.5;
> #P comment 212 457 217 196617 round and convert back to ints;
> #P number 129 470 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P number 35 470 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 129 452 27 196617 i;
> #P newex 35 452 27 196617 i;
> #P comment 212 340 141 196617 divide by the maximum value;
> #P newex 129 395 41 196617 * 255.;
> #P newex 35 395 84 196617 zmap 0 1 0 255.;
> #P comment 212 360 131 196617 range of 256 values (0-1.);
> #P flonum 143 359 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 129 337 40 196617 / 359.;
> #P flonum 49 359 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 35 337 84 196617 zmap 0 359 0 1.;
> #P comment 212 91 289 196617 % to make 256 wrap back to 0 – range of 256 values (0-255);
> #P newex 35 86 40 196617 % 256;
> #P flonum 143 295 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 49 295 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P comment 212 272 221 196617 modulo to make 360 wrap back to 0 (or offset);
> #P newex 35 272 43 196617 % 360.;
> #P newex 129 272 43 196617 % 360.;
> #P comment 171 230 149 196617 offset in degrees (-360 – 360);
> #P newex 35 207 27 196617 + 0.;
> #P newex 129 207 27 196617 + 0.;
> #P comment 212 163 242 196617 multiply by maximum value in new range (0-359);
> #P flonum 143 184 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P flonum 49 184 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 129 161 41 196617 * 359.;
> #P newex 35 161 87 196617 zmap 0 1. 0 359.;
> #P comment 212 135 131 196617 range of 256 values (0-1.);
> #P comment 212 114 277 196617 divide by the maximum value (not by the number of values);
> #P flonum 143 134 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 129 112 40 196617 / 255.;
> #P flonum 49 134 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
> #P newex 35 112 84 196617 zmap 0 255 0 1.;
> #P user hslider 35 64 18 128 513 1 0 0;
> #P comment 212 69 138 196617 range of 513 values (0-512);
> #P comment 57 23 193 196617 value number 0 256 or 513 (0 , 0 and 0);
> #P connect 59 0 39 0;
> #P fasten 2 0 39 0 40 84 13 84;
> #P connect 39 0 42 0;
> #P connect 56 0 2 0;
> #P connect 55 0 2 0;
> #P connect 54 0 2 0;
> #P connect 2 0 22 0;
> #P connect 22 0 3 0;
> #P connect 3 0 9 0;
> #P connect 59 0 15 0;
> #P connect 9 0 15 0;
> #P connect 15 0 18 0;
> #P connect 18 0 24 0;
> #P connect 24 0 29 0;
> #P connect 29 0 37 0;
> #P connect 37 0 32 0;
> #P connect 32 0 34 0;
> #P connect 3 0 4 0;
> #P connect 9 0 11 0;
> #P connect 18 0 20 0;
> #P connect 24 0 25 0;
> #P connect 29 0 44 0;
> #P connect 59 1 15 1;
> #P connect 59 0 43 0;
> #P fasten 2 0 43 0 40 84 22 84 22 434 59 434;
> #P connect 43 0 46 0;
> #P connect 2 0 40 0;
> #P connect 22 0 41 0;
> #P connect 22 0 5 0;
> #P connect 5 0 10 0;
> #P connect 59 0 14 0;
> #P connect 10 0 14 0;
> #P connect 14 0 17 0;
> #P connect 17 0 26 0;
> #P connect 26 0 30 0;
> #P connect 30 0 38 0;
> #P connect 38 0 33 0;
> #P connect 33 0 35 0;
> #P connect 49 0 59 0;
> #P connect 5 0 6 0;
> #P connect 10 0 12 0;
> #P connect 17 0 21 0;
> #P connect 26 0 27 0;
> #P connect 30 0 45 0;
> #P connect 59 1 14 1;
> #P connect 48 0 50 0;
> #P connect 50 0 49 0;
> #P hidden connect 49 0 61 0;
> #P hidden connect 50 0 51 0;
> #P connect 59 1 43 1;
> #P connect 59 1 39 1;
> #P hidden connect 61 0 52 0;
>
>
>



kjg
February 20, 2008 | 3:12 am

Quote: marius.schebella wrote on Wed, 20 February 2008 02:23
—————————————————-
> as I said before, it is only a very small differenced, but the maximum
> values are 360 and 256.
> in a distance from 0 to 1 your highest integer number is 0, in a
> distance from 0 to 2, it is 1…
>
> 0———————–(1)
> 0———–1———–(2)
> 0——-1——-2——-(3)
> 0—–1—–2—–3—–(4)
> 0—1—2—3—4—5—(6)
> 0–1–2–3–4–5–6–7–(8)
> 0-1-2-3-4-5-6-7-8-9-0-1-(12)
>
> and if you have a circle circumference from 0 to 2pi and divide it into
> 360 parts then they are labeled 0/360*2pi, 1/360*2pi, 2/360*2pi,
> 3/360*2pi, …, 357/360*2pi, 358/360*2pi, 359/360*2pi.
> but 359 is not the maximum, it is 360, the last step is back to
> 360/360*2pi or 0/360*2pi. if you divide by 359 or 255 then the last
> distance (to close the circle has a wrong value).
> marius.
>

Marius you convinced me. The light went on… :)
Just to make sure I don’t get confused again, do you agree with this general "formula" for scaling to a new range?

multiply by num_steps_new/num_steps_old

or, in this case:
0-255 * (360/256) > add offset > * (256/360) > 0-255

Thank you for the lesson! I’ve been confused about this, thanks for clearing it up.
Klaas-Jan

+ updated patch:

#P window setfont "Sans Serif" 9.;
#P message 85 37 26 196617 513;
#P message 35 15 14 196617 0;
#P message 52 31 26 196617 256;
#P user hslider 35 55 18 128 513 1 0 0;
#P flonum 84 208 69 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P hidden newex 475 150 72 196617 loadmess 390;
#P hidden newex 515 215 43 196617 % 360.;
#P hidden newex 444 215 29 196617 t b f;
#P comment 655 178 20 196617 ==;
#P hidden comment 557 217 150 196617 no negative values for modulo..;
#P number 673 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 620 178 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P user hslider 475 176 18 128 721 1 -360 0;
#P hidden newex 475 215 40 196617 + 360.;
#P comment 484 199 149 196617 offset in degrees (-360 – 360);
#P newex 303 208 40 196617 % 360;
#P newex 184 208 40 196617 % 360;
#P newex 35 208 40 196617 % 360;
#P newex 303 187 34 196617 + 30.;
#P newex 184 187 34 196617 + 30.;
#P newex 35 187 34 196617 + 30.;
#P window linecount 2;
#P comment 339 280 72 196617 numstepsnew/numstepsold;
#P comment 339 137 72 196617 numstepsnew/numstepsold;
#P comment 105 259 72 196617 numstepsnew/numstepsold;
#P number 303 383 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 303 360 34 196617 + 0.5;
#P number 184 383 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 184 360 34 196617 + 0.5;
#P number 35 383 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 360 34 196617 + 0.5;
#P flonum 303 313 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 401 96 26 196617 256;
#P message 352 96 26 196617 360;
#P message 401 237 26 196617 360;
#P message 352 237 26 196617 256;
#P newex 303 261 108 196617 expr $i1 * ($f2/$f3);
#P newex 303 118 108 196617 expr $i1 * ($f2/$f3);
#P hidden newex 500 65 48 196617 loadbang;
#P flonum 184 313 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 184 261 99 196617 zmap 0 360. 0 256.;
#P newex 184 118 96 196617 zmap 0 512 0 720.;
#P flonum 35 313 64 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 35 289 29 196617 * 1.;
#P message 54 239 26 196617 256;
#P message 71 255 26 196617 360;
#P newex 54 271 27 196617 / 1.;
#P newex 35 162 29 196617 * 1.;
#P message 54 112 26 196617 360;
#P message 71 128 26 196617 256;
#P newex 54 144 27 196617 / 1.;
#P number 35 78 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 2;
#P comment 105 121 72 196617 numstepsnew/numstepsold;
#P window linecount 1;
#P comment 360 41 392 196617 int range 0-255 converted to float range 0-359 , offset added , and converted back;
#P connect 50 0 49 0;
#P connect 51 0 49 0;
#P connect 52 0 49 0;
#P connect 49 0 2 0;
#P connect 2 0 6 0;
#P hidden connect 45 0 32 0;
#P connect 6 0 32 0;
#P connect 32 0 35 0;
#P connect 35 0 10 0;
#P connect 10 0 11 0;
#P connect 11 0 23 0;
#P connect 23 0 24 0;
#P hidden connect 15 0 5 0;
#P connect 5 0 3 0;
#P connect 3 0 6 1;
#P hidden connect 15 0 9 0;
#P connect 9 0 7 0;
#P connect 7 0 10 1;
#P hidden connect 45 1 32 1;
#P hidden connect 15 0 4 0;
#P connect 4 0 3 1;
#P hidden connect 15 0 8 0;
#P connect 8 0 7 1;
#P connect 6 0 48 0;
#P connect 2 0 12 0;
#P connect 12 0 33 0;
#P hidden connect 45 0 33 0;
#P connect 33 0 36 0;
#P connect 36 0 13 0;
#P connect 13 0 14 0;
#P connect 14 0 25 0;
#P connect 25 0 26 0;
#P hidden connect 45 1 33 1;
#P connect 2 0 16 0;
#P hidden connect 45 0 34 0;
#P connect 16 0 34 0;
#P connect 34 0 37 0;
#P connect 37 0 17 0;
#P connect 17 0 22 0;
#P connect 22 0 27 0;
#P connect 27 0 28 0;
#P hidden connect 45 1 34 1;
#P hidden connect 15 0 20 0;
#P connect 20 0 16 1;
#P hidden connect 15 0 18 0;
#P connect 18 0 17 1;
#P hidden connect 15 0 21 0;
#P connect 21 0 16 2;
#P hidden connect 15 0 19 0;
#P connect 19 0 17 2;
#P hidden connect 39 0 45 0;
#P hidden connect 47 0 40 0;
#P hidden connect 40 0 39 0;
#P hidden connect 39 0 46 0;
#P hidden connect 40 0 41 0;
#P hidden connect 46 0 42 0;


Viewing 12 posts - 1 through 12 (of 12 total)