Seeking comments regarding canvas syntax

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Seeking comments regarding canvas syntax

Post by Ref »

************************* WARNING! Content may offend some forum users! *****************************
********************* Users who are 'canvas challenged' need read no further. **************************
I have found the syntax used to deal with canvases somewhat clunky and have come up with a slightly different one.
Was wonder if this might be of interest for future releases of Love.
Currently:

Code: Select all

canvas = love.graphics.newCanvas( width, height )
   love.graphics.setCanvas( canvas )
      love.graphics.draw( image )
      love.graphics.setColor( { 255,  0,  0, 255 } )
         love.graphics.circle( 'line', 45, 45, 20 )
      love.graphics.setColor( { 255, 255, 255, 255 } )
         love.graphics.setFont( gr.newFont( 16 ) )
         love.graphics.print( 'message', 5, 75 )
         love.graphics.rectangle( 'fill', 35, 35, 20, 20 )
      love.graphics.setColor(  {0,  0,  0, 255} )
         love.graphics.print( '2', 40, 35 )
      love.graphics.setCanvas()
if love.draw()

Code: Select all

love.graphics.draw( canvas, 100,100, angle,1,1,45,45 )
Proposed:

Code: Select all

can3 = newCanvas( image )
   can3:Color( 255,  0,  0, 255 )
      can3:circle( 'line', 45, 45, 20 )
   can3:Color( 255, 255, 255, 255 )
      can3:fontsize( 16 )
      can3:text( 'message', 5, 75 )
      can3:box( 'fill', 35, 35, 20, 20 )
   can3:Color(   0,   0,   0, 255 )
      can3:text( '2', 40, 35 )
and in love.draw()

Code: Select all

can3:draw( 100, 100, angle, 1, 1, can3.canvas:getWidth()/2, can3.canvas:getHeight()/2)
Everything is changed behind the scene by requiring the library containing the modifications.
I just find it easier to read code later especially when I didn't use 'canvas' for a name but something more descriptive.
No speed advantage (or penalty) and could be extended to use fake canvases.
Of any merit or better to leave well enough alone?
Your opinion?

Edit: Canvas.lua library updated with more love.graphics features.
Canvas:line() now permits any number of line segments to be handled in one call. Points can be individually listed or put in a table and Canvas:trianglestrip() added.
Other Canvas functions now pass all the usual love.graphics settings straight through.
Last edited by Ref on Sun Oct 28, 2012 4:53 pm, edited 3 times in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Seeking comments regarding canvas syntax

Post by Nixola »

What about making available both?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Seeking comments regarding canvas syntax

Post by Ref »

Suppose I could just stick with using my library but thought that for someone just starting out, a simpler default syntax might be helpful.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Seeking comments regarding canvas syntax

Post by T-Bone »

I always use the renderTo function. I find it much easier to use, and the syntax often becomes cleaner, because you can make predefined render functions and just pass them to to renderTo which is nice. And I wouldn't want any syntax to stray too far away from the normal love.draw syntax, that's what we all know and love.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Seeking comments regarding canvas syntax

Post by Ref »

I guess the thing I like most is that an action is always associated with an object:
ball:Color()
ball:line()
ball:circle()
ball:trianglestrip() -- added feature
ball:draw()
User avatar
paritybit
Citizen
Posts: 53
Joined: Thu Sep 06, 2012 3:52 am

Re: Seeking comments regarding canvas syntax

Post by paritybit »

I tend to like object-oriented syntax and feel, but in this case there's something positive to be said for being able to draw to a canvas just like you draw to the screen.
User avatar
rokit boy
Party member
Posts: 198
Joined: Wed Jan 18, 2012 7:40 pm

Re: Seeking comments regarding canvas syntax

Post by rokit boy »

can someone add fake canvas? because i dont support them.
u wot m8
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Seeking comments regarding canvas syntax

Post by Roland_Yonaba »

rokit boy wrote:can someone add fake canvas? because i dont support them.
Thanks Xgoff!
User avatar
qaisjp
Party member
Posts: 490
Joined: Tue Sep 04, 2012 10:49 am
Location: United Kingdom
Contact:

Re: Seeking comments regarding canvas syntax

Post by qaisjp »

it looks pretty neat, actually.

instead of object:drawc how about object:draw?
Lua is not an acronym.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Seeking comments regarding canvas syntax

Post by Ref »

qaisjp wrote:it looks pretty neat, actually.

instead of object:drawc how about object:draw?
Done!
Replaced drawi and drawc with a single draw.
Will post after further testing (and if anyone is really interested.)
Thanks for the suggestion!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Semrush [Bot] and 58 guests