From 1c5bd982ab37b161410be55eaa401e4686d16351 Mon Sep 17 00:00:00 2001 From: ZoRo Date: Tue, 24 Nov 2020 20:01:30 +0000 Subject: Updated version that looks like works. EMCC loop works ok now --- Makefile | 16 +++-- fractal.c | 199 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- index.html | 19 +++++- koh.h | 1 + 4 files changed, 215 insertions(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 6f3e457..3711d67 100644 --- a/Makefile +++ b/Makefile @@ -7,15 +7,23 @@ LDFLAGS=-lSDL2 -lSDL2_ttf -lGLESv2 -lGL EM_LDFALGS=-s USE_SDL=2 -s USE_SDL_IMAGE=2 -s SDL2_IMAGE_FORMATS='["png"]' -s USE_SDL_TTF=2 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s LLD_REPORT_UNDEFINED -s USE_GLFW=3 make: - $(CC) -c koh.c -g3 -pg - $(CC) -c fractal.c -g3 -pg + $(CC) -c koh.c -g3 + $(CC) -c fractal.c -g3 #$(CC) -c fractal2.c - $(CC) koh.o fractal.o -o fractal $(LDFLAGS) -g3 -pg + $(CC) koh.o fractal.o -o fractal $(LDFLAGS) -g3 #$(CC) koh.o fractal2.o -o fractal2 $(LDFLAGS) emcc: $(EMCC) fractal.c koh.c -s WASM=1 -O3 -o index.js $(EM_LDFALGS) -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' #$(EMCC) fractal2.c koh.c -s WASM=1 -O3 -o index.js $(EM_LDFALGS) -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' +deploy: + #scp index.html segfault:~/public_html/draw.html + #scp index.js segfault:~/public_html/index.js + #scp index.wasm segfault:~/public_html/index.wasm + scp index.html fam@do2:/srv/http/wasm.main.lv/fractal + scp index.js fam@do2:/srv/http/wasm.main.lv/fractal + scp index.wasm fam@do2:/srv/http/wasm.main.lv/fractal + web: - darkhttpd ./ --port 12345 \ No newline at end of file + darkhttpd ./ --port 12345 diff --git a/fractal.c b/fractal.c index e5c0841..86ca9f4 100644 --- a/fractal.c +++ b/fractal.c @@ -27,7 +27,7 @@ #define SCREEN_WIDTH2 (SCREEN_WIDTH/2) #define SCREEN_HEIGHT 320 #define SCREEN_HEIGHT2 (SCREEN_HEIGHT/2) -#define MAX_GENERATION 5 +//#define MAX_GENERATION 5 static int quit=0; static SDL_Window *window = NULL; @@ -133,6 +133,67 @@ rgba32_t color_gen_mainlv(rgba32_t original, int gen, int max_gen) return c; } +rgba32_t color_gen_redish(rgba32_t original, int gen, int max_gen) +{ + double color_r = 20.0/255; + double color_g = 10.0/255; + 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; + c.a = original.a; + + return c; +} + +rgba32_t color_gen_yellowish(rgba32_t original, int gen, int max_gen) +{ + double color_r = 10.0/255; + double color_g = 20.0/255; + 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; + c.a = original.a; + + return c; +} + +rgba32_t color_switch(int pattern_id, rgba32_t original, int gen, int max_gen) +{ + switch(pattern_id) + { + case 0: + return color_gen_shade(original, gen, max_gen); + case 1: + return color_gen_shade_inv(original, gen, max_gen); + case 2: + return color_gen_mainlv(original, gen, max_gen); + case 3: + return color_gen_yellowish(original, gen, max_gen); + case 4: + return color_gen_redish(original, gen, max_gen); + default: + return color_gen_mainlv(original, gen, max_gen); + } + + return color_gen_mainlv(original, gen, max_gen); +} + void generate_koh(int gener, double size, int posx, int posy, double k) { int i; @@ -314,6 +375,27 @@ void RectPXcolor( int x, int y,int w, int h, rgba32_t c ) glDrawArrays ( GL_TRIANGLE_FAN, 0, 4 ); + glDeleteBuffers( 1, &vertexPosObject ); + glDeleteBuffers( 1, &colorBuffer ); + +} + +void koh_generation_inc() +{ + koh_set_config.max_generations += 1; + if (koh_set_config.max_generations >= MAX_LEVEL) + { + koh_set_config.max_generations = MAX_LEVEL-1; + } +} + +void koh_generation_dec() +{ + koh_set_config.max_generations -= 1; + if (koh_set_config.max_generations < 0) + { + koh_set_config.max_generations = 0; + } } void koh_pos_x_add(int x) @@ -336,6 +418,36 @@ void koh_pos_y_sub(int y) koh_set_config.y -= 10; } +void koh_pattern_next() +{ + koh_set_config.color_pattern += 1; + if (koh_set_config.color_pattern>4) + { + koh_set_config.color_pattern=2; + } +} + +void koh_pattern_prev() +{ + koh_set_config.color_pattern -= 1; + if (koh_set_config.color_pattern<0) + koh_set_config.color_pattern=0; +} + +void koh_size_dec() +{ + koh_set_config.size -= 25; + if (koh_set_config.size<50) + koh_set_config.size = 50; +} + +void koh_size_inc() +{ + koh_set_config.size += 25; + if (koh_set_config.size>400) + koh_set_config.size = 400; +} + rgba32_t start_col = {0.0,1.0,0.0,0.0}; #if __EMSCRIPTEN__ @@ -361,14 +473,16 @@ int main_tick() { { switch (event.key.keysym.sym) { - + case 81: case SDLK_DOWN: update_fractal = 1; - koh_pos_y_add(10); + koh_pos_y_sub(10); break; + + case 82: case SDLK_UP: update_fractal = 1; - koh_pos_y_sub(10); + koh_pos_y_add(10); break; case 80: case SDLK_LEFT: @@ -382,6 +496,54 @@ int main_tick() { printf("add 10\n"); koh_pos_x_add(10); break; + + case 61: + case 46: + case SDLK_KP_PLUS: + case SDLK_PLUS: + update_fractal=1; + koh_generation_inc(); + printf("plus\n"); + break; + + case SDLK_MINUS: + update_fractal = 1; + koh_generation_dec(); + break; + + case 21: + case SDLK_r: + update_fractal = 1; + koh_set_config.size = 100.0; + 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.color_pattern = 0; + break; + + case 20: + case SDLK_q: + koh_pattern_prev(); + break; + + case 26: + case SDLK_w: + koh_pattern_next(); + break; + + case 4: + case SDLK_a: + update_fractal = 1; + koh_size_dec(); + break; + + case 22: + case SDLK_s: + update_fractal = 1; + koh_size_inc(); + break; + default: printf("Unknown key %d\n",event.key.keysym.sym); update_fractal = 1; @@ -389,12 +551,13 @@ int main_tick() { break; } } - printf("Poll event\n"); + //printf("Poll event\n"); } if (update_fractal == 1) { queue_init(); + printf("k=%f",koh_set_config.k); generate_koh( koh_set_config.max_generations, koh_set_config.size, @@ -410,10 +573,11 @@ int main_tick() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glUseProgram(shaderProgram); - for (i=0;i<=MAX_GENERATION;i++) + 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_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
+        
- +
+ +
+ +
+          Supported keys:
+          left,right,up,down - change position by 10 pixels
+          r                  - reset the configuration
+          '-'                - decrease amount of levels
+          '+'                - increase amount of levels
+          q                  - previous color pattern
+          w                  - next color pattern
+          a                  - decrease size
+          s                  - increase size
+        
\ No newline at end of file diff --git a/koh.h b/koh.h index b197c90..b003b0b 100644 --- a/koh.h +++ b/koh.h @@ -16,6 +16,7 @@ typedef struct int max_generations; int x,y; double size; + int color_pattern; } koh_config; typedef struct -- cgit v1.2.3