summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Buland <Mike.Buland@mjfirm.com>2016-10-20 07:20:25 -0600
committerMike Buland <Mike.Buland@mjfirm.com>2016-10-20 07:20:25 -0600
commit5a2fb468527f703cb1d2cb12fd0538498902016f (patch)
tree9d9de7ffd594b951c5fb1702349e9e2c3291afc0
parenta638f876f123cb9c9d3540ce7ff184c097162480 (diff)
downloadlost-5a2fb468527f703cb1d2cb12fd0538498902016f.tar.gz
lost-5a2fb468527f703cb1d2cb12fd0538498902016f.tar.bz2
lost-5a2fb468527f703cb1d2cb12fd0538498902016f.tar.xz
lost-5a2fb468527f703cb1d2cb12fd0538498902016f.zip
We can draw lines now!
-rw-r--r--src/image.cpp30
-rw-r--r--src/image.h3
2 files changed, 33 insertions, 0 deletions
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 @@
5#include <stdlib.h> 5#include <stdlib.h>
6#include <string.h> 6#include <string.h>
7#include <png.h> 7#include <png.h>
8#include <math.h>
8 9
9Image::Image() : 10Image::Image() :
10 iWidth( 0 ), 11 iWidth( 0 ),
@@ -27,6 +28,16 @@ Image::~Image()
27 delete[] pPix; 28 delete[] pPix;
28} 29}
29 30
31int Image::getWidth() const
32{
33 return iWidth;
34}
35
36int Image::getHeight() const
37{
38 return iHeight;
39}
40
30void Image::clear( uint8_t uColor ) 41void Image::clear( uint8_t uColor )
31{ 42{
32 memset( pPix, uColor, iWidth*iHeight ); 43 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
139 set( j, y1, uColor ); 150 set( j, y1, uColor );
140 } 151 }
141 } 152 }
153 else
154 {
155 int xd = x2-x1;
156 int yd = y2-y1;
157 float d = sqrt( xd*xd + yd*yd );
158 float ux = xd/d;
159 float uy = yd/d;
160
161 float x = x1;
162 float y = y1;
163
164 set( (int)x, (int)y, uColor );
165 for( float n = 0.0; n < d; n += 1.0 )
166 {
167 x += ux;
168 y += uy;
169 set( (int)x, (int)y, uColor );
170 }
171 }
142} 172}
143 173
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:
10 Image( int32_t iWidth, int32_t iHeight ); 10 Image( int32_t iWidth, int32_t iHeight );
11 virtual ~Image(); 11 virtual ~Image();
12 12
13 int getWidth() const;
14 int getHeight() const;
15
13 void clear( uint8_t uColor=0 ); 16 void clear( uint8_t uColor=0 );
14 void set( int32_t x, int32_t y, uint8_t iCol ); 17 void set( int32_t x, int32_t y, uint8_t iCol );
15 18