Page 1 of 2

Gradient fill in a canvas

Posted: 13 Mar 2014 09:41
by wul
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.

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 10:06
by Macciza
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

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 11:01
by Macciza
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 . . .

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 11:01
by nick_liine
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.

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 11:07
by Macciza
** SNAP ** Perfect timing . . .

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 11:21
by wul
It was the decl grad line in the code that's causing the editor to crash,

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 11:31
by Macciza
PC issue? Cant recall what you run . ..

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 12:47
by Softcore
The tutorials package will be most welcome! Im struggling myself here too! lol

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 13:50
by wul
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 ?

Re: Gradient fill in a canvas

Posted: 13 Mar 2014 14:06
by oldgearguy
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: