Page 1 of 1

Switches With canvas

Posted: 02 Sep 2014 17:01
by nitefish
How to make a simple Switch with canvas?
0 is black,1 is white.
I tried to find something with onCursorDown but...

Re: Switches With canvas

Posted: 03 Sep 2014 18:02
by Softcore
Example coming soon-ish

Re: Switches With canvas

Posted: 03 Sep 2014 19:39
by nitefish
Yeah-ish! :D

Pretty sure that the solution is under my eyes...

Re: Switches With canvas

Posted: 05 Sep 2014 06:53
by Softcore
Sorry for being late-ish...lol

Here you are...colors are provided via custom expressions so you can easily change them - the expression "out" is what you need to "map" to midi or OSC out

Re: Switches With canvas

Posted: 05 Sep 2014 10:10
by nitefish
Nice example,thank you!
I never saw and I don't understand this:

canvas_setFillStyle(c,out?oncolor:offcolor);

"?" ":" ???? :geek:

Re: Switches With canvas

Posted: 05 Sep 2014 11:13
by Softcore
if a then b else c ----> a?b:c (Lemur manual, page 136)

if out is NOT 0 then if(out) returns true - if out=0, then if(out) returns false

so, instead of typing

Code: Select all

if (out==1) canvas_setFillStyle(c,oncolor); 
else canvas_setFillStyle(c,offcolor); 
we type

Code: Select all

canvas_setFillStyle(c,out?oncolor:offcolor); 

Re: Switches With canvas

Posted: 05 Sep 2014 11:53
by Joe Soap
As Softcore says, it's in the manual - but the manual doesn't really explain it very well - nowhere near as well as Softcore does himself.

Further reading:

https://en.wikipedia.org/wiki/%3F:

^ You'll have to copy / paste the entirety of the URL as the forum software is mangling the bloody thing - that colon on the end . . . is part of the URL.