From 5a2fb468527f703cb1d2cb12fd0538498902016f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 20 Oct 2016 07:20:25 -0600 Subject: We can draw lines now! --- src/image.cpp | 30 ++++++++++++++++++++++++++++++ src/image.h | 3 +++ 2 files changed, 33 insertions(+) diff --git a/src/image.cpp b/src/image.cpp index 384de9a..122df65 100644 --- a/src/image.cpp +++ b/src/image.cpp @@ -5,6 +5,7 @@ #include #include #include +#include Image::Image() : iWidth( 0 ), @@ -27,6 +28,16 @@ Image::~Image() delete[] pPix; } +int Image::getWidth() const +{ + return iWidth; +} + +int Image::getHeight() const +{ + return iHeight; +} + void Image::clear( uint8_t uColor ) { memset( pPix, uColor, iWidth*iHeight ); @@ -139,5 +150,24 @@ void Image::drawLine( int32_t x1, int32_t y1, int32_t x2, int32_t y2, uint8_t uC set( j, y1, uColor ); } } + else + { + int xd = x2-x1; + int yd = y2-y1; + float d = sqrt( xd*xd + yd*yd ); + float ux = xd/d; + float uy = yd/d; + + float x = x1; + float y = y1; + + set( (int)x, (int)y, uColor ); + for( float n = 0.0; n < d; n += 1.0 ) + { + x += ux; + y += uy; + set( (int)x, (int)y, uColor ); + } + } } diff --git a/src/image.h b/src/image.h index cdc13e0..e107712 100644 --- a/src/image.h +++ b/src/image.h @@ -10,6 +10,9 @@ public: Image( int32_t iWidth, int32_t iHeight ); virtual ~Image(); + int getWidth() const; + int getHeight() const; + void clear( uint8_t uColor=0 ); void set( int32_t x, int32_t y, uint8_t iCol ); -- cgit v1.2.3