Author Topic: CIRCLE vs Circle Fill  (Read 2862 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
CIRCLE vs Circle Fill
« on: May 15, 2019, 04:18:24 am »
Hi guys
again on CIRCLE original graphic function....
it shows many points of weakness...

Why is it yet there?

Why don't substitute it with Circle Fill (by Steve) or with another good implementation (see Bplus, TerryRitchie etc etc sorry to who my memory puts out of the list)?

this is an open letter... not a criticism
what council of developers can do this?

Thanks to read

QB64 rocks

Programming isn't difficult, only it's  consuming time and coffee

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #1 on: May 15, 2019, 04:46:28 am »
Tempo, I have not found CIRCLE problems.  It does what the wiki says (as far as I know), so what is the problem ("many points of weakness")?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #2 on: May 15, 2019, 09:30:36 am »
Hi (again) TempodiBasic,

We did investigate adding a Circle Fill routine to QB64 and found it to be a very complex proposition.


Hi Qwerkey,

Circle does have a problem with alpha colors overlapping at the cardinal compass points. Hardly anyone knows or notices.
Circle has another problem when attemping to fill pie shaped borders with PAINT, it tends to leak because start and/or stop angle is a bit off. Again hardly anyone knows but you would notice it if you tried it.

Overlapping alpha at cardinal points:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(400, 400, 32)
  2. FOR r = 175 TO 1 STEP -1
  3.     CIRCLE (200, 200), r, _RGB32(0, 0, 180, 100)
  4.  


Pie slice leaks:
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(400, 400, 32)
  2. COLOR _RGB32(0, 0, 255)
  3. startR = _PI / 12: stopR = _PI * 5 / 12
  4. CIRCLE (200, 200), 100, , startR, stopR
  5. LINE (200, 200)-(200 + 100 * COS(startR), 200 - 100 * SIN(startR))
  6. LINE (200, 200)-(200 + 100 * COS(stopR), 200 - 100 * SIN(stopR))
  7. 'PSET (250, 150) 'check paint point
  8. PRINT "Press any to PAINT pie slice"
  9. PAINT (250, 150), _RGB32(255, 255, 255), _RGB32(0, 0, 255)
  10.  

Also while making 2nd example I noticed that startRadians and stopRadians go in the opposite direction around a circle eg to make the lines of the pie slice match the endpoints of the arc drawn with circle. Blah!, not consistent with radian measures starting at 0 Due East and going CLOCKWISE from there like the rest of the graphics work with radian angles.

« Last Edit: May 15, 2019, 09:36:51 am by bplus »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #3 on: May 15, 2019, 09:38:07 am »
@Qwerkey
thanks for reply...

IMHO
try this , it seems that there is a lack of continuity of the line of the ellipse mode that lets go out the color of PAINT

Code: QB64: [Select]
  1. ' **********************  USO DEI SOTTOPROGRAMMI --SUB-- ********************
  2. '************************ FUNZIONI GRAFICHE ECCETTO DRAW ********************
  3.  
  4. ' Parte delle dichiarazioni
  5. ' Dichiaro le SUB cioŠ i sottoprogrammi
  6. DECLARE SUB Aspetta (Sec!)
  7. DECLARE SUB Inizializza ()
  8. DECLARE SUB Linee ()
  9. DECLARE SUB Scritte ()
  10. DECLARE SUB RettangoliVuoti ()
  11. DECLARE SUB RettangoliPieni ()
  12. DECLARE SUB CerchiVuoti ()
  13. DECLARE SUB CerchiPieni ()
  14. DECLARE SUB ArchiVuoti ()
  15. DECLARE SUB ArchiPieni ()
  16. DECLARE SUB FetteVuote ()
  17. DECLARE SUB FettePiene ()
  18. DECLARE SUB EllisseOrizzontaleVuota ()
  19. DECLARE SUB EllisseOrizzontalePiena ()
  20. DECLARE SUB EllisseVerticaleVuota ()
  21. DECLARE SUB EllisseVerticalePiena ()
  22. DECLARE SUB ArchiEllisseOrizzontale ()
  23. DECLARE SUB ArchiEllisseVerticale ()
  24. DECLARE SUB FetteVuoteEllisseOrizzontale ()
  25. DECLARE SUB FetteVuoteEllisseVerticale ()
  26. DECLARE SUB FettePieneEllisseOrizzontale ()
  27. DECLARE SUB FettePieneEllisseVerticale ()
  28. CONST tot = .1
  29.  
  30. SCREEN 9 'pongo lo schermo in modalit… grafica
  31. WIDTH 80, 25
  32.  
  33.  
  34. ' Qui inizia il programma che chiama le varie SUB
  35. REM Inizializza
  36. REM Scritte
  37. REM Inizializza
  38. REM Linee
  39. REM Inizializza
  40. REM RettangoliVuoti
  41. REM Inizializza
  42. REM RettangoliPieni
  43. Inizializza
  44. CerchiVuoti
  45. Inizializza
  46. CerchiPieni
  47. Inizializza
  48. ArchiVuoti
  49. Inizializza
  50. FetteVuote
  51. Inizializza
  52. FettePiene
  53. Inizializza
  54. EllisseOrizzontaleVuota
  55. Inizializza
  56. EllisseOrizzontalePiena
  57. Inizializza
  58. EllisseVerticaleVuota
  59. Inizializza
  60. EllisseVerticalePiena
  61. Inizializza
  62. ArchiEllisseOrizzontale
  63. Inizializza
  64. FetteVuoteEllisseOrizzontale
  65. Inizializza
  66. FettePieneEllisseOrizzontale
  67. Inizializza
  68. ArchiEllisseVerticale
  69. Inizializza
  70. FetteVuoteEllisseVerticale
  71. Inizializza
  72. FettePieneEllisseVerticale
  73.  
  74. ' do il messaggio Finale
  75. LOCATE 23, 23: PRINT "Premere un tasto per terminare..."
  76. CLS 'pulisco lo schermo
  77. contatore% = 0 'inizializzo contatore%
  78.  
  79. SUB ArchiEllisseOrizzontale
  80.     ' ArchiEllisseOrizzontale
  81.     FOR contatore% = 1 TO 15
  82.         ' creo un cerchio colorato
  83.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, tot, contatore% MOD 7, .5
  84.         Aspetta tot
  85.     NEXT
  86.  
  87.  
  88. SUB ArchiEllisseVerticale
  89.     'Archi di ellisse ad asse maggiore verticale
  90.     FOR contatore% = 1 TO 15
  91.         ' creo un cerchio colorato
  92.         CIRCLE (350, 215), 220 - (10 * contatore%), contatore%, tot, (contatore% MOD 7), -1
  93.         Aspetta tot
  94.     NEXT
  95.  
  96.  
  97. SUB ArchiVuoti
  98.     'archi vuoti
  99.  
  100.     FOR contatore% = 1 TO 15
  101.         ' creo un cerchio colorato
  102.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, tot, contatore% MOD 7
  103.         Aspetta tot
  104.     NEXT
  105.  
  106.  
  107. SUB Aspetta (Sec!)
  108.     via! = TIMER
  109.     WHILE TIMER - via! <= Sec!
  110.     WEND
  111.  
  112. SUB CerchiPieni
  113.  
  114.     ' cerchi pieni
  115.  
  116.     FOR contatore% = 1 TO 15
  117.         ' creo un cerchio colorato
  118.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%
  119.         ' dipingo l'interno del cerchio
  120.         PAINT (350, 175), contatore%, contatore%
  121.         Aspetta tot
  122.     NEXT
  123.  
  124.  
  125. SUB CerchiVuoti
  126.     'cerchi vuoti
  127.     FOR contatore% = 1 TO 15
  128.         ' creo un cerchio colorato
  129.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%
  130.         Aspetta tot
  131.     NEXT
  132.  
  133.  
  134. SUB EllisseOrizzontalePiena
  135.     'ellissi piene ad asse maggiore orizzontale
  136.  
  137.     FOR contatore% = 1 TO 15
  138.         ' creo un cerchio colorato
  139.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, , , .5
  140.         ' dipingo l'interno del cerchio
  141.         PAINT (350, 175), contatore%, contatore%
  142.         Aspetta tot
  143.     NEXT
  144.  
  145.  
  146. SUB EllisseOrizzontaleVuota
  147.  
  148.     ' ellissi vuote ad asse maggiore orizzontale
  149.  
  150.     FOR contatore% = 1 TO 15
  151.         ' creo un cerchio colorato
  152.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, , , .5
  153.         Aspetta tot
  154.     NEXT
  155.  
  156.  
  157. SUB EllisseVerticalePiena
  158.     ' ellissi  piene ad asse maggiore verticale
  159.     FOR contatore% = 1 TO 15
  160.         ' creo un cerchio colorato
  161.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, , , -4
  162.         ' dipingo l'interno del cerchio
  163.         PAINT (350, 175), contatore%, contatore%
  164.         Aspetta tot
  165.     NEXT
  166.  
  167.  
  168.  
  169. SUB EllisseVerticaleVuota
  170.     ' ellissi vuote ad asse maggiore verticale
  171.  
  172.     FOR contatore% = 1 TO 15
  173.         ' creo un cerchio colorato
  174.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, , , -4
  175.         Aspetta tot
  176.     NEXT
  177.  
  178.  
  179. SUB FettePiene
  180.  
  181.     ' aree di cerchio o fette di torta piene
  182.  
  183.     FOR contatore% = 1 TO 15
  184.         ' creo un cerchio colorato
  185.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, -.3, -(contatore% MOD 5) - tot
  186.         ' coloro l'area
  187.         PAINT (370, 155), contatore%, contatore%
  188.         Aspetta tot
  189.     NEXT
  190.  
  191.  
  192. SUB FettePieneEllisseOrizzontale
  193.     ' Fette di torta di ellisse orizzontale piene
  194.     FOR contatore% = 1 TO 15
  195.         ' creo un cerchio colorato
  196.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, -tot, -(contatore% MOD 2) + -2.5, .5
  197.         ' coloro l'interno della fetta
  198.         PAINT (360, 170), contatore%, contatore%
  199.         Aspetta tot
  200.     NEXT
  201.  
  202.  
  203. SUB FettePieneEllisseVerticale
  204.     ' Fette di torta di ellisse orizzontale piene
  205.     FOR contatore% = 1 TO 15
  206.         ' creo un cerchio colorato
  207.         CIRCLE (350, 215), 220 - (10 * contatore%), contatore%, -tot, -(contatore% MOD 2) + -2.5, -1
  208.         ' coloro l'interno della fetta
  209.         PAINT (360, 210), contatore%, contatore%
  210.     NEXT
  211.  
  212.  
  213. SUB FetteVuote
  214.  
  215.     ' aree di cerchio o fette di torta vuote
  216.  
  217.  
  218.     FOR contatore% = 1 TO 15
  219.         ' creo un cerchio colorato
  220.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, -.3, -(contatore% MOD 5) - tot
  221.         Aspetta tot
  222.     NEXT
  223.  
  224.  
  225. SUB FetteVuoteEllisseOrizzontale
  226.     ' Fette di torta di ellisse vuote
  227.     FOR contatore% = 1 TO 15
  228.         ' creo un cerchio colorato
  229.         CIRCLE (350, 175), 220 - (10 * contatore%), contatore%, -tot, -(contatore% MOD 7) - tot, .5
  230.         Aspetta tot
  231.     NEXT
  232.  
  233.  
  234. SUB FetteVuoteEllisseVerticale
  235.     ' Fette di torta di ellisse orizzontale vuote
  236.     FOR contatore% = 1 TO 15
  237.         ' creo un cerchio colorato
  238.         CIRCLE (350, 215), 220 - (10 * contatore%), contatore%, -tot, -(contatore% MOD 2) + -2.5, -1
  239.         Aspetta tot
  240.     NEXT
  241.  
  242.  
  243. SUB Inizializza
  244.     ' do il messaggio
  245.     LOCATE 23: PRINT "Premere un tasto per continuare..."
  246.     SLEEP 1
  247.     CLS 'pulisco lo schermo
  248.     contatore% = 0 'inizializzo contatore%
  249.  
  250.  
  251. SUB Linee
  252.                                
  253.     FOR contatore% = 1 TO 15
  254.         ' creo una linea dall'angolo in alto a sinistra a quello in basso a destra
  255.         LINE (1 + 10 * contatore%, 1)-(640 + contatore%, 350), contatore%
  256.         Aspetta tot
  257.     NEXT 'contatore%       'qui finisce il ciclo FOR...NEXT
  258.  
  259.  
  260. SUB RettangoliPieni
  261.  
  262.     ' rettangoli pieni
  263.  
  264.     FOR contatore% = 1 TO 15
  265.         ' creo un rettangolo pieno rosso
  266.         LINE (20 + 10 * contatore%, 20 + 5 * contatore%)-(200 + 10 * contatore%, 200 + 10 * contatore%), contatore%, BF
  267.         Aspetta tot
  268.     NEXT ' qui finisce il ciclo FOR...NEXT
  269.  
  270.  
  271. SUB RettangoliVuoti
  272.                          
  273.     'rettangoli vuoti
  274.     FOR contatore% = 1 TO 15
  275.         ' creo un rettangolo vuoto in fucsia
  276.         LINE (10 + 10 * contatore%, 10 + 5 * contatore%)-(100 + 20 * contatore%, 100 + 10 * contatore%), contatore%, B
  277.         Aspetta tot
  278.     NEXT 'qui finisce il ciclo FOR ... NEXT
  279.  
  280.  
  281. SUB Scritte
  282.                                
  283.     'scritte  colorate
  284.     FOR contatore% = 1 TO 15
  285.         ' pongo il cursore alla riga 1 e colonna 1, uso il colore  e scrivo Ciao
  286.         LOCATE contatore%, contatore%: COLOR contatore%
  287.         PRINT "Ciao"
  288.         Aspetta tot
  289.     NEXT
  290.  
(this is an old code written in Qbasic)

and try this
Code: QB64: [Select]
  1. ' a porting to QB64 of Mitosis simulation as showed in this video
  2. '[youtube]https://www.youtube.com/watch?v=jxGS3fKPKJA[/youtube]
  3. TYPE Cell
  4.     x AS INTEGER
  5.     y AS INTEGER
  6.     Radius AS INTEGER
  7.     Colors AS _UNSIGNED LONG
  8.  
  9. CONST Hscreen = 700, Wscreen = 800, StartRadius = 60, MaxCells = 1000
  10. CONST True = -1, False = NOT True, MinRadius = 3
  11. 'CONST Blu = _RGB32(0, 0, 255): CONST Black = _RGB32(0, 0, 0)
  12. 'CONST Red = _RGB32(255, 0, 0): CONST Green = _RGB32(0, 255, 0)
  13. 'CONST White = _RGB(255, 255, 255)
  14. DIM SHARED A AS LONG, Cells(1 TO MaxCells) AS Cell, NumActiveCell AS INTEGER
  15. DIM SHARED FNameOn AS INTEGER, KeyS AS INTEGER
  16.  
  17. IF NOT Setup THEN PRINT "Error in Setup"
  18.     IF NOT Draws THEN PRINT "Error in Draws"
  19.     IF NOT MoveCell THEN PRINT "Error in movecell"
  20.     IF MousePressed THEN
  21.         F = CellClicked
  22.         'clear buffer of mouse input
  23.         WHILE _MOUSEBUTTON(1)
  24.             IF _MOUSEINPUT THEN REM
  25.         WEND
  26.  
  27.         IF F <> False THEN
  28.             PRINT "LeftClick on cell "; F
  29.             IF NumActiveCell < MaxCells AND (NOT DuplicateCell(F)) THEN PRINT "Error in Duplicatecell"
  30.         ELSE
  31.             PRINT "LeftClick out of cells"
  32.         END IF
  33.     END IF
  34.     KeyS = _KEYHIT
  35.     IF KeyS = 78 OR KeyS = 110 THEN FNameOn = NOT FNameOn
  36.     _DISPLAY '<<<<<<<<<<<< prevent flicker
  37.     _LIMIT 10
  38. LOOP UNTIL KeyS = 32
  39.  
  40.  
  41. FUNCTION Setup
  42.     'Setup = False
  43.     DIM b AS INTEGER
  44.     A = _NEWIMAGE(Wscreen, Hscreen, 32)
  45.     IF A < -1 THEN SCREEN A ELSE PRINT "Image handle for Screen not valid"
  46.     _TITLE "Mitosis Simulation"
  47.     NumActiveCell = 10
  48.     FNameOn = False
  49.     FOR b = 1 TO NumActiveCell
  50.         IF b < 11 THEN
  51.             Cells(b).x = MinMax(5, Wscreen - 5)
  52.             Cells(b).y = MinMax(5, Hscreen - 5)
  53.             Cells(b).Radius = StartRadius
  54.             Cells(b).Colors = NewColor
  55.             'ELSE
  56.             '    Cells(b).x = 0
  57.             '    Cells(b).y = 0
  58.             '    Cells(b).Radius = 0
  59.             '    Cells(b).Colors = 0
  60.         END IF
  61.     NEXT b
  62.     Setup = True
  63.  
  64. FUNCTION DuplicateCell (Index AS INTEGER)
  65.     'DuplicateCell = False
  66.     IF INT(Cells(Index).Radius / 2) > MinRadius THEN
  67.         NumActiveCell = NumActiveCell + 1
  68.         Cells(NumActiveCell).y = Cells(Index).y
  69.         Cells(NumActiveCell).Colors = Cells(Index).Colors
  70.         Cells(NumActiveCell).Radius = INT(Cells(Index).Radius / 2)
  71.         Cells(Index).Radius = Cells(NumActiveCell).Radius
  72.         Cells(NumActiveCell).x = Cells(Index).x + MinMax(-Cells(Index).Radius, Cells(Index).Radius)
  73.         Cells(Index).x = Cells(Index).x + MinMax(-Cells(Index).Radius, Cells(Index).Radius)
  74.     END IF
  75.     DuplicateCell = True
  76.  
  77. FUNCTION MousePressed
  78.     'MousePressed = False
  79.         IF _MOUSEBUTTON(1) = True THEN MousePressed = True
  80.     WEND
  81.  
  82. FUNCTION IsInTheRange (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  83.     'IsInTheRange = False
  84.     IF What > Min AND What < Max THEN IsInTheRange = True
  85.  
  86. FUNCTION CellClicked
  87.     'CellClicked = False
  88.     DIM b AS INTEGER
  89.     FOR b = 1 TO NumActiveCell STEP 1
  90.         'IF IsInTheRange(_MOUSEX, Cells(b).x - Cells(b).Radius, Cells(b).x + Cells(b).Radius) THEN
  91.         '    IF IsInTheRange(_MOUSEY, Cells(b).y - Cells(b).Radius, Cells(b).y + Cells(b).Radius) THEN
  92.         '        CellClicked = b
  93.         '        EXIT FUNCTION
  94.         '    END IF
  95.         'END IF
  96.         IF ((_MOUSEX - Cells(b).x) ^ 2 + (_MOUSEY - Cells(b).y) ^ 2) ^ .5 <= Cells(b).Radius THEN CellClicked = b: EXIT FUNCTION
  97.     NEXT b
  98.  
  99. FUNCTION InTheRange (What AS INTEGER, Min AS INTEGER, Max AS INTEGER)
  100.     'InTheRange = False
  101.     IF What < Min THEN What = Min
  102.     IF What > Max THEN What = Max
  103.     IF What >= Min AND What <= Max THEN InTheRange = True
  104.  
  105. FUNCTION MinMax (Min AS INTEGER, Max AS INTEGER)
  106.     'MinMax = False
  107.     IF Min > Max THEN SWAP Min, Max
  108.     MinMax = INT(RND * (Max - Min + 1)) + Min
  109.  
  110. FUNCTION Draws
  111.     'Draws = False
  112.     DIM b AS INTEGER
  113.     CLS , Black
  114.     FOR b = 1 TO NumActiveCell
  115.         IF NOT ShowCell THEN PRINT "Error in Showcell with value "; Cells(b).x; " "; Cells(b).y
  116.     NEXT b
  117.     Draws = True
  118.  
  119. FUNCTION MoveCell
  120.     'MoveCell = False
  121.     DIM b AS INTEGER
  122.     FOR b = 1 TO NumActiveCell STEP 1
  123.         Cells(b).x = Cells(b).x + MinMax(-3, 3)
  124.         Cells(b).y = Cells(b).y + MinMax(-3, 3)
  125.         IF NOT InTheRange(Cells(b).x, 5, Wscreen - 5) THEN PRINT "Error IntheRange X"
  126.         IF NOT InTheRange(Cells(b).y, 5, Hscreen - 5) THEN PRINT "Error IntheRange Y"
  127.     NEXT b
  128.     MoveCell = True
  129.  
  130. FUNCTION NewColor~&
  131.     'NewColor~& = False
  132.     c = _RGB32(MinMax(100, 255), MinMax(100, 255), MinMax(100, 255), 20)
  133.     IF c < 0 THEN
  134.         PRINT "Error in NewColor "; c: EXIT FUNCTION
  135.     ELSE
  136.         NewColor~& = c
  137.     END IF
  138.  
  139. FUNCTION ShowCell
  140.     'ShowCell = False
  141.     DIM b AS INTEGER
  142.     FOR b = 1 TO NumActiveCell STEP 1
  143.         'fcirc
  144.         CIRCLE (Cells(b).x, Cells(b).y), Cells(b).Radius, Cells(b).Colors
  145.         PAINT STEP(0, 0), Cells(b).Colors, Cells(b).Colors
  146.         IF FNameOn THEN _PRINTSTRING (Cells(b).x, Cells(b).y), LTRIM$(STR$(b))
  147.     NEXT b
  148.     ShowCell = True
  149.  
  150.  
  151. 'from Steve Gold standard, >>> add for Circle Fills
  152. SUB fcirc (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  153.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  154.     DIM X AS INTEGER, Y AS INTEGER
  155.  
  156.     Radius = ABS(R)
  157.     RadiusError = -Radius
  158.     X = Radius
  159.     Y = 0
  160.  
  161.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  162.  
  163.     ' Draw the middle span here so we don't draw it twice in the main loop,
  164.     ' which would be a problem with blending turned on.
  165.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  166.  
  167.     WHILE X > Y
  168.         RadiusError = RadiusError + Y * 2 + 1
  169.         IF RadiusError >= 0 THEN
  170.             IF X <> Y + 1 THEN
  171.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  172.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  173.             END IF
  174.             X = X - 1
  175.             RadiusError = RadiusError - X * 2
  176.         END IF
  177.         Y = Y + 1
  178.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  179.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  180.     WEND
  181.  

taken from here https://www.qb64.org/forum/index.php?topic=1345.msg105440#msg105440
what do you think about it?

Thanks to reply
Programming isn't difficult, only it's  consuming time and coffee

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #4 on: May 15, 2019, 09:43:46 am »
Hi Bplus
thanks for your time
I am very glad to get informations about QB64

I'm sorry for my  heavy curiosity, but is the problem  in the underlaying C++ function or in the algorythm coded building QB64?

Programming isn't difficult, only it's  consuming time and coffee

Offline Qwerkey

  • Forum Resident
  • Posts: 755
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #5 on: May 15, 2019, 09:57:11 am »
Guys, thanks.  I had imagined that Tempo's (well everybody's) problem had something to do with leakiness or such.  But having recently used (for my Pascal's Triangle graphical program) CIRCLE and PAINT with complete success, I'd assumed that there was nothing wrong.  I've never used segments nor tried alpha with CIRCLE.  I have always been wondrous at PAINT actually working: what brilliant piece of programming is required to determine uniquely one side and the other of a drawn line? does the (c#) programming look pixel-by-pixel or what?
« Last Edit: May 15, 2019, 10:54:40 am by Qwerkey »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #6 on: May 15, 2019, 10:14:40 am »
Hi Bplus
thanks for your time
I am very glad to get informations about QB64

I'm sorry for my  heavy curiosity, but is the problem  in the underlaying C++ function or in the algorythm coded building QB64?

There was some discussion of Circle in the QB64 code here:
https://www.qb64.org/forum/index.php?topic=1044.135

Steve gave instructions of how to find it in source in reply #136
I checked it out and it was discussed a little more in replies 140++

This was when I stumbled into the alpha colors problem.

The pie slice filling problem was discovered earlier by others and solutions explored at Walter's forum. I still have code and Steve has solutions too I think. I see the PAINT leaks shows up in running old Qbasic code in QB64 that TempodiBasic brought today.
« Last Edit: May 15, 2019, 10:16:10 am by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: CIRCLE vs Circle Fill
« Reply #7 on: May 15, 2019, 10:23:03 am »
Guys, thanks.  I had imagined that Tempo's (well everybody's) problem had something to do with leakiness or such.  But having recently used (for my Pascal's Triangle graphical program) CIRCLE and PAINT with complete success, I'd assumed that there was nothing wrong.  I've never used segments not tried alpha with CIRCLE.  I have always been wondrous at PAINT actually working: what brilliant piece of programming is required to determine uniquely one side and the other of a drawn line? does the (c#) programming look pixel-by-pixel or what?

PAINT is an interesting recursive algorithm similar to making fire or growing kelp. Steve and I played around with a PAINT like method for filling a space with balls. It also comes up with labeling cells in FreeCell or MineSweeper and the Pathfinding thing we played with here for possible games.

Code: QB64: [Select]
  1. _TITLE "Circle Paint by Steve mod B+" '2019-02-06
  2. SCREEN _NEWIMAGE(640, 480, 32)
  3.  
  4. CONST Red = &HFFFF0000
  5.  
  6. LINE (200, 200)-(400, 400), Red, B
  7. CircleFiller 300, 300, 10, Red
  8. PRINT "Hit any key for real fun!"
  9. CLS , 0
  10. WHILE _KEYDOWN(27) = 0
  11.     CLS
  12.     LINE (1, 1)-(639, 479), Red, B
  13.     LINE (0, 0)-(640, 480), Red, B
  14.     FOR i = 1 TO 5
  15.         CIRCLE (RND * 640, RND * 480), RND * 30 + 20, Red
  16.     NEXT
  17.     CircleFiller 320, 240, 10, Red
  18.     _DISPLAY
  19.     _LIMIT .5
  20.  
  21. SUB CircleFiller (x, y, r, k AS _UNSIGNED LONG)
  22.     IF CircleFillValid(x, y, r, k) THEN
  23.         CircleFill x, y, r, k
  24.         CircleFiller x - r - r - 1, y, r, k
  25.         CircleFiller x + r + r + 1, y, r, k
  26.         CircleFiller x, y - r - r - 1, r, k
  27.         CircleFiller x, y + r + r + 1, r, k
  28.     END IF
  29.  
  30.  
  31. SUB CircleFill (cx AS INTEGER, cy AS INTEGER, r AS INTEGER, c AS _UNSIGNED LONG)
  32.     DIM a AS LONG, b AS LONG
  33.     DIM x AS LONG, y AS LONG
  34.     DIM xx AS LONG, yy AS LONG
  35.     DIM sx AS LONG, sy AS LONG
  36.     DIM e AS LONG
  37.     DIM rx AS INTEGER, ry AS INTEGER
  38.     rx = r: ry = r
  39.  
  40.     a = 2 * rx * rx
  41.     b = 2 * ry * ry
  42.     x = rx
  43.     xx = ry * ry * (1 - rx - rx)
  44.     yy = rx * rx
  45.     sx = b * rx
  46.  
  47.     DO WHILE sx >= sy
  48.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  49.         IF y <> 0 THEN LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  50.  
  51.         y = y + 1
  52.         sy = sy + a
  53.         e = e + yy
  54.         yy = yy + a
  55.  
  56.         IF (e + e + xx) > 0 THEN
  57.             x = x - 1
  58.             sx = sx - b
  59.             e = e + xx
  60.             xx = xx + b
  61.         END IF
  62.     LOOP
  63.  
  64.     x = 0
  65.     y = ry
  66.     xx = rx * ry
  67.     yy = rx * rx * (1 - ry - ry)
  68.     e = 0
  69.     sx = 0
  70.     sy = a * ry
  71.  
  72.     DO WHILE sx <= sy
  73.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  74.         LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  75.  
  76.         DO
  77.             x = x + 1
  78.             sx = sx + b
  79.             e = e + xx
  80.             xx = xx + b
  81.         LOOP UNTIL (e + e + yy) > 0
  82.  
  83.         y = y - 1
  84.         sy = sy - a
  85.         e = e + yy
  86.         yy = yy + a
  87.  
  88.     LOOP
  89.  
  90.  
  91.  
  92. FUNCTION CircleFillValid (cx AS INTEGER, cy AS INTEGER, r AS INTEGER, c AS _UNSIGNED LONG)
  93.     DIM a AS LONG, b AS LONG
  94.     DIM x AS LONG, y AS LONG
  95.     DIM xx AS LONG, yy AS LONG
  96.     DIM sx AS LONG, sy AS LONG
  97.     DIM e AS LONG
  98.     DIM rx AS INTEGER, ry AS INTEGER
  99.     rx = r: ry = r
  100.  
  101.     a = 2 * rx * rx
  102.     b = 2 * ry * ry
  103.     x = rx
  104.     xx = ry * ry * (1 - rx - rx)
  105.     yy = rx * rx
  106.     sx = b * rx
  107.  
  108.     DO WHILE sx >= sy
  109.         FOR i = cx - x TO cx + x
  110.             IF POINT(i, cy - y) = c THEN EXIT FUNCTION
  111.         NEXT
  112.         'LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  113.         IF y <> 0 THEN
  114.             'LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  115.             FOR i = cx - x TO cx + x
  116.                 IF POINT(i, cy + y) = c THEN EXIT FUNCTION
  117.             NEXT
  118.         END IF
  119.  
  120.         y = y + 1
  121.         sy = sy + a
  122.         e = e + yy
  123.         yy = yy + a
  124.  
  125.         IF (e + e + xx) > 0 THEN
  126.             x = x - 1
  127.             sx = sx - b
  128.             e = e + xx
  129.             xx = xx + b
  130.         END IF
  131.     LOOP
  132.  
  133.     x = 0
  134.     y = ry
  135.     xx = rx * ry
  136.     yy = rx * rx * (1 - ry - ry)
  137.     e = 0
  138.     sx = 0
  139.     sy = a * ry
  140.  
  141.     DO WHILE sx <= sy
  142.         'LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  143.         'LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  144.         FOR i = cx - x TO cx + x
  145.             IF POINT(i, cy - y) = c THEN EXIT FUNCTION
  146.             IF POINT(i, cy + y) = c THEN EXIT FUNCTION
  147.         NEXT
  148.  
  149.         DO
  150.             x = x + 1
  151.             sx = sx + b
  152.             e = e + xx
  153.             xx = xx + b
  154.         LOOP UNTIL (e + e + yy) > 0
  155.  
  156.         y = y - 1
  157.         sy = sy - a
  158.         e = e + yy
  159.         yy = yy + a
  160.  
  161.     LOOP
  162.     CircleFillValid = -1
  163.  
  164.  

Hey Pete!
Code: QB64: [Select]
  1. _TITLE "Circle Filled by Steve mod B+" '2019-02-06
  2. CONST xmax = 800
  3. CONST ymax = 600
  4.  
  5. SCREEN _NEWIMAGE(xmax, ymax, 32)
  6. black = _RGB32(0, 0, 0)
  7.  
  8. LINE (0, 0)-(800, 600), black, BF
  9. LINE (200, 200)-(400, 400), &HFFFFFFFF, B
  10. PaintWithBalls 300, 300, 10, _RGB32(255, 128, 0)
  11. INPUT "To see a show, press enter,  and other + enter ends program... "; wate$
  12.  
  13. WHILE _KEYDOWN(27) = 0
  14.     LINE (0, 0)-(800, 600), &HFF000000, BF
  15.     LINE (0, 0)-(800, 600), _RGB32(255, 255, 255), B
  16.     LINE (1, 1)-(799, 599), _RGB32(255, 255, 255), B
  17.     FOR i = 1 TO 5
  18.         LINE (RND * 800, RND * 600)-STEP(RND * 50 + 50, RND * 50 + 50), _RGB32(RND * 255, RND * 255, RND * 255), B
  19.     NEXT
  20.     PaintWithBalls 200, 200, INT(RND * 45 + 5), _RGB32(255, 100, 0)
  21.     _LIMIT 1
  22.  
  23. SUB PaintWithBalls (X, Y, ballRadius, ballColr AS _UNSIGNED LONG)
  24.     ra = _PI(2 / 6)
  25.     br = 2 * ballRadius + 1
  26.     IF circClear(X, Y, ballRadius) THEN
  27.         ball X, Y, ballRadius, ballColr
  28.         PaintWithBalls X + br * COS(0), Y + br * SIN(0), ballRadius, ballColr
  29.         PaintWithBalls X + br * COS(ra), Y + br * SIN(ra), ballRadius, ballColr
  30.         PaintWithBalls X + br * COS(ra * 2), Y + br * SIN(ra * 2), ballRadius, ballColr
  31.         PaintWithBalls X + br * COS(ra * 3), Y + br * SIN(ra * 3), ballRadius, ballColr
  32.         PaintWithBalls X + br * COS(ra * 4), Y + br * SIN(ra * 4), ballRadius, ballColr
  33.         PaintWithBalls X + br * COS(ra * 5), Y + br * SIN(ra * 5), ballRadius, ballColr
  34.     END IF
  35.  
  36. 'Steve McNeil's  copied from his forum   note: Radius is too common a name
  37. FUNCTION circClear (CX AS LONG, CY AS LONG, R AS LONG)
  38.     DIM subRadius AS LONG, RadiusError AS LONG
  39.     DIM X AS LONG, Y AS LONG
  40.  
  41.     subRadius = ABS(R)
  42.     RadiusError = -subRadius
  43.     X = subRadius
  44.     Y = 0
  45.  
  46.     'IF subRadius = 0 THEN PSET (CX, CY): EXIT SUB
  47.  
  48.     ' Draw the middle span here so we don't draw it twice in the main loop,
  49.     ' which would be a problem with blending turned on.
  50.     FOR i = CX - X TO CX + X
  51.         IF POINT(i, CY) <> black THEN EXIT FUNCTION
  52.     NEXT
  53.     WHILE X > Y
  54.         RadiusError = RadiusError + Y * 2 + 1
  55.         IF RadiusError >= 0 THEN
  56.             IF X <> Y + 1 THEN
  57.                 FOR i = CX - Y TO CX + Y
  58.                     IF POINT(i, CY - X) <> black THEN EXIT FUNCTION
  59.                 NEXT
  60.                 'LINE (CX - Y, CY - X)-(CX + Y, CY - X), , BF
  61.                 FOR i = CX - Y TO CX + Y
  62.                     IF POINT(i, CY + X) <> black THEN EXIT FUNCTION
  63.                 NEXT
  64.                 'LINE (CX - Y, CY + X)-(CX + Y, CY + X), , BF
  65.             END IF
  66.             X = X - 1
  67.             RadiusError = RadiusError - X * 2
  68.         END IF
  69.         Y = Y + 1
  70.         FOR i = CX - X TO CX + X
  71.             IF POINT(i, CY - Y) <> black THEN EXIT FUNCTION
  72.         NEXT
  73.         'LINE (CX - X, CY - Y)-(CX + X, CY - Y), , BF
  74.  
  75.         FOR i = CX - X TO CX + X
  76.             IF POINT(i, CY + Y) <> black THEN EXIT FUNCTION
  77.         NEXT
  78.         'LINE (CX - X, CY + Y)-(CX + X, CY + Y), , BF
  79.  
  80.     WEND
  81.     circClear = -1
  82.  
  83.     rd = _RED32(K): g = _GREEN32(K): b = _BLUE32(K)
  84.     FOR rad = r TO 1 STEP -1
  85.         kr = _RGB32((r - rad) / r * rd, (r - rad) / r * g, (r - rad) / r * b)
  86.         fel x, y, rad, rad, kr
  87.     NEXT
  88.  
  89. 'FillEllipse is too much typing so aballRadiuseviated to fel
  90. ' with Steve's EllipseFill, who needs CircleFill? fix for 0 radii 2019-02-05
  91. ' Is this fast enough for general circle fill (June 2018):  https://www.qb64.org/forum/index.php?topic=298.msg1942#msg1942
  92. '  EllipseFill SMcNeill (Nov 3, 2018) https://www.qb64.org/forum/index.php?topic=755.msg6506#msg6506
  93.     DIM a AS LONG, b AS LONG
  94.     DIM x AS LONG, y AS LONG
  95.     DIM xx AS LONG, yy AS LONG
  96.     DIM sx AS LONG, sy AS LONG
  97.     DIM e AS LONG
  98.  
  99.     IF rx = 0 OR ry = 0 THEN EXIT SUB 'nothing to draw
  100.  
  101.     a = 2 * rx * rx
  102.     b = 2 * ry * ry
  103.     x = rx
  104.     xx = ry * ry * (1 - rx - rx)
  105.     yy = rx * rx
  106.     sx = b * rx
  107.  
  108.     DO WHILE sx >= sy
  109.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  110.         IF y <> 0 THEN LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  111.  
  112.         y = y + 1
  113.         sy = sy + a
  114.         e = e + yy
  115.         yy = yy + a
  116.  
  117.         IF (e + e + xx) > 0 THEN
  118.             x = x - 1
  119.             sx = sx - b
  120.             e = e + xx
  121.             xx = xx + b
  122.         END IF
  123.     LOOP
  124.  
  125.     x = 0
  126.     y = ry
  127.     xx = rx * ry
  128.     yy = rx * rx * (1 - ry - ry)
  129.     e = 0
  130.     sx = 0
  131.     sy = a * ry
  132.  
  133.     DO WHILE sx <= sy
  134.         LINE (cx - x, cy - y)-(cx + x, cy - y), c, BF
  135.         LINE (cx - x, cy + y)-(cx + x, cy + y), c, BF
  136.  
  137.         DO
  138.             x = x + 1
  139.             sx = sx + b
  140.             e = e + xx
  141.             xx = xx + b
  142.         LOOP UNTIL (e + e + yy) > 0
  143.  
  144.         y = y - 1
  145.         sy = sy - a
  146.         e = e + yy
  147.         yy = yy + a
  148.  
  149.     LOOP
  150.  
  151.  
  152. FUNCTION rand% (lo%, hi%)
  153.     rand% = INT(RND * (hi% - lo% + 1)) + lo%
  154.  
  155.  
  156.  
« Last Edit: May 15, 2019, 10:55:22 am by bplus »