Fast filled circle
#2
(11-26-2022, 03:20 PM)mdijkens Wrote: I ran into issues with Paint and transparency; they don't get along very well.
So I created my own filled circle routine:
Code: (Select All)
Sub fCircle (x%, y%, r%, c~&)
  'Filled Circle: Transparency OK & >4x faster then Paint
  r2& = r% * r%
  xx% = Sqr(r2& - y2&): Line (x% - xx%, y%)-(x% + xx%, y%), c~&
  For yy% = 1 To r%
    y2& = yy% * yy%: xx% = Sqr(r2& - y2&)
    Line (x% - xx%, y% - yy%)-(x% + xx%, y% - yy%), c~&
    Line (x% - xx%, y% + yy%)-(x% + xx%, y% + yy%), c~&
  Next yy%
End Sub


It runs a lot faster then Circle & Paint and also works well with transparent colors!

That is very cool and very fast.  Side-question/observation:

Playing around with CIRCLE in GW-BASIC, the CIRCLE statement produces pretty perfect circles in every screen mode.  Drawing a square box (with LINE statement using the B parameter) in GW-BASIC will result in rectangles in different screen modes.  So the CIRCLE command in GW-BASIC must be doing something special to overcome the different pixel width to height ratios to always result in a circle instead of an oval.

For the code above, I would expect that same code to produce ovals in GW-BASIC when in screen modes that don't have 1 to 1 for pixel width to pixel height ratios.

Testing that out in QB64, the code above produces a perfect circle in every screen mode.

Just to understand the evolution of screen modes from GW-BASIC to QBASIC to QB64(pe), at which point did the varying pixel width to height ratios (as existing in GW-BASIC) go away?
Reply


Messages In This Thread
Fast filled circle - by mdijkens - 11-26-2022, 03:20 PM
RE: Fast filled circle - by CharlieJV - 11-26-2022, 03:58 PM
RE: Fast filled circle - by bplus - 11-26-2022, 04:19 PM
RE: Fast filled circle - by dbox - 11-26-2022, 10:43 PM
RE: Fast filled circle - by bplus - 11-26-2022, 10:54 PM
RE: Fast filled circle - by mdijkens - 11-26-2022, 11:13 PM
RE: Fast filled circle - by bplus - 11-26-2022, 11:29 PM
RE: Fast filled circle - by SMcNeill - 11-27-2022, 01:44 AM
RE: Fast filled circle - by SMcNeill - 11-27-2022, 01:46 AM
RE: Fast filled circle - by gaslouk - 11-27-2022, 04:50 AM



Users browsing this thread: 1 Guest(s)