@@ -186,91 +186,102 @@ void ArduinoGraphics::rect(int x, int y, int width, int height)
186
186
187
187
void ArduinoGraphics::ellipse (int x, int y, int width, int height)
188
188
{
189
- if (!_stroke && !_fill) {
190
- return ;
191
- }
189
+ if (!_stroke && !_fill) {
190
+ return ;
191
+ }
192
192
193
- int x1 = x;
194
- int y1 = y;
195
- int r1 = (int )(width/2 );
196
- int r2 = (int )(height/2 );
197
- int x2 = x1 + r1 - 1 ;
193
+ int r1 = (int )(width/2 );
194
+ int r2 = (int )(height/2 );
195
+
196
+ x--;
197
+ y--;
198
+
199
+ for (int i = 0 ; i < r1; i++)
200
+ {
201
+ int j = ceil (sqrt (1 - ((float )(i*i)/(r1*r1))) * r2);
202
+
203
+ int x1 = x-i;
204
+ int x2 = x+i;
205
+ int y1 = y-j;
206
+ int y2 = y+j;
207
+
208
+ if (width%2 == 0 )
209
+ {
210
+ x2--;
211
+ }
212
+
213
+ if (height%2 == 0 )
214
+ {
215
+ y2--;
216
+ }
217
+
218
+ if (_stroke)
219
+ {
220
+ set (x1, y1 , _strokeR, _strokeG, _strokeB);
221
+ set (x1, y2, _strokeR, _strokeG, _strokeB);
222
+ set (x2, y1 , _strokeR, _strokeG, _strokeB);
223
+ set (x2, y2, _strokeR, _strokeG, _strokeB);
224
+ }
225
+
226
+ if (_fill)
227
+ {
228
+ for (int a = 0 ; a < j; a++)
229
+ {
230
+ int x1 = x-i;
231
+ int x2 = x+i;
232
+ int y1 = y-a;
233
+ int y2 = y+a;
234
+
235
+ if (width%2 == 0 )
236
+ {
237
+ x2--;
238
+ }
239
+
240
+ if (height%2 == 0 )
241
+ {
242
+ y2--;
243
+ }
244
+
245
+ set (x1, y1 , _fillR, _fillG, _fillB);
246
+ set (x1, y2, _fillR, _fillG, _fillB);
247
+ set (x2, y1 , _fillR, _fillG, _fillB);
248
+ set (x2, y2, _fillR, _fillG, _fillB);
249
+ }
250
+ }
251
+ }
198
252
199
- for (x = x1; x <= x2; x++) {
200
- y2 = (int ) (y1 + sqrt ((1 - ((x * x)/(r1 * r1)))) * r2);
201
- for (y = y1 ; y <= y2; y++) {
202
- if ((y == y2) && _stroke) {
203
- // stroke
204
- set (x, y, _strokeR, _strokeG, _strokeB); // current point
205
- set (x - (((x - x1) * 2 )), y, _strokeR, _strokeG, _strokeB); // second reflection
206
- set (x, y - (((y - y1 ) * 2 )), _strokeR, _strokeG, _strokeB); // third reflection
207
- set (x - (((x - x1) * 2 )), y - (((y - y1 ) * 2 )), _strokeR, _strokeG, _strokeB); // fourth reflection
208
- } else if (_fill) {
209
- // fill
210
- set (x, y, _fillR, _fillG, _fillB); // current point
211
- set (x - (((x - x1) * 2 )), y, _fillR, _fillG, _fillB); // second reflection
212
- set (x, y - (((y - y1 ) * 2 )), _fillR, _fillG, _fillB); // third reflection
213
- set (x - (((x - x1) * 2 )), y - (((y - y1 ) * 2 )), _fillR, _fillG, _fillB); // fourth reflection
214
- }
215
- }
216
- }
253
+ if (_stroke)
254
+ {
255
+ for (int j = 0 ; j < r2; j++)
256
+ {
257
+ int i = ceil (sqrt (1 - ((float )(j*j)/(r2*r2))) * r1);
258
+
259
+ int x1 = x-i;
260
+ int x2 = x+i;
261
+ int y1 = y-j;
262
+ int y2 = y+j;
263
+
264
+ if (width%2 == 0 )
265
+ {
266
+ x2--;
267
+ }
268
+
269
+ if (height%2 == 0 )
270
+ {
271
+ y2--;
272
+ }
273
+
274
+ set (x1, y1 , _strokeR, _strokeG, _strokeB);
275
+ set (x1, y2, _strokeR, _strokeG, _strokeB);
276
+ set (x2, y1 , _strokeR, _strokeG, _strokeB);
277
+ set (x2, y2, _strokeR, _strokeG, _strokeB);
278
+ }
279
+ }
217
280
}
218
281
219
282
void ArduinoGraphics::circle (int x, int y, int radius)
220
283
{
221
- if (!_stroke && !_fill) {
222
- return ;
223
- }
224
-
225
- int x1 = x;
226
- int y1 = y;
227
- int x2 = x1 + radius;
228
-
229
- for (x = x1; x <= x2; x++) {
230
- y2 = (int ) y1 + sqrt ((radius*radius)-(x*x)) ;
231
- for (y = y1 ; y <= y2; y++) {
232
- if ((y == y2) && _stroke) {
233
- // stroke
234
- set (x, y, _strokeR, _strokeG, _strokeB); // current point
235
- set (x - (((x - x1) * 2 )), y, _strokeR, _strokeG, _strokeB); // second reflection
236
- set (x, y - (((y - y1 ) * 2 )), _strokeR, _strokeG, _strokeB); // third reflection
237
- set (x - (((x - x1) * 2 )), y - (((y - y1 ) * 2 )), _strokeR, _strokeG, _strokeB); // fourth reflection
238
- } else if (_fill) {
239
- // fill
240
- set (x, y, _fillR, _fillG, _fillB); // current point
241
- set (x - (((x - x1) * 2 )), y, _fillR, _fillG, _fillB); // second reflection
242
- set (x, y - (((y - y1 ) * 2 )), _fillR, _fillG, _fillB); // third reflection
243
- set (x - (((x - x1) * 2 )), y - (((y - y1 ) * 2 )), _fillR, _fillG, _fillB); // fourth reflection
244
- }
245
- }
246
- }
247
- }
248
-
249
- void ArduinoGraphics::arc (int x, int y, int radiusX, int radiusY, int start, int stop);
250
- {
251
- if (!_stroke && !_fill) {
252
- return ;
253
- }
254
-
255
- int x1 = x;
256
- int y1 = y;
257
-
258
- for (int a = start; a <= stop; a++) {
259
-
260
- int x2 = (int )(x1 + (radiusX * cos (a)));
261
- int y2 = (int )(y1 + (radiusY * sin (a)));
262
-
263
- if (_stroke) {
264
- // stroke
265
- set (x2, y2, _strokeR, _strokeG, _strokeB);
266
- }
267
-
268
- if (_fill) {
269
- for (int r = 0 ; r < a; r++) {
270
- set ((int )(x1 + (radiusX * cos (r))), (int )(y1 + (radiusY * sin (r))), _fillR, _fillG, _fillB);
271
- }
272
- }
273
- }
284
+ ellipse (x, y, ((radius*2 )-1 ), ((radius*2 )-1 ));
274
285
}
275
286
276
287
void ArduinoGraphics::text (const char * str, int x, int y)
0 commit comments