Added get coordinates function to generate sin values. #1

Merged
ewilbur merged 2 commits from bitchesbaby into master 2016-10-29 21:40:33 -07:00
2 changed files with 36 additions and 1 deletions

No files matched your search

+28
View File
@@ -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;
}
+8 -1
View File
@@ -12,6 +12,9 @@ arm-016-util.h
#define COLOUR_DELTA 0.05 /* Float from 0 to 1 incremented by this amount */
#include <math.h>
#include <stdlib.h>
typedef struct {
float r;
float g;
1
@@ -22,4 +25,8 @@ typedef struct {
extern void setColor(volatile unsigned char* fb, colour_t pixel, long x, long y, long pitch);
#endif
extern int * getCoordinates();
extern double scale_to_x_origin(int);
extern int scale_to_y_pixel(double);
#endif