Switches With canvas

Discuss Lemur and share techniques.
Post Reply
nitefish
Regular
Posts:56
Joined:24 Aug 2012 07:43
Switches With canvas

Post by nitefish » 02 Sep 2014 17:01

How to make a simple Switch with canvas?
0 is black,1 is white.
I tried to find something with onCursorDown but...

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: Switches With canvas

Post by Softcore » 03 Sep 2014 18:02

Example coming soon-ish

nitefish
Regular
Posts:56
Joined:24 Aug 2012 07:43

Re: Switches With canvas

Post by nitefish » 03 Sep 2014 19:39

Yeah-ish! :D

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

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: Switches With canvas

Post by Softcore » 05 Sep 2014 06:53

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
Attachments
CanvasSwitch.jzml
(2.67KiB)Downloaded 70 times

nitefish
Regular
Posts:56
Joined:24 Aug 2012 07:43

Re: Switches With canvas

Post by nitefish » 05 Sep 2014 10:10

Nice example,thank you!
I never saw and I don't understand this:

canvas_setFillStyle(c,out?oncolor:offcolor);

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

Softcore
Regular
Posts:1639
Joined:04 Nov 2012 08:34

Re: Switches With canvas

Post by Softcore » 05 Sep 2014 11:13

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

Joe Soap
Regular
Posts:475
Joined:07 Jul 2012 15:04

Re: Switches With canvas

Post by Joe Soap » 05 Sep 2014 11:53

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.

Post Reply