ckb-next  v0.2.8 at branch master
ckb-next driver for corsair devices
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
main.c File Reference
#include "../ckb/ckb-anim.h"
#include <math.h>
#include <stdlib.h>
#include <time.h>
+ Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define DROP_MAX   1000
 

Functions

void ckb_info ()
 
void drop_add (float x, float y, int slow)
 
void ckb_init (ckb_runctx *context)
 
void ckb_parameter (ckb_runctx *context, const char *name, const char *value)
 
void ckb_keypress (ckb_runctx *context, ckb_key *key, int x, int y, int state)
 
void ckb_start (ckb_runctx *context, int state)
 
void ckb_time (ckb_runctx *context, double delta)
 
int ckb_frame (ckb_runctx *context)
 

Variables

int spawn = 0
 
double period = 0.1
 
double maxsize = 100.
 
double speed = 100.
 
unsigned char ar = 255
 
unsigned char ag = 255
 
unsigned char ab = 255
 
float aa = 1.
 
struct {
int active
 
float x
 
float y
 
float size
 
float msize
 
drop [1000]
 
double tick = -1.
 

Macro Definition Documentation

#define DROP_MAX   1000

Definition at line 34 of file main.c.

Referenced by ckb_frame(), ckb_time(), and drop_add().

Function Documentation

int ckb_frame ( ckb_runctx context)

Definition at line 120 of file main.c.

References aa, ab, ag, ar, ckb_alpha_blend(), CKB_KEYCLEAR, drop, DROP_MAX, ckb_runctx::keycount, and ckb_runctx::keys.

120  {
121  CKB_KEYCLEAR(context);
122  // Draw drops
123  for(unsigned i = 0; i < DROP_MAX; i++){
124  if(drop[i].active){
125  unsigned count = context->keycount;
126  ckb_key* keys = context->keys;
127  for(ckb_key* key = keys; key < keys + count; key++){
128  // Calculate distance between key and drop, relative to the current drop size
129  float distance = drop[i].size - sqrt(pow(key->x - drop[i].x, 2.f) + pow(key->y - drop[i].y, 2.f));
130  // On the outside, cut the distance in half
131  if(distance < 0.)
132  distance = -distance / 2.;
133  // Scale according to drop size (fade-out radius expands as the drop becomes larger)
134  float scale = drop[i].size / 4.f;
135  if(scale < 10.)
136  scale = 10.;
137  distance /= scale;
138  if(distance <= 1.){
139  // Scale alpha according to size divided by maximum size (drops fade out as they expand)
140  float ascale = (1.f - drop[i].size / drop[i].msize);
141  if(ascale > 1.f)
142  ascale = 1.f;
143  // Apply color
144  ckb_alpha_blend(key, (1.f - distance) * ascale * aa * 255., ar, ag, ab);
145  }
146  }
147  }
148  }
149  return 0;
150 }
unsigned char ag
Definition: main.c:40
#define DROP_MAX
Definition: main.c:34
Definition: keymap.h:49
unsigned keycount
Definition: ckb-anim.h:141
#define CKB_KEYCLEAR(context)
Definition: ckb-anim.h:148
ckb_key * keys
Definition: ckb-anim.h:140
float aa
Definition: main.c:41
unsigned char ar
Definition: main.c:40
struct @7 drop[1000]
void ckb_alpha_blend(ckb_key *key, float a, float r, float g, float b)
Definition: ckb-anim.h:283
unsigned char ab
Definition: main.c:40

+ Here is the call graph for this function:

void ckb_info ( )

Definition at line 6 of file main.c.

References CKB_COPYRIGHT, CKB_DESCRIPTION, CKB_GUID, CKB_KP_POSITION, CKB_KPMODE, CKB_LICENSE, CKB_LIVEPARAMS, CKB_NAME, CKB_PARAM_DOUBLE, CKB_PARAM_LONG, CKB_PARAM_RGB, CKB_PRESET_END, CKB_PRESET_PARAM, CKB_PRESET_START, CKB_REPEAT, CKB_TIME_ABSOLUTE, CKB_TIMEMODE, CKB_VERSION, FALSE, and TRUE.

6  {
7  // Plugin info
8  CKB_NAME("Raindrop");
9  CKB_VERSION("0.10");
10  CKB_COPYRIGHT("2014-2016", "MSC");
11  CKB_LICENSE("GPLv2");
12  CKB_GUID("{5D6695AF-0496-41E2-BEE7-F7D0ABAA49E9}");
13  CKB_DESCRIPTION("A rain-like effect.");
14 
15  // Effect parameters
16  CKB_PARAM_RGB("color", "Drop color:", "", 255, 255, 255);
17  CKB_PARAM_DOUBLE("intensity", "Intensity:", "%", 100, 0, 100);
18  CKB_PARAM_DOUBLE("size", "Size:", "%", 25, 1, 100);
19  CKB_PARAM_LONG("frequency", "Frequency:", "per second", 10, 1, 100);
20 
21  // Timing/input parameters
26 
27  // Presets
28  CKB_PRESET_START("Default");
29  CKB_PRESET_PARAM("trigger", "1");
30  CKB_PRESET_PARAM("kptrigger", "1");
32 }
#define CKB_PRESET_END
Definition: ckb-anim.h:87
#define FALSE
Definition: ckb-anim.h:49
#define CKB_PARAM_DOUBLE(name, prefix, postfix, default, min, max)
Definition: ckb-anim.h:75
#define CKB_VERSION(version)
Definition: ckb-anim.h:64
#define CKB_TIMEMODE(mode)
Definition: ckb-anim.h:97
#define TRUE
Definition: ckb-anim.h:46
#define CKB_GUID(guid)
Definition: ckb-anim.h:60
#define CKB_NAME(name)
Definition: ckb-anim.h:62
#define CKB_PARAM_LONG(name, prefix, postfix, default, min, max)
Definition: ckb-anim.h:74
#define CKB_TIME_ABSOLUTE
Definition: ckb-anim.h:96
#define CKB_LICENSE(license)
Definition: ckb-anim.h:68
#define CKB_KP_POSITION
Definition: ckb-anim.h:92
#define CKB_COPYRIGHT(year, author)
Definition: ckb-anim.h:66
#define CKB_DESCRIPTION(description)
Definition: ckb-anim.h:70
#define CKB_PRESET_START(name)
Definition: ckb-anim.h:85
#define CKB_KPMODE(mode)
Definition: ckb-anim.h:93
#define CKB_LIVEPARAMS(enable)
Definition: ckb-anim.h:104
#define CKB_REPEAT(enable)
Definition: ckb-anim.h:99
#define CKB_PRESET_PARAM(name, value)
Definition: ckb-anim.h:86
#define CKB_PARAM_RGB(name, prefix, postfix, r, g, b)
Definition: ckb-anim.h:77
void ckb_init ( ckb_runctx context)

Definition at line 63 of file main.c.

63  {
64  srand(time(NULL));
65 }
void ckb_keypress ( ckb_runctx context,
ckb_key key,
int  x,
int  y,
int  state 
)

Definition at line 86 of file main.c.

References drop_add().

86  {
87  // Add a drop on keypress
88  if(state)
89  drop_add(x, y, 0);
90 }
float y
Definition: main.c:66
void drop_add(float x, float y, int slow)
Definition: main.c:49
float x
Definition: main.c:66

+ Here is the call graph for this function:

void ckb_parameter ( ckb_runctx context,
const char *  name,
const char *  value 
)

Definition at line 67 of file main.c.

References aa, ab, ag, ar, CKB_PARSE_BOOL, CKB_PARSE_DOUBLE, CKB_PARSE_LONG, CKB_PARSE_RGB, ckb_runctx::height, maxsize, period, spawn, speed, and ckb_runctx::width.

67  {
68  CKB_PARSE_RGB("color", &ar, &ag, &ab){}
69  double intensity, size;
70  long frequency;
71  CKB_PARSE_DOUBLE("intensity", &intensity){
72  aa = intensity / 100.;
73  }
74  CKB_PARSE_DOUBLE("size", &size){
75  double sizex = context->width / 2.;
76  double sizey = context->height / 2.;
77  maxsize = size / 100. * sqrt(sizex * sizex + sizey * sizey);
78  speed = maxsize;
79  }
80  CKB_PARSE_LONG("frequency", &frequency){
81  period = 1. / frequency;
82  }
83  CKB_PARSE_BOOL("trigger", &spawn){}
84 }
double maxsize
Definition: main.c:38
unsigned char ag
Definition: main.c:40
unsigned height
Definition: ckb-anim.h:143
#define CKB_PARSE_RGB(param_name, r_ptr, g_ptr, b_ptr)
Definition: ckb-anim.h:118
double period
Definition: main.c:37
int spawn
Definition: main.c:36
#define CKB_PARSE_LONG(param_name, value_ptr)
Definition: ckb-anim.h:115
#define CKB_PARSE_BOOL(param_name, value_ptr)
Definition: ckb-anim.h:117
float aa
Definition: main.c:41
#define CKB_PARSE_DOUBLE(param_name, value_ptr)
Definition: ckb-anim.h:116
unsigned char ar
Definition: main.c:40
double speed
Definition: main.c:39
unsigned width
Definition: ckb-anim.h:143
unsigned char ab
Definition: main.c:40
void ckb_start ( ckb_runctx context,
int  state 
)

Definition at line 94 of file main.c.

References tick.

94  {
95  // Start or stop random spawning
96  tick = state ? 0. : -1.;
97 }
double tick
Definition: main.c:92
void ckb_time ( ckb_runctx context,
double  delta 
)

Definition at line 99 of file main.c.

References drop, drop_add(), DROP_MAX, ckb_runctx::height, period, spawn, speed, tick, and ckb_runctx::width.

99  {
100  if(delta <= 0.)
101  return;
102  // Process existing drops
103  for(unsigned i = 0; i < DROP_MAX; i++){
104  if(drop[i].active){
105  drop[i].size += delta * speed;
106  if(drop[i].size > drop[i].msize)
107  drop[i].active = 0;
108  }
109  }
110  if(tick >= 0.){
111  // Spawn a new randomly-placed drop, if the spawn time has passed
112  tick += delta;
113  if(tick > period && spawn){
114  drop_add(rand() / (double)RAND_MAX * context->width, rand() / (double)RAND_MAX * context->height, 1);
115  tick -= period;
116  }
117  }
118 }
void drop_add(float x, float y, int slow)
Definition: main.c:49
#define DROP_MAX
Definition: main.c:34
unsigned height
Definition: ckb-anim.h:143
double period
Definition: main.c:37
int spawn
Definition: main.c:36
double tick
Definition: main.c:92
double speed
Definition: main.c:39
struct @7 drop[1000]
unsigned width
Definition: ckb-anim.h:143

+ Here is the call graph for this function:

void drop_add ( float  x,
float  y,
int  slow 
)

Definition at line 49 of file main.c.

References drop, DROP_MAX, maxsize, x, and y.

Referenced by ckb_keypress(), and ckb_time().

49  {
50  for(int i = 0; i < DROP_MAX; i++){
51  if(drop[i].active)
52  continue;
53  drop[i].active = 1;
54  drop[i].x = x;
55  drop[i].y = y;
56  float msize = maxsize * (0.9 + (rand() / (double)RAND_MAX * 0.2));
57  drop[i].size = -msize / 2. * slow;
58  drop[i].msize = msize;
59  return;
60  }
61 }
float y
Definition: main.c:66
double maxsize
Definition: main.c:38
#define DROP_MAX
Definition: main.c:34
float x
Definition: main.c:66
struct @7 drop[1000]

+ Here is the caller graph for this function:

Variable Documentation

float aa = 1.

Definition at line 41 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

unsigned char ab = 255

Definition at line 40 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

unsigned char ag = 255

Definition at line 40 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

unsigned char ar = 255

Definition at line 40 of file main.c.

Referenced by ckb_frame(), and ckb_parameter().

struct { ... } drop[ 1000 ]

Referenced by ckb_frame(), ckb_time(), and drop_add().

double maxsize = 100.

Definition at line 38 of file main.c.

Referenced by ckb_parameter(), ckb_time(), and drop_add().

double period = 0.1

Definition at line 37 of file main.c.

Referenced by ckb_parameter(), and ckb_time().

int spawn = 0

Definition at line 36 of file main.c.

Referenced by ckb_parameter(), and ckb_time().

double speed = 100.

Definition at line 39 of file main.c.

Referenced by ckb_parameter(), and ckb_time().

double tick = -1.

Definition at line 92 of file main.c.

Referenced by ckb_start(), and ckb_time().