Skip to content

Commit

Permalink
Animate sky gradient in thegrid.c example
Browse files Browse the repository at this point in the history
  • Loading branch information
maximecb committed Nov 9, 2023
1 parent 5ac70b6 commit c90efb7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ncc/examples/thegrid.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ u32 hsl_to_rgb(float h, float s, float l)
}

float line_pos = 1.0f;
float anim_time = 0.0f;

void anim_callback()
{
Expand All @@ -104,10 +105,15 @@ void anim_callback()

printf("line_pos=%f\n", line_pos);

// Animate the sky gradient over time
float h = 0.70f + 0.05f * sinf(anim_time * 0.30f);
float s = 0.95f + 0.05f * sinf(anim_time * 0.20f);
float l_max = 0.92f + 0.08f * sinf(anim_time * 0.22f);

// Draw sky/horizon
for (int i = 0; i < 335; ++i)
{
u32 color = hsl_to_rgb(0.74f, 1.0f, i / 350.0f);
u32 color = hsl_to_rgb(h, s, (i / 335.0f) * l_max);
memset32((u32*)frame_buffer[i], color, FRAME_WIDTH);
}

Expand Down Expand Up @@ -149,6 +155,7 @@ void anim_callback()

// Schedule a fixed rate update for the next frame (60fps)
fixed_rate_update(start_time, 1000 / 60, anim_callback);
anim_time = anim_time + (1 / 60.0f);
}

void keydown(u64 window_id, u16 keycode)
Expand Down

0 comments on commit c90efb7

Please sign in to comment.