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 »

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: 1613
Joined: 04 Nov 2012 08:34

Re: Switches With canvas

Post by Softcore »

Example coming soon-ish
nitefish
Regular
Posts: 56
Joined: 24 Aug 2012 07:43

Re: Switches With canvas

Post by nitefish »

Yeah-ish! :D

Pretty sure that the solution is under my eyes...
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Switches With canvas

Post 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
Attachments
CanvasSwitch.jzml
(2.67 KiB) Downloaded 64 times
nitefish
Regular
Posts: 56
Joined: 24 Aug 2012 07:43

Re: Switches With canvas

Post by nitefish »

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

canvas_setFillStyle(c,out?oncolor:offcolor);

"?" ":" ???? :geek:
Softcore
Regular
Posts: 1613
Joined: 04 Nov 2012 08:34

Re: Switches With canvas

Post 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); 
Joe Soap
Regular
Posts: 462
Joined: 07 Jul 2012 15:04

Re: Switches With canvas

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