Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Switch to DrawRgbImage to display, loop instead of for.

  • Loading branch information...
commit 2528f029180b601499faeeb8505b5ca9ade4092d 1 parent ed14ee6
@colomon authored
Showing with 16 additions and 14 deletions.
  1. +16 −14 bin/gtk-mandelbrot.pl
View
30 bin/gtk-mandelbrot.pl
@@ -234,15 +234,19 @@
constant Window = CLR::("Gtk.Window,$GTK");
constant GdkCairoHelper = CLR::("Gdk.CairoHelper,$GDK");
constant GdkGC = CLR::("Gdk.GC,$GDK");
+constant GdkRgb = CLR::("Gdk.Rgb,$GDK");
+constant GdkRgbDither = CLR::("Gdk.RgbDither,$GDK");
constant GdkColor = CLR::("Gdk.Color,$GDK");
constant GtkDrawingArea = CLR::("Gtk.DrawingArea,$GTK");
constant SystemByte = CLR::("System.Byte");
+constant ByteArray = CLR::("System.Byte[]");
my @red = @color_map.map({ SystemByte.Parse($_.comb(/\d+/)[0]) });
my @green = @color_map.map({ SystemByte.Parse($_.comb(/\d+/)[1]) });
my @blue = @color_map.map({ SystemByte.Parse($_.comb(/\d+/)[2]) });
Application.Init;
+GdkRgb.Init;
my $window = Window.new("mandelbrot");
my $windowSizeX = $size; my $windowSizeY = $size;
$window.Resize($windowSizeX, $windowSizeY); # TODO: resize at runtime NYI
@@ -268,26 +272,24 @@ ($obj, $args)
my $delta = ($lower-left.re - $upper-right.re) / $windowWidth;
- my %colors;
+ my $bytes = ByteArray.new($windowWidth * 3 * $windowHeight);
- for 0 .. $windowHeight -> $y {
+ my $counter = 0;
+ my ($x, $y);
+ loop ($y = 0; $y < $windowHeight; $y++) {
my $c = $upper-right - $y * $delta * i;
- for 0 .. $windowWidth -> $x {
+ loop ($x = 0; $x < $windowWidth; $x++) {
my $value = mandel($c);
-
- unless %colors{$value}:exists {
- my $gc = GdkGC.new($window);
- my $color = GdkColor.new(@red[$value], @green[$value], @blue[$value]);
- $window.Colormap.AllocColor($color, False, True);
- $gc.Foreground = $color;
- %colors{$value} = $gc;
- }
-
- $window.DrawPoint(%colors{$value}, $x, $y);
-
+ $bytes.Set($counter++, @red[$value]);
+ $bytes.Set($counter++, @green[$value]);
+ $bytes.Set($counter++, @blue[$value]);
$c += $delta;
}
}
+
+ my $gc = GdkGC.new($window);
+ $window.DrawRgbImage($gc, $windowX, $windowY, $windowWidth, $windowHeight,
+ GdkRgbDither.Normal, $bytes, $windowWidth * 3);
my $elapsed = time - $start-time;
say "$elapsed seconds";
Please sign in to comment.
Something went wrong with that request. Please try again.