wip generator

This commit is contained in:
2025-06-04 12:12:13 +02:00
parent 9933877b0e
commit d0f59532ca
3 changed files with 21 additions and 4 deletions
+15 -1
View File
@@ -1,19 +1,31 @@
#include "args.h"
#include "bmp.h"
#include "rand.h"
#include <math.h>
#include <stdio.h>
#define COLOR_DEPTH 3
parameters global_params;
float global_fslope;
void generate_line(unsigned short y, unsigned char *data_buffer,
unsigned int len) {
unsigned int i;
for (i = 0; i < len; i++) {
data_buffer[i] = global_params.start[i % 3];
data_buffer[i] = rand_uchar(256);
}
}
unsigned char pixel_gen(unsigned char depth, unsigned char top_pixel,
unsigned char left_pixel) {
float v = fminf(
255.0, fmaxf(0.0, (rand_float(2.0) - 1.0) * global_params.var[depth] +
((float)left_pixel) * global_fslope +
((float)top_pixel) * (1.0 - global_fslope)));
return (unsigned char)v;
}
void debug_parameters(parameters params) {
if (!params.quiet) {
printf("output %s\n", params.file_path);
@@ -29,7 +41,9 @@ void debug_parameters(parameters params) {
int generate(parameters params) {
global_params = params;
global_fslope = ((float)params.slope) / 255.0;
debug_parameters(params);
set_seed(params.seed);
bmp_generate(params.width, params.height, COLOR_DEPTH, params.file_path,
generate_line);
return 0;
+5 -3
View File
@@ -5,15 +5,17 @@ float seed;
void set_seed(unsigned long new_seed) { seed = (float)(new_seed % 1000000); }
float rand(float seed) {
float v = powf(fabs(seed), 6. / 7.);
float v = powf(seed, 6. / 7.);
v *= sinf(v) + 1.;
return v - floorf(v);
}
unsigned char rand_uchar(unsigned int max) {
float rand_float(const float max) { return rand(seed++) * max; }
unsigned char rand_uchar(const unsigned int max) {
return (unsigned char)(rand(seed++) * max);
}
unsigned short rand_ushort(unsigned int max) {
unsigned short rand_ushort(const unsigned int max) {
return (unsigned short)(rand(seed++) * max);
}
+1
View File
@@ -2,6 +2,7 @@
#define RAND_H
void set_seed(unsigned long new_seed);
float rand_float(const float max);
unsigned char rand_uchar(unsigned int max);
unsigned short rand_ushort(unsigned int max);