Gradient fill in a canvas

Discuss Lemur and share techniques.
wul
Regular
Posts:181
Joined:10 Apr 2012 13:25
Gradient fill in a canvas

Post by wul » 13 Mar 2014 09:41

How do you script a gradient fill in canvas ? If i do it like an on line html5 example . The editor crashes yet again .
The addendum needs some scripting examples for each function, similar to the main manual.

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: Gradient fill in a canvas

Post by Macciza » 13 Mar 2014 10:06

Hi
I don't think you apply it to the canvas itself as such . .
I think you have to create the Gradient and add Colors first . ..
Then you would make an object (rectangle) and Fill or Stroke it with your Gradient ...
Did some quick LED experiments and got it worked out
Will see about what I just described and get back to you . . .
MM
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: Gradient fill in a canvas

Post by Macciza » 13 Mar 2014 11:01

Hi
Try this as a draw() function - OnRedraw . . .

decl c = getobject();
decl rect = getattribute(c, 'rect');//get Canvas size

canvas_clear(c);//

decl grad = canvas_createLinearGradient(0,rect[3]/2,rect[2],rect[3]/2);//Make Gradient horizontal&middle via Canvas size
canvas_gradient_addColorStop(grad,0,{1,0,0});
canvas_gradient_addColorStop(grad,1,{0,1,0}); Add Color stops

canvas_setFillStyle(c, grad);
canvas_setStrokeStyle(c, 1);
canvas_setLineWidth(c, 1);

canvas_rect(c,0,0, rect[2],rect[3]);//Make Rect Canvas size

canvas_fill(c);
canvas_stroke(c);

Its one way to do it . . . .
Cheers
MM
PS I'm on Mac . . .
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

nick_liine
Liine Staff
Posts:340
Joined:01 Oct 2010 11:06

Re: Gradient fill in a canvas

Post by nick_liine » 13 Mar 2014 11:01

wul wrote:How do you script a gradient fill in canvas ? If i do it like an on line html5 example . The editor crashes yet again .
The addendum needs some scripting examples for each function, similar to the main manual.
Yes, there is a package of tutorial JZMLs for Canvas coming very soon. In the meantime, I've attached the example for using gradients.
Attachments
gradient_examples.zip
(3.08KiB)Downloaded 99 times

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: Gradient fill in a canvas

Post by Macciza » 13 Mar 2014 11:07

** SNAP ** Perfect timing . . .
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

wul
Regular
Posts:181
Joined:10 Apr 2012 13:25

Re: Gradient fill in a canvas

Post by wul » 13 Mar 2014 11:21

It was the decl grad line in the code that's causing the editor to crash,

Macciza
Regular
Posts:1325
Joined:07 Dec 2011 04:57
Location:Sydney, Australia.

Re: Gradient fill in a canvas

Post by Macciza » 13 Mar 2014 11:31

PC issue? Cant recall what you run . ..
iMac 2.8G i7 12G 10.6.8/10.7.2, Legacy Dexter/Lemur, Liine Lemur/iPad2, KMI SoftStep, 12Step & QuNeo , B-Controls, Mackie C4 etc
MaxMSP, Live Suite, Native Instrument stuff, etc Modified Virtual Guitar System etc All Projects/Modules © CC-BY-NC-SA[*][/b]

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

Re: Gradient fill in a canvas

Post by Softcore » 13 Mar 2014 12:47

The tutorials package will be most welcome! Im struggling myself here too! lol

wul
Regular
Posts:181
Joined:10 Apr 2012 13:25

Re: Gradient fill in a canvas

Post by wul » 13 Mar 2014 13:50

both macciza's example and nicks .jzmlib's crash the editor on windows xp
it appears to be the decl grad line thats the problem, macciza's crashes when compiling/verifying the script . the jzmlibs crash on launch

incidentlty there is a online html5 image to code editor here http://canvimation.github.io/ the code generated needs a bit of converting to suit lemur but it gives a bit of a clue as to the structure

so no authentic looking knobs, panels, or vu meters from me for the time being!

anyone else getting the distorted text issue in the editor ?

oldgearguy
Regular
Posts:315
Joined:02 Nov 2013 11:19

Re: Gradient fill in a canvas

Post by oldgearguy » 13 Mar 2014 14:06

wul wrote:both macciza's example and nicks .jzmlib's crash the editor on windows xp
it appears to be the decl grad line thats the problem, macciza's crashes when compiling/verifying the script . the jzmlibs crash on launch

incidentlty there is a online html5 image to code editor here http://canvimation.github.io/ the code generated needs a bit of converting to suit lemur but it gives a bit of a clue as to the structure

so no authentic looking knobs, panels, or vu meters from me for the time being!

anyone else getting the distorted text issue in the editor ?

I'm getting the distorted text in Windows as well (Vista on the family PC). I haven't installed 5.0 on my music Mac yet to test it there. Since I've mainly been editing existing .jzml files outside Lemur and simply using the editor for small touchups, I can work with the distorted text. Long-term, obviously that needs to be addressed. Maybe anti-aliasing is turned off for the text editor? :lol:

Post Reply