blob: 25ab43a371bc4af4b512d708e8a6302b63617ff8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "fft.h"
#define N_SAMPLES 128
#define K ((2 * M_PI) / N_SAMPLES)
static double
ssin (double f)
{
return 0.5 * (sin (K * f) + 1.0);
}
static double
scos (double f)
{
return 0.5 * (cos (K * f) + 1.0);
}
int
main ()
{
complex_t *noise = malloc (sizeof (complex_t) * N_SAMPLES * N_SAMPLES);
int i, j;
double max, min;
srand48 (time (0));
for (i = 0; i < N_SAMPLES; ++i)
{
for (j = 0; j < N_SAMPLES; ++j)
{
noise[i * N_SAMPLES + j].re = 0.5 * (drand48() + drand48());
noise[i * N_SAMPLES + j].im = 0;
}
}
fft_2d (noise, N_SAMPLES);
shift_2d (noise, N_SAMPLES);
max = noise[0].re;
min = noise[0].re;
for (i = 0; i < N_SAMPLES; ++i)
{
for (j = 0; j < N_SAMPLES; ++j)
{
double d = sqrt ((i - N_SAMPLES/2) * (i - N_SAMPLES/2) +
(j - N_SAMPLES/2) * (j - N_SAMPLES/2));
double f = (d / (N_SAMPLES)); // * (d / N_SAMPLES);
if (d != 0.0)
{
noise[i * N_SAMPLES + j].re *= 0.5 * (cos (M_PI * (1 - 2 * f)) + 1.0);
noise[i * N_SAMPLES + j].im *= 0.5 * (cos (M_PI * (1 - 2 * f)) + 1.0);
#if 0
noise[i * N_SAMPLES + j].re *= 2.4 * f;
noise[i * N_SAMPLES + j].im *= 2.4 * f;
#endif
}
}
}
printf ("%f %f\n", noise[i * (N_SAMPLES/2) + N_SAMPLES/2].re, noise[i * (N_SAMPLES/2) + N_SAMPLES/2].im);
#if 0
noise[i * (N_SAMPLES / 2) + N_SAMPLES / 2].re = 1.5;
noise[i * (N_SAMPLES / 2) + N_SAMPLES / 2].im = 0;
#endif
shift_2d (noise, N_SAMPLES);
ifft_2d (noise, N_SAMPLES);
show_image ("blue noise", noise, N_SAMPLES);
return 0;
}
|