From 0e327b284f19d29ef261c2a5352fc358913e580a Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 29 Oct 2016 21:25:09 -0700 Subject: [PATCH 1/2] Added get coordinates function to generate sin values. --- src/includes/kernel/util.c | 28 ++++++++++++++++++++++++++++ src/includes/kernel/util.h | 8 +++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/includes/kernel/util.c b/src/includes/kernel/util.c index abbfabe..f4010f8 100644 --- a/src/includes/kernel/util.c +++ b/src/includes/kernel/util.c @@ -42,4 +42,32 @@ void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long p +// Takes a computed sin value and finds what pixel it cooresponds to +int scale_to_y_pixel(double y) +{ + return (int) ((SCREEN_HEIGHT / 2) * (1 - y)); +} + +// Takes a horizontal pixel location and finds where it would be in a normal graph 0 < t < 2pi +double scale_to_x_origin(int x) +{ + return x * 2 * M_PI / SCREEN_WIDTH; +} + + +// Returns the coordinates of the sin function. sin[x] = y coordinate on the horizontal pixel x. +int *getCoordinates() +{ + int x = 0; + int *yCords = (int*) malloc(sizeof(int) * SCREEN_WIDTH); + memset(yCords, 0, SCREEN_WIDTH); + for (x = 0; x < SCREEN_WIDTH; ++x) + { + double float_x = scale_to_x_origin(x); + yCords[x] = scale_to_y_pixel(sin(float_x)); + } + + return yCords; +} + diff --git a/src/includes/kernel/util.h b/src/includes/kernel/util.h index 2a2cbea..62b08b4 100644 --- a/src/includes/kernel/util.h +++ b/src/includes/kernel/util.h @@ -12,6 +12,8 @@ arm-016-util.h #define COLOUR_DELTA 0.05 /* Float from 0 to 1 incremented by this amount */ +#include + typedef struct { float r; float g; @@ -22,4 +24,8 @@ typedef struct { extern void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long pitch); -#endif \ No newline at end of file +int * getCoordinates(); +double scale_to_x_origin(int); +int scale_to_y_pixel(double); + +#endif -- 2.54.0 From 4319688dfb39444d9edcc384e4c56977967cda4b Mon Sep 17 00:00:00 2001 From: Evan Date: Sat, 29 Oct 2016 21:38:07 -0700 Subject: [PATCH 2/2] Include stdlib.h and changed function declaration to extern --- src/includes/kernel/util.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/includes/kernel/util.h b/src/includes/kernel/util.h index 62b08b4..5102783 100644 --- a/src/includes/kernel/util.h +++ b/src/includes/kernel/util.h @@ -13,6 +13,7 @@ arm-016-util.h #define COLOUR_DELTA 0.05 /* Float from 0 to 1 incremented by this amount */ #include +#include typedef struct { float r; @@ -24,8 +25,8 @@ typedef struct { extern void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long pitch); -int * getCoordinates(); -double scale_to_x_origin(int); -int scale_to_y_pixel(double); +extern int * getCoordinates(); +extern double scale_to_x_origin(int); +extern int scale_to_y_pixel(double); #endif -- 2.54.0