From ba7ba3d66638dc85b2e066ecb57852a8716cb587 Mon Sep 17 00:00:00 2001 From: tTh Date: Fri, 22 Sep 2023 14:20:26 +0200 Subject: [PATCH] working on patterns --- Lib/patterns.c | 50 +++++++++++++++++-------------------------------- Lib/patterns3.c | 49 ++++++++++++++++++++---------------------------- 2 files changed, 37 insertions(+), 62 deletions(-) diff --git a/Lib/patterns.c b/Lib/patterns.c index 3be0bed..f7f953b 100644 --- a/Lib/patterns.c +++ b/Lib/patterns.c @@ -9,8 +9,7 @@ #include "../tthimage.h" /*::------------------------------------------------------------------::*/ -int -Image_pattern_000(Image_Desc *img, int foo) +int Image_pattern_000(Image_Desc *img, int foo) { int x, y, xx, yy, r, g, b; @@ -18,11 +17,9 @@ int x, y, xx, yy, r, g, b; fprintf(stderr, "%s : foo = %d\n", __func__, foo); #endif -for (x=0; xwidth; x++) - { +for (x=0; xwidth; x++) { xx = (x * 256) / img->width; - for (y=0; yheight; y++) - { + for (y=0; yheight; y++) { yy = (y * 256) / img->height; r = xx & yy & foo; g = ((xx * yy) & 0xf8 ); @@ -37,8 +34,7 @@ for (x=0; xwidth; x++) return FUNC_IS_BETA; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_001(Image_Desc *img, int foo) +int Image_pattern_001(Image_Desc *img, int foo) { int x, y; @@ -50,11 +46,10 @@ for (x=0; xwidth; x++) for (y=0; yheight; y++) Image_plotRGB(img, x, y, x^y^foo, (x*y)>>4, x&y); -return FUNC_NOT_FINISH; +return FUNC_IS_BETA; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_002(Image_Desc *img, int foo) +int Image_pattern_002(Image_Desc *img, int foo) { int x, y, x2, y2; @@ -62,11 +57,9 @@ int x, y, x2, y2; fprintf(stderr, "Pattern 002: %d\n", foo); #endif -for (x=0; xwidth; x++) - { +for (x=0; xwidth; x++) { x2 = (x * 256) / img->width; - for (y=0; yheight; y++) - { + for (y=0; yheight; y++) { y2 = (y * 256) / img->height; Image_plotRGB(img, x, y, (x2/2)&(y2/2)&foo, (x2*y2)>>3, x2^y2); } @@ -75,8 +68,7 @@ for (x=0; xwidth; x++) return FUNC_IS_BETA; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_003(Image_Desc *img, int foo) +int Image_pattern_003(Image_Desc *img, int foo) { int x, x2, y, y2; @@ -85,11 +77,9 @@ fprintf(stderr, "Pattern 003: foo is %d\n", foo); #endif /* added some ugly code the 28 february 2008 */ -for (x=0; xwidth; x++) - { +for (x=0; xwidth; x++) { x2 = (x * 256) / img->width; - for (y=0; yheight; y++) - { + for (y=0; yheight; y++) { y2 = (y * 256) / img->height; Image_plotRGB(img, x, y, (x2/4)&(y2/4)&foo, (x2*y2)>>5, x2^y2); } @@ -98,8 +88,7 @@ for (x=0; xwidth; x++) return FUNC_NOT_FINISH; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_004(Image_Desc *img, int a, int b, int c, int d) +int Image_pattern_004(Image_Desc *img, int a, int b, int c, int d) { #if DEBUG_LEVEL fprintf(stderr, "Pattern 004: %d, %d, %d, %d\n", a, b, c, d); @@ -122,11 +111,9 @@ if (NULL == map) { return NULL_POINTER; } -for (y=0; yheight; y++) - { +for (y=0; yheight; y++) { fy = (double)y; - for (x=0; xwidth; x++) - { + for (x=0; xwidth; x++) { fx = (double)x; idx = (int)(127.0+(sin(fx)*cos(fy)*254.99)); @@ -140,8 +127,7 @@ for (y=0; yheight; y++) return FUNC_NOT_FINISH; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_042(Image_Desc *img, int foo) +int Image_pattern_042(Image_Desc *img, int foo) { int x, y, r, g, b; @@ -150,10 +136,8 @@ fprintf(stderr, "Pattern 042: threshold level is %d\n", foo); #endif r = g = b = 42; -for (x=0; xwidth; x++) - { - for (y=0; yheight; y++) - { +for (x=0; xwidth; x++) { + for (y=0; yheight; y++) { r += rand() % 4; if (r > foo) r = 0; diff --git a/Lib/patterns3.c b/Lib/patterns3.c index 91f65cc..23e133a 100644 --- a/Lib/patterns3.c +++ b/Lib/patterns3.c @@ -16,15 +16,15 @@ /* * c'est quasiment impossible de documenter cette fonction. */ -int -Image_pattern_100(Image_Desc *dst, int kr, int kg, int kb) +int Image_pattern_100(Image_Desc *dst, int kr, int kg, int kb) { int x, y, r,g, b; -for (x=0; xwidth; x++) - { - for (y=0; yheight; y++) - { +fprintf(stderr, ">>> %s ( %p %d %d %d )\n", __func__, + dst, kr, kg, kb); + +for (x=0; xwidth; x++) { + for (y=0; yheight; y++) { r = abs(x+y-(dst->width/3)) * kr; g = abs(x-y-(dst->height/3)) * kg; b = (rand() % 42) + kb; @@ -36,19 +36,19 @@ for (x=0; xwidth; x++) return FUNC_IS_BETA; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_101(Image_Desc *dst, int kr, int kg, int kb) +int Image_pattern_101(Image_Desc *dst, int kr, int kg, int kb) { int x, y, r,g, b; +fprintf(stderr, ">>> %s ( %p %d %d %d )\n", __func__, + dst, kr, kg, kb); + if (kr == 0) kr = 1; if (kg == 0) kg = 1; if (kb == 0) kb = 1; -for (x=0; xwidth; x++) - { - for (y=0; yheight; y++) - { +for (x=0; xwidth; x++) { + for (y=0; yheight; y++) { if (x < dst->width/2) { r=x/kr; g=y/kg; b=x/kb; } else @@ -59,18 +59,15 @@ for (x=0; xwidth; x++) return FUNC_IS_BETA; } /*::------------------------------------------------------------------::*/ -int -Image_pattern_102(Image_Desc *dst, int param, int kr, int kg, int kb) +int Image_pattern_102(Image_Desc *dst, int param, int kr, int kg, int kb) { int x, y, r,g, b; -for (x=0; xwidth; x++) - { - for (y=0; yheight; y++) - { +for (x=0; xwidth; x++) { + for (y=0; yheight; y++) { r = x ^ kr; g = y ^ kg; - b = (x+y) ^ kb; + b = (x+y+param) ^ kb; Image_plotRGB(dst, x, y, r, g, b); } } @@ -80,26 +77,20 @@ return FUNC_NOT_FINISH; /*::------------------------------------------------------------------::*/ /* hop, 31 mars 2008, une petite evolution stochastique de base... * */ -int -Image_pattern_103(Image_Desc *dst, int param, int kr, int kg, int kb) +int Image_pattern_103(Image_Desc *dst, int param, int kr, int kg, int kb) { int x, y, r, g, b; -long surface; double dx, dy; #if DEBUG_LEVEL fprintf(stderr, "%s: acting on image %p\n", __func__, dst); #endif -surface = dst->width * dst->height; - -for (x=0; xwidth; x++) - { +for (x=0; xwidth; x++) { dx = (double)x / (double)dst->width; - for (y=0; yheight; y++) - { + for (y=0; yheight; y++) { dy = (double)x / (double)dst->height; - r = (int)round(256.0 * sqrt(dx * dy)); /* XXX */ + r = (int)(256.0 * sqrt(dx * dy)); /* XXX */ g = b = rand() & 0xf0; Image_plotRGB(dst, x, y, r, g, b); }