ugBASIC 1.18
An isomorphic BASIC language compiler for retrocomputers
Loading...
Searching...
No Matches
circle.c
Go to the documentation of this file.
1/*****************************************************************************
2 * ugBASIC - an isomorphic BASIC language compiler for retrocomputers *
3 *****************************************************************************
4 * Copyright 2021-2026 Marco Spedaletti (asimov@mclink.it)
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *----------------------------------------------------------------------------
18 * Concesso in licenza secondo i termini della Licenza Apache, versione 2.0
19 * (la "Licenza"); è proibito usare questo file se non in conformità alla
20 * Licenza. Una copia della Licenza è disponibile all'indirizzo:
21 *
22 * http://www.apache.org/licenses/LICENSE-2.0
23 *
24 * Se non richiesto dalla legislazione vigente o concordato per iscritto,
25 * il software distribuito nei termini della Licenza è distribuito
26 * "COSÌ COM'È", SENZA GARANZIE O CONDIZIONI DI ALCUN TIPO, esplicite o
27 * implicite. Consultare la Licenza per il testo specifico che regola le
28 * autorizzazioni e le limitazioni previste dalla medesima.
29 ****************************************************************************/
30
31/****************************************************************************
32 * INCLUDE SECTION
33 ****************************************************************************/
34
35#include "../../ugbc.h"
36
37/****************************************************************************
38 * CODE SECTION
39 ****************************************************************************/
40
50/* <usermanual>
51@keyword CIRCLE
52
53@english
54
55The ''CIRCLE'' command in BASIC draws a circle on the screen. In other words, it defines
56a complete circle based on the coordinates and radius that you specify.
57
58This command allows you to draw a circle with starting coordinates in ''(x,y)''
59and radius ''r''. The color is indicated by the parameter ''c''. If the abscissa
60and/or ordinate is omitted, the last graphic position drawn will be used. In
61addition, the color can also be omitted and, if necessary, the last color set with the
62''PEN'' or ''INK'' command will be used.
63
64There is also another additional syntax, that can be used
65to draw ellipses: you can give both the radii ''rx'' and ''ry'' in the color determined
66by ''fq'' (see ''HIRES'').
67
68The accuracy of the circle depends on the resolution of your screen. Lower-resolution screens
69may display less sharp circles.
70
71@italian
72
73Il comando ''CIRCLE'' in BASIC disegna un cerchio sullo schermo. In altre parole,
74definisce un cerchio completo in base alle coordinate e al raggio specificati.
75
76Questo comando consente di disegnare un cerchio con coordinate iniziali in ''(x,y)''
77e raggio ''r''. Il colore è indicato dal parametro ''c''. Se l'ascissa e/o l'ordinata
78vengono omesse, verrà utilizzata l'ultima posizione grafica disegnata. Inoltre, è
79possibile omettere anche il colore e, se necessario, verrà utilizzato l'ultimo colore
80impostato con il comando ''PEN'' o ''INK''.
81
82Esiste anche un'altra sintassi aggiuntiva, che può essere utilizzata per disegnare
83ellissi: è possibile specificare sia i raggi ''rx'' che ''ry'' nel colore determinato
84da ''fq'' (vedere ''HIRES'').
85
86La precisione del cerchio dipende dalla risoluzione dello schermo. Gli schermi a
87bassa risoluzione potrebbero visualizzare cerchi meno nitidi.
88
89@syntax CIRCLE [x], [y], r[, c]
90@syntax CIRCLE x, y, rx, ry[, c]
91
92@example ' Draw a circle
93@example CIRCLE 100,100,42
94@example ' Draw an ellipse
95@example CIRCLE 100,100,21,42
96@example CIRCLE ,,21,RED
97@usedInExample graphics_position_01.bas
98@usedInExample graphics_position_02.bas
99@usedInExample graphics_shapes_02.bas
100
101@seeAlso ELLIPSE
102
103@target all
104</usermanual> */
105void circle( Environment * _environment, char * _x, char * _y, char * _r, char * _c, int _preserve_color ) {
106
107 Variable * xCentre = variable_retrieve_or_define( _environment, _x, VT_POSITION, 0 );
108 Variable * yCentre = variable_retrieve_or_define( _environment, _y, VT_POSITION, 0 );
109 Variable * r = variable_retrieve_or_define( _environment, _r, VT_POSITION, 0 );
110
111 Variable * x = variable_temporary( _environment, VT_POSITION, "(x)" );
112 variable_move( _environment, r->name, x->name );
113 Variable * y = variable_temporary( _environment, VT_POSITION, "(y)" );
114 variable_store( _environment, y->name, 0 );
115 Variable * p = variable_temporary( _environment, VT_SWORD, "(p)" );
116
117 plot( _environment, variable_add( _environment, x->name, xCentre->name )->name, variable_add( _environment, y->name, yCentre->name )->name, _c, 0 );
118 plot( _environment, variable_sub( _environment, xCentre->name, x->name )->name, variable_add( _environment, y->name, yCentre->name )->name, _c, 0 );
119 plot( _environment, variable_add( _environment, x->name, xCentre->name )->name, variable_sub( _environment, yCentre->name, y->name )->name, _c, 0 );
120 plot( _environment, variable_sub( _environment, xCentre->name, x->name )->name, variable_sub( _environment, yCentre->name, y->name )->name, _c, 0 );
121
122 variable_move( _environment, variable_complement_const( _environment, r->name, 1 )->name, p->name );
123
124 begin_while( _environment );
125 begin_while_condition( _environment, variable_greater_than( _environment, x->name, y->name, 1 )->name );
126
127 if_then( _environment, variable_less_than_const( _environment, p->name, 0, 1 )->name );
128 variable_move( _environment, variable_add( _environment, variable_sl_const( _environment, y->name, 1 )->name, p->name )->name, p->name );
129 variable_increment( _environment, p->name );
130 else_if_then_label( _environment );
131 else_if_then( _environment, NULL );
132 variable_decrement( _environment, x->name );
133 variable_move( _environment, variable_add( _environment, variable_sl_const( _environment, y->name, 1 )->name, p->name )->name, p->name );
134 variable_move( _environment, variable_sub( _environment, p->name, variable_sl_const( _environment, x->name, 1 )->name )->name, p->name );
135 variable_increment( _environment, p->name );
136 end_if_then( _environment );
137
138 if_then( _environment, variable_less_than( _environment, x->name, y->name, 0 )->name );
139 exit_loop( _environment, 0 );
140 end_if_then( _environment );
141
142 plot( _environment, variable_add( _environment, x->name, xCentre->name )->name, variable_add( _environment, y->name, yCentre->name )->name, _c, _preserve_color );
143 plot( _environment, variable_sub( _environment, xCentre->name, x->name )->name, variable_add( _environment, y->name, yCentre->name )->name, _c, _preserve_color );
144 plot( _environment, variable_add( _environment, x->name, xCentre->name )->name, variable_sub( _environment, yCentre->name, y->name )->name, _c, _preserve_color );
145 plot( _environment, variable_sub( _environment, xCentre->name, x->name )->name, variable_sub( _environment, yCentre->name, y->name )->name, _c, _preserve_color );
146
147 //if_then( _environment, variable_compare_not( _environment, x->name, y->name )->name );
148 plot( _environment, variable_add( _environment, y->name, xCentre->name )->name, variable_add( _environment, x->name, yCentre->name )->name, _c, _preserve_color );
149 plot( _environment, variable_sub( _environment, xCentre->name, y->name )->name, variable_add( _environment, x->name, yCentre->name )->name, _c, _preserve_color );
150 plot( _environment, variable_add( _environment, y->name, xCentre->name )->name, variable_sub( _environment, yCentre->name, x->name )->name, _c, _preserve_color );
151 plot( _environment, variable_sub( _environment, xCentre->name, y->name )->name, variable_sub( _environment, yCentre->name, x->name )->name, _c, _preserve_color );
152
153 //end_if_then( _environment );
154
155 variable_increment( _environment, y->name );
156
157 end_while( _environment );
158
159}
Variable * variable_add(Environment *_environment, char *_source, char *_destination)
Add two variable and return the sum of them.
Variable * variable_less_than_const(Environment *_environment, char *_source, int _destination, int _equal)
Variable * variable_retrieve_or_define(Environment *_environment, char *_name, VariableType _type, int _value)
void variable_decrement(Environment *_environment, char *_source)
Decrement a variable by one.
Variable * variable_less_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_greater_than(Environment *_environment, char *_source, char *_destination, int _equal)
Compare two variable and return the result of comparation.
Variable * variable_move(Environment *_environment, char *_source, char *_destination)
Store the value of a variable inside another variable by converting it.
void variable_increment(Environment *_environment, char *_source)
Increment a variable by one.
Variable * variable_sl_const(Environment *_environment, char *_destination, int _steps)
Variable * variable_sub(Environment *_environment, char *_source, char *_dest)
Make a differenze between two variable and return the difference of them.
Variable * variable_temporary(Environment *_environment, VariableType _type, char *_meaning)
Define a temporary variable.
Variable * variable_store(Environment *_environment, char *_destination, unsigned int _value)
Store a direct value to a variable.
Variable * variable_complement_const(Environment *_environment, char *_source, int _value)
Calculate the complement of a variable.
void plot(Environment *_environment, char *_x, char *_y, char *_c, int _preserve_color)
Definition plot.c:46
void circle(Environment *_environment, char *_x, char *_y, char *_r, char *_c, int _preserve_color)
Emit code for CIRCLE command.
Definition circle.c:105
void else_if_then_label(Environment *_environment)
Emit ASM code for ... ELSE [IF] ....
void else_if_then(Environment *_environment, char *_expression)
Emit ASM code for ... ELSE [IF] ....
void end_if_then(Environment *_environment)
Emit ASM code for ENDIF.
Definition end_if_then.c:50
void exit_loop(Environment *_environment, int _number)
Emit ASM code for EXIT.
Definition exit_loop.c:97
void if_then(Environment *_environment, char *_expression)
Emit ASM code for IF ... THEN ....
Definition if_then.c:123
char * name
Definition ugbc.h:979
struct _Variable Variable
Structure of a single variable.
struct _Environment Environment
Structure of compilation environment.
@ VT_POSITION
Definition ugbc.h:468
@ VT_SWORD
Definition ugbc.h:457
void begin_while_condition(Environment *_environment, char *_expression)
Definition while.c:99
void begin_while(Environment *_environment)
Emit ASM code for WHILE ....
Definition while.c:83
void end_while(Environment *_environment)
Emit ASM code for ... WEND.
Definition while.c:127