General

Gradient fill in a canvas

Started by wul on .

Sign in or create an account to join the conversation.

17 posts

Topic starter
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.
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
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 . . .
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.

gradient_examples.zip
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 ?
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:
Hi
Somewhat related as 'g' is the Gradient being defined in the other line . . .
Important to send details to Support including OS / Version etc

Sorry, but no dramas noticed on OSX so far . . .
Been gradually hacking away at HexaPads
Got 4 versions so far with rotated Hex, Diamond and Circle variants . . .
Draft versions of LEDs underway as well
And scouring the net for suitable Canvas tuts and resources

MM