Author Topic: CIRCLE with coordinates off of screen.  (Read 2813 times)

0 Members and 1 Guest are viewing this topic.

Offline ngr888

  • Newbie
  • Posts: 5
    • View Profile
CIRCLE with coordinates off of screen.
« on: April 15, 2020, 04:45:39 pm »
Hi.

How could I draw a circle (an arc, really) with the center coordinates outside the boundaries of the screen?
(No _CLIP -GET an PUT-)

I want to draw several circles with different centers.

Obviously,  CIRCLE(-x1, -y1), r  don't work.

Thank you.

Offline TerryRitchie

  • Seasoned Forum Regular
  • Posts: 495
  • Semper Fidelis
    • View Profile
Re: CIRCLE with coordinates off of screen.
« Reply #1 on: April 15, 2020, 05:15:49 pm »
Negative values work just fine.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2.  
  3. CIRCLE (-20, -20), 100, _RGB32(255, 255, 255)
  4.  
In order to understand recursion, one must first understand recursion.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: CIRCLE with coordinates off of screen.
« Reply #2 on: April 15, 2020, 06:09:35 pm »
I've drawn enormous circles with only small bits on screen, to the point that they appear to be straight lines. The application is a 'to scale' solar system model. https://www.qb64.org/forum/index.php?topic=1429.0

It's just a matter of getting your relative coordinate systems right, then doing the proper transformations.

I've found it necessary to be careful of certain types of off screen drawing as they can slow down programs under certain circumstances. For example, in the application I link to above, I was drawing planetary orbs to scale under various zoom factors and filling those circles with a rather famous circle filling routine that many here use (aka Steve's Fcirc). Problem being that when zooming in on a small moon or other local detail, large stars and planets that weren't in the view screen where being "processed" as if they were being drawn and they were gargantuan under those zoom settings. The program would essentially seem to lock up, though it was actually working properly, it was just taking vast amounts of processor time to do computations that weren't necessary.

Offline ngr888

  • Newbie
  • Posts: 5
    • View Profile
Re: CIRCLE with coordinates off of screen.
« Reply #3 on: April 19, 2020, 02:10:54 pm »
Hi, TerryRitchie.

Thank you for the answer that, logically, works with the extraordinary beauty of simplicity.

This is in summary the origin of the stupid typo that confused me:
         
================================
SCREEN 12
CLS
CIRCLE (100, 100), 20
circlr (-200, -200), 400
END
================================

Obtaining, of course, the relevant error message:

          ILLEGAL FUNCTION CALL

Highlighting the text in red (making it less legible for me) and indicating the line of the error.
Without further compiler information my attention was focused on the incorrect function call  that I attributed to the negative parameters and not to the writing error.

(CIRCLE "is" a system function
circlr would be a user defined function)

A message like:

     undefined user function circlr

would have served me as a better warning.

Confused in this way, I tackled the problem hard:

================================
REM  Aproximacion a dibujo de arco con centro fuera de pantalla.
'  QB64       15 ABR 2020
'
'
'   Pendiente: precisar punto de entrada y salida en los bordes.

CONST PI = 3.1416

DIM ancho AS INTEGER
DIM alto AS INTEGER
DIM ox AS INTEGER
DIM oy AS INTEGER
DIM r AS INTEGER
' DIM x AS INTEGER      No hacen falta
' DIM y AS INTEGER
DIM x2 AS INTEGER
DIM y2 AS INTEGER
DIM a AS SINGLE
DIM paso AS SINGLE
DIM primera AS INTEGER

ancho = 640
alto = 480

SCREEN 12           'REM_NEWIMAGE(ancho, alto)

ox = 700
oy = 500
r = 400

paso = 0.1

' x = INT(ox + r * COS(0))
' y = INT(oy + r * SIN(0))

primera = 1

FOR a = 0 TO 2 * PI STEP paso
    x2 = INT(ox + r * COS(a))
    y2 = INT(oy + r * SIN(a))
    ' Clipping
    IF ((x2 >= 0 AND (x2 < ancho))) AND ((y2 >= 0) AND (y2 < alto)) THEN
        ' La primera vez se establece el punto para las coordenadas relativas.
        IF primera = 1 THEN
            PSET (x2, y2)
            primera = 0
        ELSE
            LINE -(x2, y2)
        END IF
    END IF
NEXT a
END
================================

Code that works even though it is unrefined and leaves a "gap" between the input of the segments that will make up the circle (arc) and the edges of the window.
With this a PAINT (x, y),c command would fail to find no limit.

Now a new question: By establishing 'logical' coordinates linked to other 'physics', would PMAP also work with coordinates of the circle outside the window to remap?

Thanks again.

PD: OldMoses.

I will read your message carefully. It is something similar to my interest.
Specifically, simulate a (very elementary) approach to the shock waves of an object by breaking the sound barrier.

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: CIRCLE with coordinates off of screen.
« Reply #4 on: April 21, 2020, 08:10:52 pm »
I've lost count of the times that I've fussed, sometimes for hours or days, over similar typo based errors. When you mentioned the red highlight making the line less legible, it occurred to me that might be a good addition to a future version update. Making error message highlighting colors a user defined IDE color option. I don't see anywhere that it can be done presently.

Obtaining, of course, the relevant error message:

          ILLEGAL FUNCTION CALL

Highlighting the text in red (making it less legible for me) and indicating the line of the error.
Without further compiler information my attention was focused on the incorrect function call  that I attributed to the negative parameters and not to the writing error.

(CIRCLE "is" a system function
circlr would be a user defined function)

A message like:

     undefined user function circlr

would have served me as a better warning.