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

New Visual Effects #127

Open
wants to merge 8 commits into
base: testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Touch up heat and bump version
  • Loading branch information
Devon Richards committed Sep 23, 2015
commit c542ade477535148508ca7c9c8851bf1a3dad19b
2 changes: 1 addition & 1 deletion ckb.pro
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ SUBDIRS = \
src/ckb-pinwheel \
src/ckb-random \
src/ckb-rain \
src/ckb-hist
src/ckb-heat

QMAKE_MAC_SDK = macosx10.10
2 changes: 1 addition & 1 deletion src/ckb-hist/ckb-hist.pro → src/ckb-heat/ckb-heat.pro
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
TEMPLATE = app
TARGET = ckb-hist
TARGET = ckb-heat

QMAKE_CFLAGS += -std=c99
QMAKE_MAC_SDK = macosx10.10
Expand Down
41 changes: 31 additions & 10 deletions src/ckb-hist/main.c → src/ckb-heat/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@

void ckb_info(){
// Plugin info
CKB_NAME("Histogram");
CKB_VERSION("0.0");
CKB_NAME("HeatMap");
CKB_VERSION("0.5");
CKB_COPYRIGHT("2015", "RULER501");
CKB_LICENSE("GPLv2");
CKB_LICENSE("LGPLv3");
CKB_GUID("{097D69F0-70B2-48B8-AFE2-25A1CDB0D92C}");
CKB_DESCRIPTION("A spot effect on pressed keys that shows usage");

// Effect parameters
CKB_PARAM_AGRADIENT("color", "Fade color:", "", "ffffffff");
CKB_PARAM_BOOL("random", "Random Coloring", 0);
//CKB_PARAM_LONG("frequency", "Spot Radius:", "", "1", "0", "150");

// Timing/input parameters
Expand All @@ -35,6 +36,7 @@ int* keyUsages = NULL;
int* keyPressed = NULL;
double* keyTiming = NULL;
double duration = 1.f;
int randomBright = 0;

void ckb_init(ckb_runctx* context){
keyUsages = calloc(context->keycount, sizeof(int));
Expand All @@ -46,6 +48,7 @@ void ckb_parameter(ckb_runctx* context, const char* name, const char* value){
CKB_PARSE_AGRADIENT("color", &animcolor){}
//CKB_PARSE_LONG("frequency", &radius){}
CKB_PARSE_DOUBLE("duration", &duration){}
CKB_PARSE_BOOL("random", &randomBright){}
}

#define ANIM_MAX (144 * 2)
Expand Down Expand Up @@ -82,7 +85,7 @@ void ckb_keypress(ckb_runctx* context, ckb_key* key, int x, int y, int state){
// Add or remove a spot on this key
if(state){
anim_add(key, x, y);
keyUsages[key - context->keys] += 60*duration;
keyUsages[key - context->keys] += 30*duration;
keyPressed[key - context->keys] = 1;
keyTiming[key - context->keys] = 0;
}
Expand All @@ -97,7 +100,7 @@ void ckb_start(ckb_runctx* context, int state){
}

void ckb_time(ckb_runctx* context, double delta){
int i = context->keycount;
/* int i = context->keycount;
for(;i --> 0;){
if(keyUsages[i] && !keyPressed[i]){
keyTiming[i] -= delta;
Expand All @@ -106,13 +109,23 @@ void ckb_time(ckb_runctx* context, double delta){
keyTiming[i] += 0.03333333333;
}
}
}
}*/
}

inline int max(int a, int b){
return a > b ? a : b;
}


inline int min(int a, int b){
return a < b ? a : b;
}

inline int clamp(int a, int b, int t){
return max(min(a,b), t);
}

int gcounter = 0;

int ckb_frame(ckb_runctx* context){
CKB_KEYCLEAR(context);
// Draw spots
Expand All @@ -121,15 +134,23 @@ int ckb_frame(ckb_runctx* context){
for(unsigned i = 0; i < ANIM_MAX; i++){
//if(anim[i].active){
for(ckb_key* key = keys; key < keys + count; key++){
if(!anim[i].press || keyUsages[anim[i].press - keys] == 0)
if(!(anim[i].press && keyUsages[anim[i].press - keys]))
continue;
if(max(abs(anim[i].x - key->x), abs(anim[i].y - key->y)) <= radius){
float a, r, g, b;
ckb_grad_color(&a, &r, &g, &b, &animcolor, max(keyUsages[anim[i].press - keys],600)/600.f);
ckb_alpha_blend(key, a, r, g, b);
if(random)
ckb_grad_color(&a, &r, &g, &b, &animcolor, ((float)(rand() % 1000))/10.f);
else
ckb_grad_color(&a, &r, &g, &b, &animcolor, ((float)min(keyUsages[anim[i].press-keys],300))/3.f);
ckb_alpha_blend(key, a, r, g, b);
}
}
//}
}
gcounter++;
if(!(gcounter %= 3))
for(;count --> 0;)
if(keyUsages[count] && !keyPressed[count])
keyUsages[count]--;
return 0;
}