Skip to content

Commit 19ecac1

Browse files
committed
Merge branch 'master' of https://github.com/0----0/ckb into testing
2 parents 938edb2 + 16c94f5 commit 19ecac1

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/ckb-ripple/main.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "../ckb/ckb-anim.h"
22
#include <math.h>
3+
#include <time.h>
34

45
void ckb_info(){
56
// Plugin info
@@ -14,6 +15,7 @@ void ckb_info(){
1415
CKB_PARAM_AGRADIENT("color", "Ripple color:", "", "ffffffff");
1516
CKB_PARAM_DOUBLE("length", "Ring length:", "%", 100, 1, 100);
1617
CKB_PARAM_BOOL("symmetric", "Symmetric", 0);
18+
CKB_PARAM_BOOL("randomize", "Randomly select from gradient", 0);
1719

1820
// Timing/input parameters
1921
CKB_KPMODE(CKB_KP_POSITION);
@@ -44,11 +46,12 @@ void ckb_info(){
4446

4547
float kbsize = 0.f;
4648
ckb_gradient animcolor = { 0 };
47-
int symmetric = 0, kprelease = 0;
49+
int symmetric = 0, kprelease = 0, randomize = 0;
4850
double animlength = 0.;
4951

5052
void ckb_init(ckb_runctx* context){
5153
kbsize = sqrt(context->width * context->width / 4.f + context->height * context->height / 4.f);
54+
srand((unsigned)time(NULL));
5255
}
5356

5457
void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
@@ -61,6 +64,7 @@ void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
6164
}
6265
CKB_PARSE_BOOL("symmetric", &symmetric){}
6366
CKB_PARSE_BOOL("kprelease", &kprelease){}
67+
CKB_PARSE_BOOL("randomize", &randomize){}
6468
}
6569

6670
#define ANIM_MAX (144 * 2)
@@ -69,6 +73,7 @@ struct {
6973
float x, y;
7074
float maxsize;
7175
float cursize;
76+
float choice;
7277
} anim[ANIM_MAX] = { };
7378

7479
void anim_add(float x, float y, float width, float height){
@@ -82,6 +87,7 @@ void anim_add(float x, float y, float width, float height){
8287
float sizey = fmax(y, height - y);
8388
anim[i].maxsize = sqrt(sizex * sizex + sizey * sizey) + animlength;
8489
anim[i].cursize = (symmetric) ? -animlength : 0;
90+
anim[i].choice = (float)rand()/(float)(RAND_MAX);
8591
return;
8692
}
8793
}
@@ -140,10 +146,12 @@ int ckb_frame(ckb_runctx* context){
140146
if(distance > 1.f && distance <= 1.005f)
141147
// Round values close to 1
142148
distance = 1.f;
149+
143150
// Blend color gradient according to position
144151
if(distance >= 0. && distance <= 1.f){
145152
float a, r, g, b;
146-
ckb_grad_color(&a, &r, &g, &b, &animcolor, distance * 100.);
153+
float gradChoice = randomize ? anim[i].choice : distance;
154+
ckb_grad_color(&a, &r, &g, &b, &animcolor, gradChoice * 100.);
147155
ckb_alpha_blend(key, a, r, g, b);
148156
}
149157
}

0 commit comments

Comments
 (0)