From a54d8fb8f1ea2184e508adf160915a27b95a7302 Mon Sep 17 00:00:00 2001 From: ZoRo Date: Mon, 30 Nov 2020 08:03:00 +0000 Subject: Version 0.3 --- fractal.c | 66 +++++++++++++++---------------------------------------------- index.html | 15 ++++++++++++-- index.js | 2 +- index.wasm | Bin 570905 -> 570774 bytes 4 files changed, 30 insertions(+), 53 deletions(-) diff --git a/fractal.c b/fractal.c index 86ca9f4..ab326bd 100644 --- a/fractal.c +++ b/fractal.c @@ -17,17 +17,12 @@ #include #endif - -//#include - #include "koh.h" -//#include "queue.h" #define SCREEN_WIDTH 320 #define SCREEN_WIDTH2 (SCREEN_WIDTH/2) #define SCREEN_HEIGHT 320 #define SCREEN_HEIGHT2 (SCREEN_HEIGHT/2) -//#define MAX_GENERATION 5 static int quit=0; static SDL_Window *window = NULL; @@ -39,11 +34,12 @@ typedef struct rgba32_t } rgba32_t; #define MAX_LEVEL 7 -#define QUEUE_SIZE (1+MAX_LEVEL*MAX_LEVEL*MAX_LEVEL*MAX_LEVEL) +#define QUEUE_SIZE (1+MAX_LEVEL*MAX_LEVEL*MAX_LEVEL*MAX_LEVEL*3) int queue_index=0; koh_node koh_queue[QUEUE_SIZE]; koh_config koh_set_config; +int first_run=1; @@ -63,16 +59,14 @@ void queue_init() void queue_add(koh_node kn) { - if (queue_index > QUEUE_SIZE) + if (queue_index >= QUEUE_SIZE) { printf("Cannot add to queue\n"); - //return -1; return ; } koh_queue[queue_index] = kn; queue_index += 1; return; - //return 0; } @@ -80,7 +74,7 @@ koh_node queue_get(int idx) { koh_node kn = {-1,-1,-1,-1}; - if ((idx<0) || (idx>QUEUE_SIZE)) + if ((idx<0) || (idx>=QUEUE_SIZE)) { return kn; } @@ -120,11 +114,6 @@ rgba32_t color_gen_mainlv(rgba32_t original, int gen, int max_gen) double color_b = 14.0/255; rgba32_t c = {color_r, color_g, color_b,0}; - /* - c.r = 1.0*180/255 + (gen-max_gen)*color_r; - c.g = 1.0*100/255 + (gen-max_gen)*color_g; - c.b = 1.0*50/255 + (gen-max_gen)*color_b; - */ c.r = 1.0*180/255 - (max_gen-gen)*color_r; c.g = 1.0*100/255 - (max_gen-gen)*color_g; c.b = 1.0*50/255 - (max_gen-gen)*color_b; @@ -140,11 +129,6 @@ rgba32_t color_gen_redish(rgba32_t original, int gen, int max_gen) double color_b = 14.0/255; rgba32_t c = {color_r, color_g, color_b,0}; - /* - c.r = 1.0*180/255 + (gen-max_gen)*color_r; - c.g = 1.0*100/255 + (gen-max_gen)*color_g; - c.b = 1.0*50/255 + (gen-max_gen)*color_b; - */ c.r = 1.0*180/255 - (max_gen-gen)*color_r; c.g = 1.0*30/255 - (max_gen-gen)*color_g; c.b = 1.0*10/255 - (max_gen-gen)*color_b; @@ -160,11 +144,6 @@ rgba32_t color_gen_yellowish(rgba32_t original, int gen, int max_gen) double color_b = 14.0/255; rgba32_t c = {color_r, color_g, color_b,0}; - /* - c.r = 1.0*180/255 + (gen-max_gen)*color_r; - c.g = 1.0*100/255 + (gen-max_gen)*color_g; - c.b = 1.0*50/255 + (gen-max_gen)*color_b; - */ c.r = 1.0*180/255 - (max_gen-gen)*color_r; c.g = 1.0*160/255 - (max_gen-gen)*color_g; c.b = 1.0*40/255 - (max_gen-gen)*color_b; @@ -199,12 +178,10 @@ void generate_koh(int gener, double size, int posx, int posy, double k) int i; koh_node kn = {-1,-1,-1,-1}; - //printf("%f %f\n",size,k); double t_size = size*k; if (gener<0) { - //return 0; return; } @@ -369,9 +346,6 @@ void RectPXcolor( int x, int y,int w, int h, rgba32_t c ) glEnableVertexAttribArray(1); glBindBuffer(GL_ARRAY_BUFFER, colorBuffer); glVertexAttribPointer(1 /* ? */, 3, GL_FLOAT, GL_FALSE, 0, 0); - - //glDisableVertexAttribArray(0); - //glDisableVertexAttribArray(1); glDrawArrays ( GL_TRIANGLE_FAN, 0, 4 ); @@ -383,7 +357,7 @@ void RectPXcolor( int x, int y,int w, int h, rgba32_t c ) void koh_generation_inc() { koh_set_config.max_generations += 1; - if (koh_set_config.max_generations >= MAX_LEVEL) + if (koh_set_config.max_generations > MAX_LEVEL-1) { koh_set_config.max_generations = MAX_LEVEL-1; } @@ -423,7 +397,7 @@ void koh_pattern_next() koh_set_config.color_pattern += 1; if (koh_set_config.color_pattern>4) { - koh_set_config.color_pattern=2; + koh_set_config.color_pattern=4; } } @@ -518,7 +492,7 @@ int main_tick() { koh_set_config.x = SCREEN_WIDTH2-100/2; koh_set_config.y = SCREEN_WIDTH2-100/2; koh_set_config.k = 0.5f; - koh_set_config.max_generations = MAX_LEVEL-2; + koh_set_config.max_generations = MAX_LEVEL-1; koh_set_config.color_pattern = 0; break; @@ -554,6 +528,13 @@ int main_tick() { //printf("Poll event\n"); } + //check for first ever run + if (first_run == 1) + { + first_run = 0; + update_fractal = 1; + } + if (update_fractal == 1) { queue_init(); @@ -569,17 +550,12 @@ int main_tick() { } - //glClear( GL_COLOR_BUFFER_BIT ); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(shaderProgram); for (i=0;i<=koh_set_config.max_generations;i++) { - //rgba32_t c = color_gen_shade(start_col, i, MAX_GENERATION); - //rgba32_t c = color_gen_mainlv(start_col, i, MAX_LEVEL); rgba32_t c = color_switch(koh_set_config.color_pattern, start_col, i, MAX_LEVEL); - //static int once=0 - //glColor(1.0f,0.0,0.0,0.0); for (j=0;j
-        Koh fractal. Version: 0.1
+        Koh fractal. Version: 0.3