Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 5:495d64d8934d, committed 2015-05-01
- Comitter:
- martydd3
- Date:
- Fri May 01 05:25:19 2015 +0000
- Parent:
- 4:75498bd2e742
- Child:
- 6:baece3338bfe
- Commit message:
- Moved all drawing to primative functions
Changed in this revision
--- a/main.cpp Fri May 01 03:26:50 2015 +0000
+++ b/main.cpp Fri May 01 05:25:19 2015 +0000
@@ -3,7 +3,7 @@
#include <string>
#include "constants.h"
-#include "shape.h"
+#include "shape_drawer.h"
// RF tranceiver to link with handheld.
MRF24J40 mrf(p11, p12, p13, p14, p26);
@@ -149,66 +149,19 @@
int displaces[HEIGHT];
-void init_displaces(){
- for(int i = 0; i < HEIGHT; i++){
- switch(i){
- case 0: displaces[i] = 0; break;
- case 1: displaces[i] = 4 * SLICES / 8; break;
- case 2: displaces[i] = 7 * SLICES / 8 - 5; break;
- case 3: displaces[i] = 3 * SLICES / 8 - 8; break;
- case 4: displaces[i] = 6 * SLICES / 8 - 6; break;
- case 5: displaces[i] = 2 * SLICES / 8 - 7; break;
- case 6: displaces[i] = 5 * SLICES / 8 - 7; break;
- case 7: displaces[i] = 1 * SLICES / 8 - 8; break;
- }
- }
-}
-
void convert_array(){
- static bool initialized = false;
- int array_i;
-
- if(!initialized){
- init_displaces();
+ if(frame_id == 0){
+ move_buffer(&frame_buffer2);
+ frame_id = 1;
+ } else {
+ move_buffer(&frame_buffer1);
+ frame_id = 0;
}
-
- for(int i = 0; i < SLICES; i++){
- for(int j = 0; j < WIDTH; j++){
- char bit = 0x00;
-
- for(int h = 0; h < HEIGHT; h++){
- bit |= (work_buffer[(i + displaces[h]) % SLICES][j] & (0x01 << h));
- }
-
- if(frame_id == 0)
- frame_buffer2[i][j] = bit;
- else
- frame_buffer1[i][j] = bit;
- }
- }
-
- if(frame_id == 0)
- frame_id = 1;
- else
- frame_id = 0;
}
int display_mode = 0;
Ticker animate_ticker;
void animate(){
- static WaveCircle *wc1 = NULL;
- static WaveCircle *wc2 = NULL;
- static WaveCircle *wc3 = NULL;
- static WaveCircle *wc4 = NULL;
- static WaveCircle *wc5 = NULL;
- static WaveCircle *wc6 = NULL;
- static WaveCircle *wc7 = NULL;
- static WaveCircle *wc8 = NULL;
- static WaveCircle *wc9 = NULL;
- static WaveCircle *wc10 = NULL;
- static WaveCircle *wc11 = NULL;
- static WaveCircle *wc12 = NULL;
- static WaveCircle *wc13 = NULL;
for(int i = 0; i < SLICES; i++){
for(int j = 0; j < WIDTH; j++){
@@ -218,118 +171,42 @@
if(display_mode == 1)
{
- if(wc1 == NULL){
- wc1 = new WaveCircle(3, 4, &work_buffer);
- wc2 = new WaveCircle(4, 4, &work_buffer);
- wc3 = new WaveCircle(5, 4, &work_buffer);
- wc4 = new WaveCircle(6, 4, &work_buffer);
- wc5 = new WaveCircle(7, 4, &work_buffer);
- wc6 = new WaveCircle(8, 4, &work_buffer);
- wc7 = new WaveCircle(9, 4, &work_buffer);
- wc8 = new WaveCircle(10, 4, &work_buffer);
- wc9 = new WaveCircle(11, 4, &work_buffer);
- wc10 = new WaveCircle(12, 4, &work_buffer);
- wc11 = new WaveCircle(13, 4, &work_buffer);
- wc12 = new WaveCircle(14, 4, &work_buffer);
- wc13 = new WaveCircle(15, 4, &work_buffer);
- }
+ static int disp = 0;
+ for(int i = 3; i < WIDTH; i++){
+ draw_wavecircle(i, 4, disp);
+ }
- wc1->animate();
- wc2->animate();
- wc3->animate();
- wc4->animate();
- wc5->animate();
- wc6->animate();
- wc7->animate();
- wc8->animate();
- wc9->animate();
- wc10->animate();
- wc11->animate();
- wc12->animate();
- wc13->animate();
-
- wc1->draw();
- wc2->draw();
- wc3->draw();
- wc4->draw();
- wc5->draw();
- wc6->draw();
- wc7->draw();
- wc8->draw();
- wc9->draw();
- wc10->draw();
- wc11->draw();
- wc12->draw();
- wc13->draw();
+ disp += 10;
+ if(disp >= SLICES){
+ disp = 0;
+ }
}
else if(display_mode == 2)
{
- Line line1(10, 10, 0, 10, -10, 0, &work_buffer);
- Line line2(10, -10, 0, -10, -10, 0, &work_buffer);
- Line line3(-10, -10, 0, -10, 10, 0, &work_buffer);
- Line line4(-10, 10, 0, 10, 10, 0, &work_buffer);
-
- line1.draw();
- line2.draw();
- line3.draw();
- line4.draw();
-
- Line line5(10, 10, 7, 10, -10, 7, &work_buffer);
- Line line6(10, -10, 7, -10, -10, 7, &work_buffer);
- Line line7(-10, -10, 7, -10, 10, 7, &work_buffer);
- Line line8(-10, 10, 7, 10, 10, 7, &work_buffer);
+ draw_line(10, 10, 0, 10, -10, 0);
+ draw_line(10, -10, 0, -10, -10, 0);
+ draw_line(-10, -10, 0, -10, 10, 0);
+ draw_line(-10, 10, 0, 10, 10, 0);
+
+ draw_line(10, 10, 7, 10, -10, 7);
+ draw_line(10, -10, 7, -10, -10, 7);
+ draw_line(-10, -10, 7, -10, 10, 7);
+ draw_line(-10, 10, 7, 10, 10, 7);
- line5.draw();
- line6.draw();
- line7.draw();
- line8.draw();
-
- Line line9(10, 10, 0, 10, 10, 7, &work_buffer);
- Line line10(10, -10, 0, 10, -10, 7, &work_buffer);
- Line line11(-10, -10, 0, -10, -10, 7, &work_buffer);
- Line line12(-10, 10, 0, -10, 10, 7, &work_buffer);
-
- line9.draw();
- line10.draw();
- line11.draw();
- line12.draw();
+ draw_line(10, 10, 0, 10, 10, 7);
+ draw_line(10, -10, 0, 10, -10, 7);
+ draw_line(-10, -10, 0, -10, -10, 7);
+ draw_line(-10, 10, 0, -10, 10, 7);
+
}
else if(display_mode == 3)
{
} else if(display_mode == 4){
-
- Line line1(0, 16, 0, 0, -16, 7, &work_buffer);
- Line line2(4, 16, 0, 4, -16, 7, &work_buffer);
- Line line3(8, 16, 0, 8, -16, 7, &work_buffer);
- Line line4(12, 16, 0, 12, -16, 7, &work_buffer);
- Line line5(-4, 16, 0, -4, -16, 7, &work_buffer);
- Line line6(-8, 16, 0, -8, -16, 7, &work_buffer);
- Line line7(-12, 16, 0, -12, -16, 7, &work_buffer);
-
- line1.draw();
- line2.draw();
- line3.draw();
- line4.draw();
- line5.draw();
- line6.draw();
- line7.draw();
-
- Line line11(16, 4, 0, -16, 4, 7, &work_buffer);
- Line line21(16, 8, 0, -16, 8, 7, &work_buffer);
- Line line31(16, 12, 0, -16, 12, 7, &work_buffer);
- Line line41(16, 0, 0, -16, 0, 7, &work_buffer);
- Line line51(16, -4, 0, -16, -4, 7, &work_buffer);
- Line line61(16, -8, 0, -16, -8, 7, &work_buffer);
- Line line71(16, -12, 0, -16, -12, 7, &work_buffer);
-
- line11.draw();
- line21.draw();
- line31.draw();
- line41.draw();
- line51.draw();
- line61.draw();
- line71.draw();
+ for(int i = -12; i < 13; i += 4){
+ draw_line(i, 16, 0, i, -16, 0);
+ draw_line(16, i, 0, -16, i, 0);
+ }
}
convert_array();
@@ -342,7 +219,7 @@
int main (void)
{
- display_mode = 2;
+ display_mode = 1;
InterruptIn hall_pin(p25);
hall_pin.fall(&rotate_sense);
--- a/shape.cpp Fri May 01 03:26:50 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,307 +0,0 @@
-#include "shape.h"
-#include "constants.h"
-#include <math.h>
-#include "mbed.h"
-
-
-
-void Circle::draw(){
- uint8_t s = (0x01 << height);
- for(int i = 0; i < SLICES; i++){
- (*buffer)[i][radius] |= s;
- }
-}
-
-bool Circle::remove(){
- return radius < 0 || radius >= WIDTH || height < 0 || height >= HEIGHT;
-}
-
-/*
-*********************************************************************************
-*/
-
-void WaveCircle::draw(){
- float h;
- for(int i = 0; i < SLICES; i++){
- h = 3.5*sin(2.0 * M_PI * (i + displace) * freq / SLICES) + 3.5;
- (*buffer)[i][radius] |= (0x01 << (int)rint(h));
- }
-}
-
-void WaveCircle::animate(){
- displace += 10;
- if(displace >= SLICES)
- displace = 0;
-}
-
-bool WaveCircle::remove(){
- return radius < 0 || radius >= WIDTH;
-}
-
-/*********************************************************************/
-
-//coordinates in Line are cartesian
-//on display, 0 - 90 degrees is 1st quadrant, 180 to 270 is 3rd
-
-//Lines in polar coordinates have 2 types, through the origin and displaced
-
-//remember identies, x = r cos p, y = r sin p, z = z
-
-//For line y = mx + b, r sin p = m r cos p + b, r = b / (sin p - m cos p)
-
-void Line::draw(){
- //Perfectly vertical lines
- if(x1 == x2 && y1 == y2){
- float r = sqrt(1.0*x1*x1 + 1.0*y1*y1);
- float p = asin(1.0*y1/r);
-
- if(x1 < 0)
- p = M_PI - p;
-
- //set p to 0 - 2p range, and convert to slice index
- p = p < 0 ? p + 2 * M_PI : p;
- p = p * SLICES / (2 * M_PI);
-
- int i = z1;
- while(true){
- (*buffer)[(int)rint(p)][(int)rint(r)] |= (0x01 << i);
-
- if(i == z2)
- break;
-
- i = z1 > z2 ? i - 1 : i + 1;
- }
- }
-
- //Perfectly horizontal lines through origin
- else if(y1 == 0 && y2 == 0){
- float m = (1.0*z2 - 1.0*z1)/(1.0*x2 - 1.0*x1);
- float h = z1;
-
- int i = x1;
- while(true){
- h = z1 + m * (i - x1);
-
- if(i >= 0){
- (*buffer)[0][i] |= (0x01 << (int)rint(h));
- } else if(i <= 0){
- (*buffer)[SLICES / 2 - 1][-i] |= (0x01 << (int)rint(h));
- }
-
- if(i == x2)
- break;
-
- i = x1 > x2 ? i - 1 : i + 1;
- }
- }
-
- //Perfectly vertical lines through origin
- else if(x1 == 0 && x2 == 0){
- float m = (1.0*z2 - 1.0*z1)/(1.0*y2 - 1.0*y1);
- float h = z1;
-
- int i = y1;
- while(true){
- h = z1 + m * (i - y1);
-
- if(i >= 0){
- (*buffer)[SLICES / 4 - 1][i] |= (0x01 << (int)rint(h));
- } else if(i <= 0){
- (*buffer)[3 * SLICES / 4 - 1][-i] |= (0x01 << (int)rint(h));
- }
-
- if(i == y2)
- break;
-
- i = y1 > y2 ? i - 1 : i + 1;
- }
- }
-
- //For line y = mx + b, r sin p = m r cos p + b, r = b / (sin p - m cos p)
- //if m = 0, then r = b / sin p
-
- //Perfectly horizontal lines
- else if(y1 == y2){
- float b = y1;
- float p1 = atan2(y1, x1);
- float p2 = atan2(y2, x2);
-
- p1 = p1 < 0 ? p1 + 2 * M_PI : p1;
- p2 = p2 < 0 ? p2 + 2 * M_PI : p2;
-
- int i1 = (int)rint(p1 * SLICES / (2 * M_PI));
- int i2 = (int)rint(p2 * SLICES / (2 * M_PI));
-
- float m = (z2 - z1)/(x2 - x1);
-
- while(true){
-
- float p = i1 * 2 * M_PI / SLICES;
- float r = b / sin(p);
- float x = y1 / tan(p);
- float h = z1 + m * (x - x1);
-
- if((int)rint(r) < WIDTH)
- (*buffer)[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
-
- if(i1 == i2)
- break;
-
- if(abs(i1 - i2) > SLICES / 2){
- i1 = i1 > i2 ? i1 + 1 : i1 - 1;
- } else {
- i1 = i1 > i2 ? i1 - 1 : i1 + 1;
- }
-
- if(i1 == SLICES)
- i1 = 0;
-
- if(i1 == -1)
- i1 = SLICES - 1;
- }
- }
-
- //Perfectly vertical lines
- // r = b / r cos p
- else if(x1 == x2){
- float b = x1;
- float p1 = atan2(y1, x1);
- float p2 = atan2(y2, x2);
-
- p1 = p1 < 0 ? p1 + 2 * M_PI : p1;
- p2 = p2 < 0 ? p2 + 2 * M_PI : p2;
-
- int i1 = (int)rint(p1 * SLICES / (2 * M_PI));
- int i2 = (int)rint(p2 * SLICES / (2 * M_PI));
-
- float m = (z2 - z1)/(y2 - y1);
-
- while(true){
- float p = i1 * 2 * M_PI / SLICES;
- float r = b / cos(p);
- float y = x1 * tan(p);
- float h = z1 + m * (y - y1);
-
- if((int)rint(r) < WIDTH)
- (*buffer)[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
-
- if(i1 == i2)
- break;
-
- if(abs(i1 - i2) > SLICES / 2){
- i1 = i1 > i2 ? i1 + 1 : i1 - 1;
- } else {
- i1 = i1 > i2 ? i1 - 1 : i1 + 1;
- }
-
- if(i1 == SLICES)
- i1 = 0;
- if(i1 == -1)
- i1 = SLICES - 1;
- }
- }
-
- //Arbitrary lines
- // y = mx + b,
- // r = b / (sin p - m cos p)
- //
- // if m is close to infinity, better to use
- // x = ny + c
- // r = c / (cos p - n sin p)
- else {
- float m_1 = 1.0*(y2 - y1)/(x2 - x1);
- float m_2 = 1.0*(x2 - x1)/(y2 - y1);
- float d = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
- float m_h = (z2 - z1)/d;
- float m, p1, p2, b, h;
-
- //x = m_2 y + b is steeper than y = m_1 x + b
- if(abs(m_2) > abs(m_1)){
- m = m_1;
- p1 = atan2(y1, x1);
- p2 = atan2(y2, x2);
-
- p1 = p1 < 0 ? p1 + 2 * M_PI : p1;
- p2 = p2 < 0 ? p2 + 2 * M_PI : p2;
-
- b = y1 - m * x1;
- h = z1;
-
- int i1 = (int)rint(p1 * SLICES / (2 * M_PI));
- int i2 = (int)rint(p2 * SLICES / (2 * M_PI));
-
- while(true){
- float p = i1 * 2 * M_PI / SLICES;
- float r = b / (sin(p) - m * cos(p));
-
- float dx = r * cos(p);
- float dy = r * sin(p);
-
- float dd = sqrt((x1 - dx)*(x1 - dx) + (y1 - dy)*(y1 - dy));
- h = z1 + m_h * dd;
-
- if((int)rint(r) < WIDTH)
- (*buffer)[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
-
- if(i1 == i2)
- break;
-
- if(abs(i1 - i2) > SLICES / 2){
- i1 = i1 > i2 ? i1 + 1 : i1 - 1;
- } else {
- i1 = i1 > i2 ? i1 - 1 : i1 + 1;
- }
-
- if(i1 == SLICES)
- i1 = 0;
- if(i1 == -1)
- i1 = SLICES - 1;
- }
- } else {
- m = m_2;
- p1 = atan2(y1, x1);
- p2 = atan2(y2, x2);
-
- p1 = p1 < 0 ? p1 + 2 * M_PI : p1;
- p2 = p2 < 0 ? p2 + 2 * M_PI : p2;
-
- b = x1 - m * y1;
- h = z1;
-
- int i1 = (int)rint(p1 * SLICES / (2 * M_PI));
- int i2 = (int)rint(p2 * SLICES / (2 * M_PI));
-
- while(true){
- float p = i1 * 2 * M_PI / SLICES;
- float r = b / (cos(p) - m * sin(p));
-
- float dx = r * cos(p);
- float dy = r * sin(p);
-
- float dd = sqrt((x1 - dx)*(x1 - dx) + (y1 - dy)*(y1 - dy));
- h = z1 + m_h * dd;
-
- if((int)rint(r) < WIDTH)
- (*buffer)[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
-
- if(i1 == i2)
- break;
-
- if(abs(i1 - i2) > SLICES / 2){
- i1 = i1 > i2 ? i1 + 1 : i1 - 1;
- } else {
- i1 = i1 > i2 ? i1 - 1 : i1 + 1;
- }
-
- if(i1 == SLICES)
- i1 = 0;
- if(i1 == -1)
- i1 = SLICES - 1;
- }
- }
- }
-}
-
-bool Line::remove(){
- return true;
-}
\ No newline at end of file
--- a/shape.h Fri May 01 03:26:50 2015 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-#ifndef SHAPE
-#define SHAPE
-
-#include "mbed.h"
-#include "constants.h"
-
-class Shape {
- protected:
- char (*buffer)[SLICES][WIDTH];
- public:
- Shape(char (*b)[SLICES][WIDTH]): buffer(b){};
- virtual void draw(void) = 0;
- virtual bool remove(void) = 0;
-};
-
-class Circle: public Shape {
- protected:
- int radius, height;
- public:
- Circle(int r, int h, char (*b)[SLICES][WIDTH]) : Shape(b), radius(r), height(h){};
- void draw();
- bool remove();
-};
-
-class WaveCircle: public Shape {
- protected:
- int radius, freq, displace;
- public:
- WaveCircle(int r, int freq, char (*b)[SLICES][WIDTH]) : Shape(b), radius(r), freq(freq), displace(0){};
- void animate();
- void draw();
- bool remove();
-};
-
-class Line: public Shape {
- protected:
- float x1, y1, z1, x2, y2, z2;
- public:
- Line(float x1, float y1, float z1, float x2, float y2, float z2, char(*b)[SLICES][WIDTH]):
- Shape(b), x1(x1), y1(y1), z1(z1), x2(x2), y2(y2), z2(z2) {};
- void draw();
- bool remove();
-};
-
-#endif
\ No newline at end of file
--- a/shape_drawer.cpp Fri May 01 03:26:50 2015 +0000
+++ b/shape_drawer.cpp Fri May 01 05:25:19 2015 +0000
@@ -1,3 +1,280 @@
#include "constants.h"
+#include "mbed.h"
+#include <math.h>
+
+static char work_buffer[SLICES][WIDTH];
+
+static void erase(){
+ for(int i = 0; i < SLICES; i++){
+ for(int j = 0; j < WIDTH; j++){
+ work_buffer[i][j] = 0x00;
+ }
+ }
+}
+
+void draw_circle(float r, float h){
+ for(int i = 0; i < SLICES; i++){
+ work_buffer[i][(int)rint(r)] |= (0x01 << (int)rint(h));
+ }
+}
+
+void draw_wavecircle(float r, float freq, float disp){
+ for(int i = 0; i < SLICES; i++){
+ float h = 3.5*sin(2.0 * M_PI * (i + disp) * freq / SLICES) + 3.5;
+ work_buffer[i][(int)rint(r)] |= (0x01 << (int)rint(h));
+ }
+}
+
+#define VERT 1
+#define HORZ 0
+
+static void draw_zvert_line(float x, float y, float z1, float z2);
+static void draw_orig_line(float x1, float x2, float z1, float z2, int ori);
+static void draw_perp_line(float a1, float a2, float b, float z1, float z2, int ori);
+static void draw_arb_line(float x1, float x2, float y1, float y2, float z1, float z2);
+
+static void norm_angle(float &p){
+ p = p < 0 ? p + 2 * M_PI : p;
+ p = p > 2 * M_PI ? p - 2 * M_PI : p;
+}
+
+static float deg2rad(float p){
+ return 2 * M_PI * p / SLICES;
+}
+
+static float rad2deg(float p){
+ return p * SLICES / (2 * M_PI);
+}
+
+static void step_i(float a, float b, int &i){
+ float diff = abs(a - b);
+ if(diff > SLICES / 2)
+ i = a > b ? i + 1: i - 1;
+ else
+ i = a > b ? i - 1: i + 1;
+
+ i = (i == SLICES) ? 0 : i;
+ i = (i == -1) ? SLICES - 1 : i;
+}
+
+void draw_line(float x1, float y1, float z1, float x2, float y2, float z2){
+
+ //Perfectly vertical depth lines
+ if(x1 == x2 && y1 == y2){
+ draw_zvert_line(x1, y1, z1, z2);
+ }
+
+ //Perfectly horizontal lines through origin
+ else if(y1 == 0 && y2 == 0){
+ draw_orig_line(x1, x2, z1, z2, HORZ);
+ }
+
+ //Perfectly vertical lines through origin
+ else if(x1 == 0 && x2 == 0){
+ draw_orig_line(y1, y2, z1, z2, VERT);
+ }
+
+ //Perfectly horizontal lines
+ else if(y1 == y2){
+ draw_perp_line(x1, x2, y1, z1, z2, HORZ);
+ }
+
+ //Perfectly vertical lines
+ // r = b / r cos p
+ else if(x1 == x2){
+ draw_perp_line(y1, y2, x1, z1, z2, VERT);
+ }
+
+ //Arbitrary lines
+ else {
+ draw_arb_line(x1, x2, y1, y2, z1, z2);
+ }
+}
-static char
\ No newline at end of file
+static void draw_arb_line(float x1, float x2, float y1, float y2, float z1, float z2){
+ // y = mx + b,
+ // r = b / (sin p - m cos p)
+ //
+ // if m is close to infinity, better to use
+ // x = ny + c
+ // r = c / (cos p - n sin p)
+
+ float m_1 = 1.0*(y2 - y1)/(x2 - x1);
+ float m_2 = 1.0*(x2 - x1)/(y2 - y1);
+ float d = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+ float m_h = (z2 - z1)/d;
+ float m, p1, p2, b, h;
+ int ori;
+
+ //x = m_2 y + b is steeper than y = m_1 x + b
+ if(abs(m_2) > abs(m_1)){
+ m = m_1;
+ b = y1 - m * x1;
+ ori = HORZ;
+ } else {
+ m = m_2;
+ b = x1 - m * y1;
+ ori = VERT;
+ }
+
+ p1 = atan2(y1, x1);
+ p2 = atan2(y2, x2);
+
+ norm_angle(p1);
+ norm_angle(p2);
+
+ h = z1;
+
+ int i1 = rad2deg(p1);
+ int i2 = rad2deg(p2);
+
+ while(true){
+ float p = deg2rad(i1);
+ float r = (ori == HORZ) ? b / (sin(p) - m * cos(p)) : b / (cos(p) - m * sin(p));
+
+ float dx = r * cos(p);
+ float dy = r * sin(p);
+
+ float dd = sqrt((x1 - dx)*(x1 - dx) + (y1 - dy)*(y1 - dy));
+ h = z1 + m_h * dd;
+
+ if((int)rint(r) < WIDTH)
+ work_buffer[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
+
+ if(i1 == i2)
+ break;
+
+ step_i(i1, i2, i1);
+ }
+}
+
+static void draw_perp_line(float a1, float a2, float b, float z1, float z2, int ori){
+ float p1 = (ori == HORZ) ? atan2(b, a1) : atan2(a1, b);
+ float p2 = (ori == HORZ) ? atan2(b, a2) : atan2(a2, b);
+
+ norm_angle(p1);
+ norm_angle(p2);
+
+ int i1 = rad2deg(p1);
+ int i2 = rad2deg(p2);
+
+ float m = (z2 - z1)/(a2 - a1);
+
+ while(true){
+ float p = deg2rad(i1);
+ float r = (ori == HORZ) ? b / sin(p) : b / cos(p);
+ float d = (ori == HORZ) ? b / tan(p) : b * tan(p);
+ float h = z1 + m * (d - a1);
+
+ if((int)rint(r) < WIDTH)
+ work_buffer[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
+
+ if(i1 == i2)
+ break;
+
+ step_i(i1, i2, i1);
+ }
+}
+
+static void draw_orig_line(float r1, float r2, float z1, float z2, int ori){
+ int p1, p2;
+ float m;
+
+ if(ori == HORZ){
+ p1 = 0;
+ p2 = SLICES / 2 - 1;
+ m = (1.0*z2 - 1.0*z1)/(1.0*r2 - 1.0*r1);
+ } else {
+ p1 = SLICES / 4 - 1;
+ p2 = 3 * SLICES / 4 - 1;
+ m = (1.0*z2 - 1.0*z1)/(1.0*r2 - 1.0*r1);
+ }
+
+ int i = r1;
+ while(true){
+ float h = z1 + m * (i - r1);
+
+ if(i >= 0){
+ work_buffer[p1][i] |= (0x01 << (int)rint(h));
+ } else if(i <= 0){
+ work_buffer[p2][-i] |= (0x01 << (int)rint(h));
+ }
+
+ if(i == r2)
+ break;
+
+ printf("i: %d, h: %d\n", i, (int)rint(h));
+
+ i = r1 > r2 ? i - 1 : i + 1;
+ }
+}
+
+static void draw_zvert_line(float x, float y, float z1, float z2){
+ float r = sqrt(1.0*x*x + 1.0*y*y);
+ float p = atan2(y, x);
+
+ //set p to 0 - 2p range, and convert to slice index
+ norm_angle(p);
+ p = rad2deg(p);
+
+ int i = z1;
+ while(true){
+ work_buffer[(int)rint(p)][(int)rint(r)] |= (0x01 << i);
+
+ if(i == z2)
+ break;
+
+ step_i(z1, z2, i);
+ }
+}
+
+/*
+ Moves shapes in work_buffer over to display_buffer in a format that accounts for
+ displaced blades on display
+*/
+static void init_displacements();
+static int displacements[HEIGHT];
+
+void move_buffer(char (*buffer)[SLICES][WIDTH]){
+ static bool initialized = false;
+
+ if(!initialized){
+ init_displacements();
+ }
+
+ for(int i = 0; i < SLICES; i++){
+ for(int j = 0; j < WIDTH; j++){
+ char bit = 0x00;
+
+ for(int h = 0; h < HEIGHT; h++){
+ bit |= (work_buffer[(i + displacements[h]) % SLICES][j] & (0x01 << h));
+ }
+
+ (*buffer)[i][j] = bit;
+ }
+ }
+
+ erase();
+}
+
+/*
+ Initializes buffer used to adjust for vertical misalignment of display blades
+*/
+static void init_displacements(){
+
+ for(int i = 0; i < HEIGHT; i++){
+ switch(i){
+ case 0: displacements[i] = 0; break;
+ case 1: displacements[i] = 4 * SLICES / 8; break;
+ case 2: displacements[i] = 7 * SLICES / 8 - 5; break;
+ case 3: displacements[i] = 3 * SLICES / 8 - 8; break;
+ case 4: displacements[i] = 6 * SLICES / 8 - 6; break;
+ case 5: displacements[i] = 2 * SLICES / 8 - 7; break;
+ case 6: displacements[i] = 5 * SLICES / 8 - 7; break;
+ case 7: displacements[i] = 1 * SLICES / 8 - 8; break;
+ }
+ }
+}
+
+
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/shape_drawer.h Fri May 01 05:25:19 2015 +0000 @@ -0,0 +1,13 @@ +#ifndef SHAPE_DRAWER +#define SHAPE_DRAWER + +#include "constants.h" + +void move_buffer(char (*buffer)[SLICES][WIDTH]); + +void draw_circle(float r, float h); +void draw_wavecircle(float r, float freq, float disp); + +void draw_line(float x1, float y1, float z1, float x2, float y2, float z2); + +#endif \ No newline at end of file