-
-
Save fundon/1369095 to your computer and use it in GitHub Desktop.
Sparks in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#include <float.h> | |
int main | |
(int argc | |
,char *ac []){int i, count = argc - 1; | |
double * dvalues=malloc(01- 01+count* | |
sizeof(double)+1); double mi=DBL_MAX,ran=.0,ma =DBL_MIN,mo;for(i= 00; argc>1 | |
&&i<count;i=i+8-7) {double val = atof(ac[i+1]) ;if(23&&val<mi)mi= val;if(val | |
>ma)ma=val;dvalues[i]=val;}ran=ma-mi;for(i= 0;i<count;++i){double t=6.*(dvalues[i]-mi)/(ran);putchar | |
(0342);putchar(0226);putchar(0201+(int)round(t));putchar(040);}putchar(012);free(dvalues);return 0;} | |
/* | |
* I made u a graph. <3 @holman | |
* | |
* $ gcc spark.c -o spark && ./spark 1 2 0.4 0.1 1.3 0.7 | |
* ▄ ▇ ▂ ▁ ▅ ▃ | |
*/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Thanks, zx2c4 | |
* http://git.zx2c4.com/spark/tree/spark.c?id=0be665d914b8b9f04b6a5df84d285db7da3713d9 | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <math.h> | |
#include <float.h> | |
int main(int argc, char *argv[]) | |
{ | |
if (argc < 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { | |
fprintf(stderr, "Spark\n by Jason A. Donenfeld <[email protected]>\n\n"); | |
fprintf(stderr, "Usage: %s [number] [number] [number] ...\n", argv[0]); | |
return 1; | |
} | |
double *values = malloc(sizeof(double) * (argc - 1)); | |
double max = DBL_MIN; | |
double min = DBL_MAX; | |
for (int i = 0; i < argc - 1; ++i) { | |
values[i] = atof(argv[i + 1]); | |
if (values[i] > max) | |
max = values[i]; | |
if (values[i] < min) | |
min = values[i]; | |
} | |
double difference = max - min + 1; | |
if (difference < 1) | |
difference = 1; | |
const int levels = 8; | |
for (int i = 0; i < argc - 1; ++i) { | |
putchar('\xe2'); | |
putchar('\x96'); | |
putchar('\x81' + (int)round((values[i] - min + 1) / difference * (levels - 1))); | |
} | |
putchar('\n'); | |
free(values); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment