Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #38621 > unrolled thread

Canvas filled circles

Started byJonas Thörnvall <jonas.thornvall@gmail.com>
First post2020-07-30 15:41 -0700
Last post2020-07-31 12:30 -0700
Articles 9 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Canvas filled circles Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-30 15:41 -0700
    Re: Canvas filled circles luserdroog <luser.droog@gmail.com> - 2020-07-31 01:19 -0700
      Re: Canvas filled circles Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-31 03:13 -0700
        Re: Canvas filled circles Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-31 03:38 -0700
        Re: Canvas filled circles luserdroog <luser.droog@gmail.com> - 2020-07-31 10:44 -0700
          Re: Canvas filled circles Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-31 11:06 -0700
          Re: Canvas filled circles luserdroog <luser.droog@gmail.com> - 2020-07-31 11:56 -0700
    Re: Canvas filled circles "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2020-07-31 11:49 -0700
      Re: Canvas filled circles Jonas Thörnvall <jonas.thornvall@gmail.com> - 2020-07-31 12:30 -0700

#38621 — Canvas filled circles

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-30 15:41 -0700
SubjectCanvas filled circles
Message-ID<2d67a118-b5a6-4e51-a40d-98926523bcb6o@googlegroups.com>
When i draw 2 filled circles.
ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
ctm.fill();

And then draw two more to the right there is two triangles between them formed xshaped/butterfly?

Why?

[toc] | [next] | [standalone]


#38622

Fromluserdroog <luser.droog@gmail.com>
Date2020-07-31 01:19 -0700
Message-ID<05c7781a-872f-4257-af74-5df9b0353445o@googlegroups.com>
In reply to#38621
On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> When i draw 2 filled circles.
> ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> ctm.fill();
> 
> And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> 
> Why?

I've seen this in PostScript drawing. It can happen when arc has a subtly
different behavior depending upon whether there's a current point in the
path. If there's no current point, arc will start with a MoveTo element.
But if there is a current point, arc will start with a LineTo element.

The workaround is to call fill() or whatever your drawing operation is
after each shape. Filling will implicitly clear the path.

[toc] | [prev] | [next] | [standalone]


#38623

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-31 03:13 -0700
Message-ID<e93aaa27-353f-43a8-a233-82f623f5ef4fo@googlegroups.com>
In reply to#38622
Den fredag 31 juli 2020 kl. 10:19:30 UTC+2 skrev luserdroog:
> On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > When i draw 2 filled circles.
> > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > ctm.fill();
> > 
> > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > 
> > Why?
> 
> I've seen this in PostScript drawing. It can happen when arc has a subtly
> different behavior depending upon whether there's a current point in the
> path. If there's no current point, arc will start with a MoveTo element.
> But if there is a current point, arc will start with a LineTo element.
> 
> The workaround is to call fill() or whatever your drawing operation is
> after each shape. Filling will implicitly clear the path.

Well i added fill after every ARC, and there is just two so that is not it?
I basicly have just three drawn elements rectangles, arcs and from Unicode charset.

And 2*Math.PI is the correct full circle, it is not somehow open at end?

[toc] | [prev] | [next] | [standalone]


#38624

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-31 03:38 -0700
Message-ID<6fa19be8-b5ad-4e52-8e73-fc3fbefcd9d1o@googlegroups.com>
In reply to#38623
Den fredag 31 juli 2020 kl. 12:13:42 UTC+2 skrev Jonas Thörnvall:
> Den fredag 31 juli 2020 kl. 10:19:30 UTC+2 skrev luserdroog:
> > On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > > When i draw 2 filled circles.
> > > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > > ctm.fill();
> > > 
> > > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > > 
> > > Why?
> > 
> > I've seen this in PostScript drawing. It can happen when arc has a subtly
> > different behavior depending upon whether there's a current point in the
> > path. If there's no current point, arc will start with a MoveTo element.
> > But if there is a current point, arc will start with a LineTo element.
> > 
> > The workaround is to call fill() or whatever your drawing operation is
> > after each shape. Filling will implicitly clear the path.
> 
> Well i added fill after every ARC, and there is just two so that is not it?
> I basicly have just three drawn elements rectangles, arcs and from Unicode charset.
> 
> And 2*Math.PI is the correct full circle, it is not somehow open at end?

Well the logic isn't quite there yet but i am working on it "creating a possible moves array", but the drawing problem anyone understand what goes wrong?

https://jonasth.github.io/chess/chess.html

[toc] | [prev] | [next] | [standalone]


#38625

Fromluserdroog <luser.droog@gmail.com>
Date2020-07-31 10:44 -0700
Message-ID<8e598e5b-93c1-468b-94ec-17f9566ad050o@googlegroups.com>
In reply to#38623
On Friday, July 31, 2020 at 5:13:42 AM UTC-5, Jonas Thörnvall wrote:
> Den fredag 31 juli 2020 kl. 10:19:30 UTC+2 skrev luserdroog:
> > On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > > When i draw 2 filled circles.
> > > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > > ctm.fill();
> > > 
> > > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > > 
> > > Why?
> > 
> > I've seen this in PostScript drawing. It can happen when arc has a subtly
> > different behavior depending upon whether there's a current point in the
> > path. If there's no current point, arc will start with a MoveTo element.
> > But if there is a current point, arc will start with a LineTo element.
> > 
> > The workaround is to call fill() or whatever your drawing operation is
> > after each shape. Filling will implicitly clear the path.
> 
> Well i added fill after every ARC, and there is just two so that is not it?
> I basicly have just three drawn elements rectangles, arcs and from Unicode charset.
> 
> And 2*Math.PI is the correct full circle, it is not somehow open at end?

No, fill should automatically close the path first. It has to. Hmm.

[toc] | [prev] | [next] | [standalone]


#38626

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-31 11:06 -0700
Message-ID<dd8ebd11-c145-485b-9f18-53b41809821fo@googlegroups.com>
In reply to#38625
Den fredag 31 juli 2020 kl. 19:44:39 UTC+2 skrev luserdroog:
> On Friday, July 31, 2020 at 5:13:42 AM UTC-5, Jonas Thörnvall wrote:
> > Den fredag 31 juli 2020 kl. 10:19:30 UTC+2 skrev luserdroog:
> > > On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > > > When i draw 2 filled circles.
> > > > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > > > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > > > ctm.fill();
> > > > 
> > > > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > > > 
> > > > Why?
> > > 
> > > I've seen this in PostScript drawing. It can happen when arc has a subtly
> > > different behavior depending upon whether there's a current point in the
> > > path. If there's no current point, arc will start with a MoveTo element.
> > > But if there is a current point, arc will start with a LineTo element.
> > > 
> > > The workaround is to call fill() or whatever your drawing operation is
> > > after each shape. Filling will implicitly clear the path.
> > 
> > Well i added fill after every ARC, and there is just two so that is not it?
> > I basicly have just three drawn elements rectangles, arcs and from Unicode charset.
> > 
> > And 2*Math.PI is the correct full circle, it is not somehow open at end?
> 
> No, fill should automatically close the path first. It has to. Hmm.

Of course when you select a new piece to move, the possible move from the other pawn should be overwritten, but i am not sure that help i do not understand what creat those lines/areas.

[toc] | [prev] | [next] | [standalone]


#38628

Fromluserdroog <luser.droog@gmail.com>
Date2020-07-31 11:56 -0700
Message-ID<06b7ff89-4ab4-44fc-a3c7-c393ae741576o@googlegroups.com>
In reply to#38625
On Friday, July 31, 2020 at 12:44:39 PM UTC-5, luserdroog wrote:
> On Friday, July 31, 2020 at 5:13:42 AM UTC-5, Jonas Thörnvall wrote:
> > Den fredag 31 juli 2020 kl. 10:19:30 UTC+2 skrev luserdroog:
> > > On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > > > When i draw 2 filled circles.
> > > > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > > > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > > > ctm.fill();
> > > > 
> > > > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > > > 
> > > > Why?
> > > 
> > > I've seen this in PostScript drawing. It can happen when arc has a subtly
> > > different behavior depending upon whether there's a current point in the
> > > path. If there's no current point, arc will start with a MoveTo element.
> > > But if there is a current point, arc will start with a LineTo element.
> > > 
> > > The workaround is to call fill() or whatever your drawing operation is
> > > after each shape. Filling will implicitly clear the path.
> > 
> > Well i added fill after every ARC, and there is just two so that is not it?
> > I basicly have just three drawn elements rectangles, arcs and from Unicode charset.
> > 
> > And 2*Math.PI is the correct full circle, it is not somehow open at end?
> 
> No, fill should automatically close the path first. It has to. Hmm.

Aha. I was wrong here as reveal by Michael Haufe. In PostScript a fill
starts a new path. I incorrectly assumed that JS would follow the same
semantics, which was extra stupid because I've made this mistake before.

[toc] | [prev] | [next] | [standalone]


#38627

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2020-07-31 11:49 -0700
Message-ID<0ecb157b-5ccc-4c7b-9665-5cf7ea6a17cbo@googlegroups.com>
In reply to#38621
On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> When i draw 2 filled circles.
> ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> ctm.fill();
> 
> And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> 
> Why?

I assume because the "two more to the right" that you drew are missing another 'ctm.beginPath()' call. I've recreated your bug here:

<https://codepen.io/mlhaufe/pen/JjGgEjY>

specifically:

```js
const canvas = document.querySelector("canvas");
const ctx = canvas.getContext("2d");

ctx.beginPath();
ctx.arc(100, 75, 15, 0, 2 * Math.PI);
ctx.arc(150, 100, 15, 0, 2 * Math.PI);
ctx.fill();

// The following line is missing. Uncomment to fix the bug
// ctx.beginPath()
ctx.arc(200, 75, 15, 0, 2 * Math.PI);
ctx.fill();
```

[toc] | [prev] | [next] | [standalone]


#38629

FromJonas Thörnvall <jonas.thornvall@gmail.com>
Date2020-07-31 12:30 -0700
Message-ID<4596b71f-186a-4fe0-a136-b84273d6f79fo@googlegroups.com>
In reply to#38627
Den fredag 31 juli 2020 kl. 20:49:42 UTC+2 skrev Michael Haufe (TNO):
> On Thursday, July 30, 2020 at 5:41:58 PM UTC-5, Jonas Thörnvall wrote:
> > When i draw 2 filled circles.
> > ctm.arc(tileElement[u].X+50, tileElement[u].Y+50, 15, 0, 2 * Math.PI);
> > ctm.arc(tileElement[v].X+50, tileElement[v].Y+50, 15, 0, 2 * Math.PI);
> > ctm.fill();
> > 
> > And then draw two more to the right there is two triangles between them formed xshaped/butterfly?
> > 
> > Why?
> 
> I assume because the "two more to the right" that you drew are missing another 'ctm.beginPath()' call. I've recreated your bug here:
> 
> <https://codepen.io/mlhaufe/pen/JjGgEjY>
> 
> specifically:
> 
> ```js
> const canvas = document.querySelector("canvas");
> const ctx = canvas.getContext("2d");
> 
> ctx.beginPath();
> ctx.arc(100, 75, 15, 0, 2 * Math.PI);
> ctx.arc(150, 100, 15, 0, 2 * Math.PI);
> ctx.fill();
> 
> // The following line is missing. Uncomment to fix the bug
> // ctx.beginPath()
> ctx.arc(200, 75, 15, 0, 2 * Math.PI);
> ctx.fill();
> ```

Thanks Michael i was clueless just could not find it in the examples.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web