summaryrefslogtreecommitdiffstats
path: root/fractal.c
diff options
context:
space:
mode:
Diffstat (limited to 'fractal.c')
-rw-r--r--fractal.c66
1 files changed, 16 insertions, 50 deletions
diff --git a/fractal.c b/fractal.c
index 86ca9f4..ab326bd 100644
--- a/fractal.c
+++ b/fractal.c
@@ -17,17 +17,12 @@
#include <GLES2/gl2.h>
#endif
-
-//#include <GL/glu.h>
-
#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<queue_index;j++)
{
@@ -587,8 +563,6 @@ int main_tick() {
if (koh_queue[j].generaton == i)
{
koh_node kn = queue_get(j);
- //printf("j:%d %d %d %d\n",j,kn.x, kn.y, kn.size);
- //RectPX(kn.x, kn.y, kn.size, kn.size);
#ifndef __EMSCRIPTEN__
if (update_fractal == 1)
#endif
@@ -600,11 +574,8 @@ int main_tick() {
if (update_fractal == 1)
#endif
{
- //printf("SWAP\n");
SDL_GL_SwapWindow( window );
}
- //SDL_UpdateWindowSurface(window);
- //SDL_Delay( 20 );
update_fractal=0;
#if !__EMSCRIPTEN__
@@ -616,15 +587,11 @@ void main_loop()
{
#if __EMSCRIPTEN__
- //emscripten_set_main_loop(main_tick, -1, 1);
- //emscripten_set_main_loop(main_tick, 100, 1);
emscripten_set_main_loop(main_tick, 25, 1);
#else
while (0 == quit)
{
-
main_tick();
- //printf("One tick\n");
}
#endif
}
@@ -676,8 +643,8 @@ int main()
koh_set_config.size = 100;
koh_set_config.x = SCREEN_WIDTH2-frac_size/2;
koh_set_config.y = SCREEN_WIDTH2-frac_size/2;
- koh_set_config.k = 0.5;
- koh_set_config.max_generations = MAX_LEVEL-2;
+ koh_set_config.k = 0.5f;
+ koh_set_config.max_generations = MAX_LEVEL-1;
generate_koh(
koh_set_config.max_generations,
@@ -734,7 +701,6 @@ int main()
main_loop();
- //SDL_StopTextInput();
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();