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.
Diff: shape_drawer.cpp
- Revision:
- 6:baece3338bfe
- Parent:
- 5:495d64d8934d
- Child:
- 7:2db895370298
diff -r 495d64d8934d -r baece3338bfe shape_drawer.cpp
--- a/shape_drawer.cpp Fri May 01 05:25:19 2015 +0000
+++ b/shape_drawer.cpp Fri May 01 06:46:08 2015 +0000
@@ -3,6 +3,7 @@
#include <math.h>
static char work_buffer[SLICES][WIDTH];
+static int (*height)(float d) = NULL;
static void erase(){
for(int i = 0; i < SLICES; i++){
@@ -12,17 +13,21 @@
}
}
-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_point(float x1, float y1, float z1, float x2, float y2, float z2, float r){
+
}
-void draw_wavecircle(float r, float freq, float disp){
+void draw_circle(float r, float _h){
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));
- }
+ float h;
+
+ if(height != NULL)
+ h = height(1.0 * i / SLICES);
+ else
+ h = _h;
+
+ work_buffer[i][(int)rint(r)] |= (0x01 << (int)rint(h));
+ }
}
#define VERT 1
@@ -57,6 +62,10 @@
i = (i == -1) ? SLICES - 1 : i;
}
+void set_hfunc(int (*h)(float d)){
+ height = h;
+}
+
void draw_line(float x1, float y1, float z1, float x2, float y2, float z2){
//Perfectly vertical depth lines
@@ -102,7 +111,7 @@
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 slope = (z2 - z1) / d;
float m, p1, p2, b, h;
int ori;
@@ -123,8 +132,6 @@
norm_angle(p1);
norm_angle(p2);
- h = z1;
-
int i1 = rad2deg(p1);
int i2 = rad2deg(p2);
@@ -136,7 +143,11 @@
float dy = r * sin(p);
float dd = sqrt((x1 - dx)*(x1 - dx) + (y1 - dy)*(y1 - dy));
- h = z1 + m_h * dd;
+
+ if(height != NULL)
+ h = height(dd / d);
+ else
+ h = z1 + slope * d;
if((int)rint(r) < WIDTH)
work_buffer[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
@@ -164,7 +175,12 @@
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);
+ float h;
+
+ if(height != NULL)
+ h = height(d / (a2 - a1));
+ else
+ h = z1 + m * (d - a1);
if((int)rint(r) < WIDTH)
work_buffer[i1][(int)rint(r)] |= (0x01 << (int)rint(h));
@@ -192,7 +208,12 @@
int i = r1;
while(true){
- float h = z1 + m * (i - r1);
+ float h;
+
+ if(height != NULL)
+ h = height(i / (r2 - r1));
+ else
+ h = z1 + m * (i - r1);
if(i >= 0){
work_buffer[p1][i] |= (0x01 << (int)rint(h));