summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <ssp@redhat.com>2010-09-25 03:20:40 -0400
committerSøren Sandmann Pedersen <ssp@redhat.com>2010-09-25 03:20:40 -0400
commita14685fd08ed6698350abc96eb1a9f98022c9a72 (patch)
tree51691a78282a955bfaaa0d754d5dec68e52138a1
parent03869c01eca1506c5f849c77f6e9ac74c8e26e3e (diff)
Tile the noise when drawing
-rw-r--r--bluenoise.c14
-rw-r--r--gtk-utils.c35
2 files changed, 34 insertions, 15 deletions
diff --git a/bluenoise.c b/bluenoise.c
index 54dd4a1..fcf0976 100644
--- a/bluenoise.c
+++ b/bluenoise.c
@@ -1,3 +1,4 @@
+#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
@@ -26,6 +27,8 @@ 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)
{
@@ -49,17 +52,18 @@ main ()
{
double d = sqrt ((i - N_SAMPLES/2) * (i - N_SAMPLES/2) +
(j - N_SAMPLES/2) * (j - N_SAMPLES/2));
- double f = (d / (sqrt (2) * N_SAMPLES)); // * (d / N_SAMPLES);
+ double f = (d / (N_SAMPLES)); // * (d / N_SAMPLES);
if (d != 0.0)
{
-#if 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
- noise[i * N_SAMPLES + j].re *= f;
- noise[i * N_SAMPLES + j].im *= f;
}
}
}
@@ -70,7 +74,7 @@ main ()
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);
diff --git a/gtk-utils.c b/gtk-utils.c
index 0e2c848..e1eca8d 100644
--- a/gtk-utils.c
+++ b/gtk-utils.c
@@ -27,7 +27,9 @@ pixbuf_from_buffer (complex_t *buffer, int n)
if (v < 0)
v = 0;
- pb[0] = pb[1] = pb[2] = (int)v;
+ pb[0] = (int)(v);
+ pb[1] = (int)(v);
+ pb[2] = (int)(v);
pb[3] = 0xff;
}
}
@@ -35,18 +37,31 @@ pixbuf_from_buffer (complex_t *buffer, int n)
return pixbuf;
}
+#define SIZE 1024
+#define SIZE 1024
+
static gboolean
on_expose (GtkWidget *widget, GdkEventExpose *expose, gpointer data)
{
GdkPixbuf *pixbuf = data;
-
- gdk_draw_pixbuf (widget->window, NULL,
- pixbuf, 0, 0, 0, 0,
- gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- GDK_RGB_DITHER_NONE,
- 0, 0);
-
+ int i, j;
+ int pwidth = gdk_pixbuf_get_width (pixbuf);
+ int pheight = gdk_pixbuf_get_height (pixbuf);
+ int dwidth, dheight;
+
+ gdk_drawable_get_size (widget->window, &dwidth, &dheight);
+
+ for (i = 0; i < dheight; i += pheight)
+ {
+ for (j = 0; j < dwidth; j += pwidth)
+ {
+ gdk_draw_pixbuf (widget->window, NULL,
+ pixbuf, 0, 0, i, j, pwidth, pheight,
+ GDK_RGB_DITHER_NONE,
+ 0, 0);
+
+ }
+ }
return TRUE;
}
@@ -66,7 +81,7 @@ show_image (const char *name, complex_t *image, int n)
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
- gtk_window_set_default_size (GTK_WINDOW (window), n, n);
+ gtk_window_set_default_size (GTK_WINDOW (window), SIZE, SIZE);
pixbuf = pixbuf_from_buffer (image, n);