From c57a8984c4e997e49eaa35be2218798b09a5540a Mon Sep 17 00:00:00 2001 From: Brett Weiland Date: Tue, 1 Apr 2025 20:27:25 -0500 Subject: [PATCH] colorschemes developed, fixed point arithmatic fixed --- recon/screen_tests_c/main.c | 92 ++++++++++++++++++++++++++++---- recon/screen_tests_c/mandelbrot | Bin 21624 -> 21872 bytes 2 files changed, 81 insertions(+), 11 deletions(-) diff --git a/recon/screen_tests_c/main.c b/recon/screen_tests_c/main.c index d77ecfb..d729644 100644 --- a/recon/screen_tests_c/main.c +++ b/recon/screen_tests_c/main.c @@ -4,14 +4,15 @@ #include #include #include +#include -#define RES_X 1600 -#define RES_Y 800 +#define RES_X 160 +#define RES_Y 80 #define DEFAULT_CENTER_X 0 #define DEFAULT_CENTER_Y 0 #define MOUSE_BUTTON 0 -#define STEP_SIZE .25 -#define ZOOM_SIZE .25 +#define STEP_SIZE .1 +#define ZOOM_SIZE .1 #define DECIMAL_LOC 28 @@ -25,6 +26,69 @@ #define ITERS 255 #define INFTY_SQR_FIXED DOUBLE_TO_FIXED(INFTY_SQR) +//#define SHIP + +#ifdef SHIP +Color get_color(int i) { + if(i == ITERS) return (Color){0, 0, 0, 255}; + if(i == 0) return (Color){0, 0, 0, 255}; + return (Color) { + 2*(i - 128)+255, + 0, + 0, + 255 + }; +} +#else +Color get_color(int i) { + if(i == ITERS) return (Color){0, 0, 0, 255}; + if(i == 0) return (Color){0, 0, 0, 255}; + if(i < 128) { + return (Color) { + 2*(i - 128)+255, + 0, + 4*(i - 64)+255, + 255 + }; + } + return (Color) { + 0, + 0, + -2*(i - 128)+255, + 255 + }; +} +#endif + +/** +Color get_color(int i) { + //return (Color){((float)i / ITERS) * 255, 0, 0, 255}; + if(i == ITERS) return (Color){0, 0, 0, 255}; + if(i == 0) return (Color){255, 255, 255, 255}; + if(i < 85) { + return (Color) { + 0, + 0, + -3*(i - 255), + 255 + }; + } + if(i < 170) { + return (Color) { + 0, + -3*(i - 85)+255, + 3*(i - 170)+255, + 255 + }; + } + return (Color) { + -3*(i - 85), + 3*(i - 85)+255, + 0, + 255 + }; +} +**/ struct camera { double min_r, min_i, max_r, max_i; @@ -59,7 +123,7 @@ int main() { }; cam.min_i = ((double)RES_Y / RES_X) * cam.min_r; cam.max_i = ((double)RES_Y / RES_X) * cam.max_r; - InitWindow(RES_X, RES_Y, "mandelbrot fixed point test"); + InitWindow(160, 80, "mandelbrot fixed point test"); Image img = GenImageColor(RES_X, RES_Y, BLUE); Texture tex = LoadTextureFromImage(img); @@ -67,6 +131,7 @@ int main() { SetTargetFPS(10); + while(!WindowShouldClose()) { switch(GetKeyPressed()) { case KEY_UP: @@ -82,7 +147,6 @@ int main() { shift_cam(&cam, -STEP_SIZE, 0); break; case KEY_W: - printf("a\n"); zoom_cam(&cam, ZOOM_SIZE); break; case KEY_S: @@ -107,12 +171,12 @@ int main() { int32_t c_i = DOUBLE_TO_FIXED(cam.max_i); int32_t c_r, z_i, z_r, zn_i, zn_r; int32_t z_r_2, z_i_2; - uint8_t color; printf("%f, %f\n", FIXED_TO_DOUBLE(scale_r), (cam.max_r - cam.min_r) / (double)RES_X); int i; - int max = 0; + int min = INT_MAX; + int max = INT_MIN; for(int y = 0; y < RES_Y; y++) { c_r = DOUBLE_TO_FIXED(cam.min_r); for(int x = 0; x < RES_X; x++) { @@ -124,24 +188,30 @@ int main() { zn_r = z_r_2 - z_i_2 + c_r; +#ifdef SHIP + zn_i = abs(FIXED_MULTIPLY((DOUBLE_TO_FIXED(2)), (FIXED_MULTIPLY(z_r, z_i)))) + c_i; +#else zn_i = (FIXED_MULTIPLY((DOUBLE_TO_FIXED(2)), (FIXED_MULTIPLY(z_r, z_i)))) + c_i; +#endif z_i = zn_i; z_r = zn_r; if(z_i_2 + z_r_2 > INFTY_SQR_FIXED) break; } - color = ((float)i / ITERS) * UINT8_MAX; - pixels[((y * RES_X) + x)] = (Color){color, color, color, 255}; + if(i > max) max = i; + if(i < min) min = i; + pixels[((y * RES_X) + x)] = get_color(i); c_r += scale_r; } c_i -= scale_i; } + printf("min: %i, max: %i\n", min, max); } BeginDrawing(); UpdateTexture(tex, pixels); - DrawTexture(tex, 0, 0, WHITE); + DrawTextureEx(tex, (Vector2){0,0}, 0, GetRenderWidth()/RES_X, WHITE); EndDrawing(); } diff --git a/recon/screen_tests_c/mandelbrot b/recon/screen_tests_c/mandelbrot index 708131cd980c8efdc25b54d9e9af7a5665973f98..6974baf805c8bdfd9d876cfcb0e76c7ed257803d 100755 GIT binary patch delta 6162 zcmZ`-3v^V~x!(Uiv*(dXGBe2}WD+0=@<@0j@~9X?B!L7b;r&n&McxUdJXA~+tYqMZ zC}Tv4d)cbX<)c1srC`yxR8%BE+n{yb#>Z8p?QO7CgIYnfia?$F{rgNPr1zec{O|w! z|NS`o%sHojMJIRDt~`0e%(jtFc}{wSxlXoyRG5(KwUu12PN4$5dR9QsqZ5IiT-$t} z>v?i%Zby!7?awFKW-&>>BmWRQ*Lll??;U>_KH`xxi3czL<4b3{KWo&_TMH>)w@n*B zAL?93Aw3N`fR=$~uvPB^-|EPqx7n_HAl+spzsjIHP3((IRVE2BM1L()>0@Jk$VBBK z>ZH-#2CY}k&oAG&{Fa5an;IH7)>dp1Q)*Y&Z(vjXhSg$vZNvQ94XbK5E~;PEutraF z&eM-Ohw8VTce_ZCkb?AbS5^@TOUyt$e|&h)xBc8HghN~vw*~9#lLTUx#r4L_dQ7bp zKW*Rdn(ThgUrcmDPYN81M7NyVw&h$5FpU}e#LEn~G#6-rK$x-tGL@Z%{qm2KS3XJ7-k% z9aA&^EqWIj`^5j7aoy|fp_H{0DO#z2uCY=$95bPhlS|PIv0zD zqb-|au~?n&M29cGg8#cu`TXiM_R}d}prV77Z{iAjW*N(IW2x!nki%>>N$*`?Jrdrj zf(u{>M-RO=7ljW#3ex-0S)CTl_p#wMHiV;Hy~ob#S;5ir@w578!Td!kyLU?yK+mCp`J^1p0ga z&N;r`H-Cu5dY=F}Ugpr0o*${kZbs)XInZ?PA~?A77undVUIOD$a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