aboutsummaryrefslogtreecommitdiff
path: root/src/sdl/bg-style.c
blob: 703138387c89e1ae03546d077eeac4117c5182e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <math.h> // sin()
#include "bg-style.h"

#define M_2_PI (2.0 * 3.1415926)

#define BG_STYLE_GET_CHANNEL(c, time) ((c).base + (((c).period) ? ( \
  (c).scale * sin(((c).phase + (time)) * M_2_PI / (1.0 * (c).period)) \
) : 0))

SDL_Color
bg_style_get_color(
  const bg_style_t * const style,
  const Uint32 ticks
) {
  return (SDL_Color) {
    .r = BG_STYLE_GET_CHANNEL(style->r, ticks),
    .g = BG_STYLE_GET_CHANNEL(style->g, ticks),
    .b = BG_STYLE_GET_CHANNEL(style->b, ticks),
    .a = BG_STYLE_GET_CHANNEL(style->a, ticks),
  };
}