@@ -195,7 +195,8 @@ class MutableLEDImage : public LEDImageBase<PixelType> {
195
195
196
196
using LEDImageBase<PixelType>::pixel;
197
197
PixelType& pixel ( int row, int column );
198
-
198
+ void setPixel ( int row, int column, PixelType color );
199
+
199
200
void placeImageAt ( const LEDImageBase<PixelType>& image, int row, int column );
200
201
void paintColor ( PixelType color );
201
202
void drawLine (
@@ -214,6 +215,13 @@ class MutableLEDImage : public LEDImageBase<PixelType> {
214
215
bool fill = true
215
216
);
216
217
218
+ void drawCircle (
219
+ int centerRow,
220
+ int centerColumn,
221
+ int radius,
222
+ PixelType color,
223
+ bool fill = true
224
+ );
217
225
};
218
226
219
227
template <class PixelType , PixelType LEDBlackColor, PixelType LEDTransparentColor>
@@ -282,6 +290,23 @@ PixelType& MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::pixel(
282
290
return _data[row*this ->columns () + column];
283
291
}
284
292
293
+ template <class PixelType , PixelType LEDBlackColor, PixelType LEDTransparentColor>
294
+ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::setPixel(
295
+ int row,
296
+ int column,
297
+ PixelType color
298
+ ) {
299
+ if ( (row < 0 )
300
+ ||(column < 0 )
301
+ ||(row >= this ->rows ())
302
+ ||(column >= this ->columns ())
303
+ ) {
304
+ return ;
305
+ }
306
+
307
+ this ->pixel (row, column) = color;
308
+ }
309
+
285
310
template <class PixelType , PixelType LEDBlackColor, PixelType LEDTransparentColor>
286
311
void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::placeImageAt(
287
312
const LEDImageBase<PixelType>& image,
@@ -345,6 +370,15 @@ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawLine(
345
370
PixelType color
346
371
)
347
372
{
373
+ if (
374
+ ((startRow < 0 )&&(stopRow < 0 ))
375
+ ||((startRow >= this ->rows ())&&(stopRow >= this ->rows ()))
376
+ ||((startColumn < 0 )&&(stopColumn < 0 ))
377
+ ||((startColumn >= this ->columns ())&&(stopColumn >= this ->columns ()))
378
+ ) {
379
+ // the line is assuredly completely off screen. do nothing
380
+ return ;
381
+ }
348
382
_dirty = true ;
349
383
if ( stopColumn != startColumn ) {
350
384
float delta_col = stopColumn - startColumn;
@@ -356,7 +390,7 @@ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawLine(
356
390
delta_col < 0 ? col-- : col++ )
357
391
{
358
392
int row = round (startRow + delta_row*(col - startColumn)/delta_col);
359
- this ->pixel (row,col) = color;
393
+ this ->setPixel (row, col, color) ;
360
394
}
361
395
}
362
396
else {
@@ -365,7 +399,7 @@ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawLine(
365
399
delta_row < 0 ? row-- : row++ )
366
400
{
367
401
int col = round (startColumn + delta_col*(row - startRow)/delta_row);
368
- this ->pixel (row,col) = color;
402
+ this ->setPixel (row, col, color) ;
369
403
}
370
404
371
405
}
@@ -377,7 +411,7 @@ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawLine(
377
411
delta_row < 0 ? row >= stopRow : row <= stopRow;
378
412
delta_row < 0 ? row-- : row++ )
379
413
{
380
- this ->pixel (row,startColumn) = color;
414
+ this ->setPixel (row, startColumn, color) ;
381
415
}
382
416
}
383
417
}
@@ -418,4 +452,88 @@ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawRectangle
418
452
}
419
453
}
420
454
455
+ template <class PixelType , PixelType LEDBlackColor, PixelType LEDTransparentColor>
456
+ void MutableLEDImage<PixelType,LEDBlackColor,LEDTransparentColor>::drawCircle(
457
+ int cRow,
458
+ int cCol,
459
+ int radius,
460
+ PixelType color,
461
+ bool fill
462
+ )
463
+ {
464
+ if (radius == 0 ) {
465
+ this ->setPixel (cRow, cCol, color);
466
+ return ;
467
+ }
468
+
469
+
470
+ this ->setPixel (cRow + radius, cCol, color);
471
+ this ->setPixel (cRow - radius, cCol, color);
472
+ this ->setPixel (cRow, cCol + radius, color);
473
+ this ->setPixel (cRow, cCol - radius, color);
474
+
475
+ int r2 = radius*radius;
476
+ int x = 1 ;
477
+ int y = (int )(sqrtf (r2 - 1 ) + 0.5 );
478
+ while (x < y){
479
+ if (fill) {
480
+ this ->drawLine (
481
+ cRow + y, cCol + x,
482
+ cRow - y, cCol + x,
483
+ color
484
+ );
485
+ this ->drawLine (
486
+ cRow + y, cCol - x,
487
+ cRow - y, cCol - x,
488
+ color
489
+ );
490
+ this ->drawLine (
491
+ cRow + x, cCol + y,
492
+ cRow - x, cCol + y,
493
+ color
494
+ );
495
+ this ->drawLine (
496
+ cRow + x, cCol - y,
497
+ cRow - x, cCol - y,
498
+ color
499
+ );
500
+ } else {
501
+ this ->setPixel (cRow + y, cCol + x, color);
502
+ this ->setPixel (cRow + y, cCol - x, color);
503
+ this ->setPixel (cRow - y, cCol + x, color);
504
+ this ->setPixel (cRow - y, cCol - x, color);
505
+ this ->setPixel (cRow + x, cCol + y, color);
506
+ this ->setPixel (cRow + x, cCol - y, color);
507
+ this ->setPixel (cRow - x, cCol + y, color);
508
+ this ->setPixel (cRow - x, cCol - y, color);
509
+ }
510
+
511
+ x += 1 ;
512
+ y = (int )(sqrtf (r2 - x*x) + 0.5 );
513
+ }
514
+
515
+ if (x == y) {
516
+ if (fill) {
517
+ this ->drawLine (
518
+ cRow + y, cCol + x,
519
+ cRow - y, cCol + x,
520
+ color
521
+ );
522
+ this ->drawLine (
523
+ cRow + y, cCol - x,
524
+ cRow - y, cCol - x,
525
+ color
526
+ );
527
+ } else {
528
+ this ->setPixel (cRow + y, cCol + x, color);
529
+ this ->setPixel (cRow + y, cCol - x, color);
530
+ this ->setPixel (cRow - y, cCol + x, color);
531
+ this ->setPixel (cRow - y, cCol - x, color);
532
+ }
533
+ }
534
+
535
+ if (fill) {
536
+ this ->drawCircle (cRow, cCol, radius-1 , color, fill);
537
+ }
538
+ }
421
539
#endif // __LEDIMAGE_H__
0 commit comments