Hello Everyone, I will be using this thread for my "endeavor" as I explore the possibilities with C … Basically making / test functions that may or not be useful and at the same time I will be learning more about C (feel free to join).
I will start with gradients, I have been research for past few days attempting to learn in how gradients are done in other languages (such as JavaScript, python, rust, etc.) I happened to have stubbled upon stack overflow thread with an example in python using pygame.
So, I attempted to port it onto the CE, this is what I got:
Code:
"The code is very limited and could be approved upon"
I attempted to increase the size of the rectangle and was met with an error:
Code:
How could I fix it and how could you improve upon the code?
I will start with gradients, I have been research for past few days attempting to learn in how gradients are done in other languages (such as JavaScript, python, rust, etc.) I happened to have stubbled upon stack overflow thread with an example in python using pygame.
So, I attempted to port it onto the CE, this is what I got:
Code:
void main(void)
{
gfx_Begin();
gfx_FillScreen(0);
gradientRectangle(1, 1, 10, 10);
delay(3000);
gfx_End();
return;
}
void gradientRectangle(int x, int y, int w, int h)
{
uint8_t start_color[3] = {0,0,0};
uint8_t end_color[3] = {255,130,0};
uint8_t rm, gm, bm; //red, green, blue medium
rm = (start_color[0] + end_color[0]) * w;
gm = (start_color[1] + end_color[1]) * w;
bm = (start_color[2] + end_color[2]) * w;
for (int i = 0; i < w + 1; i++){
gfx_palette[i+1] = gfx_RGBTo1555(start_color[0] + rm*i, start_color[1] + gm*i, start_color[2] + bm*i);
gfx_SetColor(i+1);
gfx_VertLine(x + i, y, h);
}
return;
}
"The code is very limited and could be approved upon"
I attempted to increase the size of the rectangle and was met with an error:
Code:
void main(void)
{
gfx_Begin();
gfx_FillScreen(0);
gradientRectangle(1, 1, 50, 50);
delay(3000);
gfx_End();
return;
}
void gradientRectangle(int x, int y, int w, int h)
{
uint8_t start_color[3] = {0,0,0};
uint8_t end_color[3] = {255,130,0};
uint8_t rm, gm, bm; //red, green, blue medium
rm = (end_color[0] - start_color[0]) * w;
gm = (end_color[1] - start_color[1]) * w;
bm = (end_color[2] - start_color[2]) * w;
for (int i = 0; i < w + 1; i++){
gfx_palette[i+1] = gfx_RGBTo1555(start_color[0] + rm*i, start_color[1] + gm*i, start_color[2] + bm*i);
gfx_SetColor(i+1);
gfx_VertLine(x + i, y, h);
}
return;
}
How could I fix it and how could you improve upon the code?