@@ -192,13 +192,13 @@ void ArduinoGraphics::ellipse(int x, int y, int width, int height)
192
192
193
193
int x1 = x;
194
194
int y1 = y;
195
- int r1 = (width/2 );
196
- int r2 = (height/2 );
195
+ int r1 = (int )( width/2 );
196
+ int r2 = (int )( height/2 );
197
197
int x2 = x1 + r1 - 1 ;
198
198
199
- for (x = x1; x <= x2; x++) {
200
- y2 = y1 + sqrt ((1 - ((x * x)/(r1 * r1)))) * r2;
201
- for (y = y1 ; y <= y2; y++) {
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
202
if ((y == y2) && _stroke) {
203
203
// stroke
204
204
set (x, y, _strokeR, _strokeG, _strokeB); // current point
@@ -216,6 +216,63 @@ void ArduinoGraphics::ellipse(int x, int y, int width, int height)
216
216
}
217
217
}
218
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;
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
+ }
274
+ }
275
+
219
276
void ArduinoGraphics::text (const char * str, int x, int y)
220
277
{
221
278
if (!_font || !_stroke) {
0 commit comments