[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.programming

javascript fillrect vs beginpath - why is that so?

kenobi

11/29/2015 1:28:00 PM

afail in js/canvas there is no call to fillrect, fillcircle etc method but instead something like

ctx.beginPath();
ctx.rect(brickX, brickY, brickWidth, brickHeight);
ctx.fillStyle = "#0095DD";
ctx.fill();
ctx.closePath();

is used... it seems overal a bit weird decision.. dont you think so? (or maybe not?) at least it wonders me a bit, Why is that so - is there some rationale under it?
4 Answers

LudovicoVan

11/29/2015 8:34:00 PM

0

On Sunday, November 29, 2015 at 1:28:02 PM UTC, fir wrote:
> afail in js/canvas there is no call to fillrect, fillcircle etc method but instead something like
>
> ctx.beginPath();
> ctx.rect(brickX, brickY, brickWidth, brickHeight);
> ctx.fillStyle = "#0095DD";
> ctx.fill();
> ctx.closePath();
>
> is used... it seems overal a bit weird decision.. dont you think so? (or maybe not?) at least it wonders me a bit, Why is that so - is there some rationale under it?

Generally, under HTML5 styles follow the CSS model.

Julio

kenobi

12/3/2015 3:20:00 PM

0

W dniu niedziela, 29 listopada 2015 21:34:11 UTC+1 uzytkownik Julio Di Egidio napisal:
> On Sunday, November 29, 2015 at 1:28:02 PM UTC, fir wrote:
> > afail in js/canvas there is no call to fillrect, fillcircle etc method but instead something like
> >
> > ctx.beginPath();
> > ctx.rect(brickX, brickY, brickWidth, brickHeight);
> > ctx.fillStyle = "#0095DD";
> > ctx.fill();
> > ctx.closePath();
> >
> > is used... it seems overal a bit weird decision.. dont you think so? (or maybe not?) at least it wonders me a bit, Why is that so - is there some rationale under it?
>
> Generally, under HTML5 styles follow the CSS model.
>
> Julio

I see i was wrong there is simple firlect in canvas too (i thought its absent and that seemd strange/interesting to me)

Öö Tiib

12/6/2015 4:08:00 PM

0

On Thursday, 3 December 2015 17:20:32 UTC+2, fir wrote:
> W dniu niedziela, 29 listopada 2015 21:34:11 UTC+1 uzytkownik Julio Di Egidio napisal:
> > On Sunday, November 29, 2015 at 1:28:02 PM UTC, fir wrote:
> > > afail in js/canvas there is no call to fillrect, fillcircle etc method but instead something like
> > >
> > > ctx.beginPath();
> > > ctx.rect(brickX, brickY, brickWidth, brickHeight);
> > > ctx.fillStyle = "#0095DD";
> > > ctx.fill();
> > > ctx.closePath();
> > >
> > > is used... it seems overal a bit weird decision.. dont you think so? (or maybe not?) at least it wonders me a bit, Why is that so - is there some rationale under it?
> >
> > Generally, under HTML5 styles follow the CSS model.
> >
> > Julio
>
> I see i was wrong there is simple firlect in canvas too (i thought its absent and that seemd strange/interesting to me)

Perhaps 'ctx.fill' is meant for filling more complex shape than 'ctx.rect'
(or for filling several shapes at once). If you need to fill just single
rect then 'ctx.fillrect' is indeed more rational to use.

Bartc

12/7/2015 2:20:00 PM

0

On 29/11/2015 13:27, fir wrote:
> afail in js/canvas there is no call to fillrect, fillcircle etc method but instead something like
>
> ctx.beginPath();
> ctx.rect(brickX, brickY, brickWidth, brickHeight);
> ctx.fillStyle = "#0095DD";
> ctx.fill();
> ctx.closePath();
>
> is used... it seems overal a bit weird decision.. dont you think so? (or maybe not?) at least it wonders me a bit, Why is that so - is there some rationale under it?

Why? It seems they decided to use a consistent approach to area fill:
define an outline path first, then apply fill. Because in general, areas
to be filled can be arbitrarily complex (maybe the rectangle is a hole
within a bigger shape, or is an island within a hole).

There's nothing to stop you creating your own dedicated rectangle fill
routine based around the above.

(Your sequence above doesn't seem quite right: you're filling the shape
/then/ closing the path!)

--
Bartc