@@ -186,91 +186,96 @@ 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
- }
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 ;
198
-
199
- for (x = x1; x <= x2; x++) {
200
- int 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
- }
217
- }
218
-
219
- void ArduinoGraphics::circle (int x, int y, int radius)
220
- {
221
- if (!_stroke && !_fill) {
222
- return ;
223
- }
224
-
225
- int x1 = x;
226
- int y1 = y;
227
- int x2 = x1 + radius;
189
+ if (!_stroke && !_fill) {
190
+ return ;
191
+ }
228
192
229
- for (x = x1; x <= x2; x++) {
230
- int 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
- }
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
+ for (int a = 0 ; a < j; a++)
227
+ {
228
+ int x1 = x-i;
229
+ int x2 = x+i;
230
+ int y1 = y-a;
231
+ int y2 = y+a;
232
+
233
+ if (width%2 == 0 )
234
+ {
235
+ x2--;
236
+ }
237
+
238
+ if (height%2 == 0 )
239
+ {
240
+ y2--;
241
+ }
242
+
243
+ set (x1, y1, _fillR, _fillG, _fillB);
244
+ set (x1, y2, _fillR, _fillG, _fillB);
245
+ set (x2, y1, _fillR, _fillG, _fillB);
246
+ set (x2, y2, _fillR, _fillG, _fillB);
247
+ }
248
+ }
248
249
249
- void ArduinoGraphics::arc (int x, int y, int radiusX, int radiusY, int start, int stop)
250
- {
251
- if (!_stroke && !_fill) {
252
- return ;
253
- }
250
+ for (int j = 0 ; j < r2; j++)
251
+ {
252
+ int i = ceil (sqrt (1 - ((float )(j*j)/(r2*r2))) * r1);
254
253
255
- int x1 = x;
256
- int y1 = y;
254
+ int x1 = x-i;
255
+ int x2 = x+i;
256
+ int y1 = y-j;
257
+ int y2 = y+j;
257
258
258
- for (int a = start; a <= stop; a++) {
259
+ if (width%2 == 0 )
260
+ {
261
+ x2--;
262
+ }
259
263
260
- int x2 = (int )(x1 + (radiusX * cos (a)));
261
- int y2 = (int )(y1 + (radiusY * sin (a)));
264
+ if (height%2 == 0 )
265
+ {
266
+ y2--;
267
+ }
262
268
263
- if (_stroke) {
264
- // stroke
269
+ set (x1, y1, _strokeR, _strokeG, _strokeB);
270
+ set (x1, y2, _strokeR, _strokeG, _strokeB);
271
+ set (x2, y1, _strokeR, _strokeG, _strokeB);
265
272
set (x2, y2, _strokeR, _strokeG, _strokeB);
266
- }
273
+ }
274
+ }
267
275
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
- }
276
+ void ArduinoGraphics::circle (int x, int y, int radius)
277
+ {
278
+ ellipse (x, y, ((radius*2 )-1 ), ((radius*2 )-1 ));
274
279
}
275
280
276
281
void ArduinoGraphics::text (const char * str, int x, int y)
0 commit comments