FloatImg/funcs/misc-plots.c

137 lines
3.1 KiB
C
Raw Normal View History

2019-03-04 02:22:55 +11:00
/*
2021-03-18 04:32:51 +11:00
* This is an eternal WIP, sorry...
*/
2019-03-04 02:22:55 +11:00
#include <stdio.h>
#include <stdlib.h>
2021-05-20 18:31:28 +11:00
#include <stdint.h>
2019-03-04 02:22:55 +11:00
#include <math.h>
#include "../floatimg.h"
/* --------------------------------------------------------------------- */
2020-03-01 06:52:06 +11:00
int fimg_test_pattern(FloatImg *fimg, int type, double dval)
{
int nio;
2020-07-03 01:55:45 +11:00
int x, y, k;
2020-03-01 07:34:29 +11:00
float fr, fg, fb, val;
2020-03-01 06:52:06 +11:00
#if DEBUG_LEVEL
fprintf(stderr, ">>> %s ( %p %d %g )\n", __func__, fimg, type, dval);
#endif
if (fimg->type != FIMG_TYPE_RGB) {
fprintf(stderr, "%s need an rgb pic\n", __func__);
return -6;
}
2022-07-06 19:27:55 +11:00
if (type) {
fprintf(stderr, "%s : %d %f\n", __func__, type, dval);
}
2020-03-01 06:52:06 +11:00
/* rampe de primaires dans le quart du haut */
2020-03-01 07:34:29 +11:00
val = (float)dval;
2020-03-01 06:52:06 +11:00
for (x=0; x<fimg->width; x++) {
nio = x / (fimg->width / 8);
switch(nio) {
2020-03-01 07:34:29 +11:00
case 0: fr = 0.0, fg = 0.0, fb = 0.0; break;
case 1: fr = val, fg = 0.0, fb = 0.0; break;
case 2: fr = 0.0, fg = val, fb = 0.0; break;
case 3: fr = val, fg = val, fb = 0.0; break;
case 4: fr = 0.0, fg = 0.0, fb = val; break;
case 5: fr = val, fg = 0.0, fb = val; break;
case 6: fr = 0.0, fg = val, fb = val; break;
case 7: fr = val, fg = val, fb = val; break;
2020-03-01 06:52:06 +11:00
default:
2020-03-01 07:34:29 +11:00
abort(); break;
2020-03-01 06:52:06 +11:00
}
for (y=0; y<fimg->height/4; y++)
fimg_plot_rgb(fimg, x, y, fr, fg, fb);
}
2022-10-30 23:06:36 +11:00
k = (fimg->height / 4) + 20;
2020-07-03 01:55:45 +11:00
for (x=0; x<fimg->width; x++) {
val = ((double)x / (double)fimg->width) * dval;
for (y=0; y<20; y++) {
fimg_plot_rgb(fimg, x, k+y, val, val, val);
2020-07-24 22:45:17 +11:00
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
2020-07-03 01:55:45 +11:00
}
2020-07-24 22:45:17 +11:00
// fprintf(stderr, " %6d %f\n", x, val);
2020-07-03 01:55:45 +11:00
}
2020-03-17 19:29:20 +11:00
2022-10-30 23:06:36 +11:00
k = (fimg->height / 4) + 90;
for (x=0; x<fimg->width; x++) {
val = ((x%8)<4) ? dval : 0.0;
for (y=0; y<20; y++) {
fimg_plot_rgb(fimg, x, k+y, val, val, val);
fimg_plot_rgb(fimg, x, k+y+20, dval-val, dval-val, dval-val);
}
}
2020-03-01 07:34:29 +11:00
return 0;
2020-03-01 06:52:06 +11:00
}
/* --------------------------------------------------------------------- */
2019-03-04 02:22:55 +11:00
int fimg_draw_something(FloatImg *fimg)
{
int x, y;
float fx, fy;
#define K (3.14159*13.456)
#define M 100.0
for (x=0; x<fimg->width; x++) {
fimg_plot_rgb(fimg, x, 0,
(float)x,
(float)x + 5.678,
(float)x * 1.33333);
}
for (y=1; y<fimg->height; y++) {
fy = (float)y / (float)fimg->height;
for (x=0; x<fimg->width; x++) {
fx = (float)x / (float)fimg->width;
fimg_plot_rgb(fimg, x, y,
M*(cos(fx*K)+1.2),
2019-12-31 22:02:37 +11:00
M*(sin(fy*K)+1.4),
M*(cos(fx*fy)+1.6));
2019-03-04 02:22:55 +11:00
}
}
return 0;
}
/* --------------------------------------------------------------------- */
2021-05-12 21:04:55 +11:00
int fimg_mircol_1(FloatImg *dst, float mval)
{
int x, y;
float fx, fy, rgb[3];
for (y=0; y<dst->height; y++) {
fy = (float)y / (float)dst->height;
for (x=0; x<dst->width; x++) {
fx = (float)x / (float)dst->width;
rgb[0] = mval * fx;
rgb[1] = mval * ((fx+fy)/2.0);
rgb[2] = mval * fy;
fimg_put_rgb(dst, x, y, rgb);
}
}
return -1;
}
/* --------------------------------------------------------------------- */
2021-03-18 04:32:51 +11:00
int fimg_multirandom(FloatImg *fimg, long nbpass)
2019-03-04 02:22:55 +11:00
{
int foo, x, y;
#define RI ( (rand()/7) + (rand()/9) )
#define RD ( (drand48()/7) + (drand48()/7) )
2021-03-18 04:32:51 +11:00
for (foo=0; foo<nbpass; foo++)
2019-03-04 02:22:55 +11:00
{
x = RI % fimg->width;
y = RI % fimg->height;
fimg_add_rgb(fimg, x, y, RD, RD, RD);
}
return 0;
}
/* --------------------------------------------------------------------- */