Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(ckb-ripple) Add the option to select a single color at random from the gradient #264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/ckb-ripple/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "../ckb/ckb-anim.h"
#include <math.h>
#include <time.h>

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

// Timing/input parameters
CKB_KPMODE(CKB_KP_POSITION);
Expand Down Expand Up @@ -44,11 +46,12 @@ void ckb_info(){

float kbsize = 0.f;
ckb_gradient animcolor = { 0 };
int symmetric = 0, kprelease = 0;
int symmetric = 0, kprelease = 0, randomize = 0;
double animlength = 0.;

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

void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
Expand All @@ -61,6 +64,7 @@ void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
}
CKB_PARSE_BOOL("symmetric", &symmetric){}
CKB_PARSE_BOOL("kprelease", &kprelease){}
CKB_PARSE_BOOL("randomize", &randomize){}
}

#define ANIM_MAX (144 * 2)
Expand All @@ -69,6 +73,7 @@ struct {
float x, y;
float maxsize;
float cursize;
float choice;
} anim[ANIM_MAX] = { };

void anim_add(float x, float y, float width, float height){
Expand All @@ -82,6 +87,7 @@ void anim_add(float x, float y, float width, float height){
float sizey = fmax(y, height - y);
anim[i].maxsize = sqrt(sizex * sizex + sizey * sizey) + animlength;
anim[i].cursize = (symmetric) ? -animlength : 0;
anim[i].choice = (float)rand()/(float)(RAND_MAX);
return;
}
}
Expand Down Expand Up @@ -140,10 +146,12 @@ int ckb_frame(ckb_runctx* context){
if(distance > 1.f && distance <= 1.005f)
// Round values close to 1
distance = 1.f;

// Blend color gradient according to position
if(distance >= 0. && distance <= 1.f){
float a, r, g, b;
ckb_grad_color(&a, &r, &g, &b, &animcolor, distance * 100.);
float gradChoice = randomize ? anim[i].choice : distance;
ckb_grad_color(&a, &r, &g, &b, &animcolor, gradChoice * 100.);
ckb_alpha_blend(key, a, r, g, b);
}
}
Expand Down