Ubuntu 9.10 and the Google Go Emacs Mode
November 24, 2009 on 1:00 pm | In english, hacking, linux, open source, technic | No CommentsAfter some hours with google go I recognize the emacs mode in the source directory of the current distribution.
It is easy to install the mode for ubuntu 9.10 (karmic). First install the emacs with
sudo apt-get install emacs23
After that copy the the two .el files from you google ~/go/misc/emacs directory to
/usr/share/emacs/23.1/lisp
Now create a .emacs file in you home directory and add the following to lines.
(add-to-list ‘load-path “/usr/share/emacs/23.1/lisp” t)
(require ‘go-mode-load)
Now the google mode is activated after loading a .go file.

Splintering of Empires
November 18, 2009 on 11:58 am | In art, english, politics | No CommentsMore about this nice project Link
Google Go and the Mandelbrot Set Part II
November 17, 2009 on 12:22 pm | In english, hacking, linux | No CommentsThe following code is my solution for parallel calculation of a mandelbrot set with google go.
package main
import ( "image";
"image/png";
"bufio";
"fmt";
"os";
"math";
"time"; )
type PixelCalc struct { x int;
y int;
cx float64;
cy float64; }
func PointIteration(in chan *PixelCalc,ready chan int,img *image.RGBA){
for {
pixelCalc := <- in;
xt := float64(0);
yt := float64(0);
x := float64(0);
y := float64(0);
quadValue := float64(0);
iter := 0;
for quadValue <= 255.0 && iter < 255 {
xt= ( x * x ) - ( y * y) + pixelCalc.cx;
yt= ( float64(2.0) * x * y ) + pixelCalc.cy;
x = xt;
y = yt;
iter++;
quadValue = ( x * x ) + ( y * y );
}
color := new(image.NRGBAColor);
color.A = 255;
iter8 := uint8(iter);
color.R = iter8;
color.G = iter8;
color.B = iter8;
img.Set(pixelCalc.x,pixelCalc.y,color);
ready <- 1;
}
}
func main(){
start := time.Seconds();
const pictureSize = 1000;
img := image.NewRGBA(pictureSize,pictureSize);
f, err := os.Open("mandel.png", os.O_WRONLY|os.O_CREAT, 0666);
if err != nil {
fmt.Printf("Can't create picture file\n");
}
calc := make(chan *PixelCalc,pictureSize*pictureSize);
out := make(chan int,pictureSize*pictureSize);
for i:=0;i<4;i++{
go PointIteration(calc,out,img);
}
deltaX := math.Fabs(float64(-2.0 - 1.0)) / float64(pictureSize);
deltaY := math.Fabs(float64(-1.0 - 1.0)) / float64(pictureSize);
cx := float64(-2.0);
for x:=0;x<pictureSize;x++{
cx+=deltaX;
cy := float64(-1.0);
for y:=0;y<pictureSize;y++{
cy+=deltaY;
pixelCalc := new(PixelCalc);
pixelCalc.cx = cx;
pixelCalc.cy = cy;
pixelCalc.x = x;
pixelCalc.y = y;
calc <- pixelCalc;
}
}
for i:=0;i<pictureSize*pictureSize;i++{
<- out;
}
w := bufio.NewWriter(f);
png.Encode(w,img);
w.Flush();
fmt.Printf("Seconds needed %d\n",time.Seconds() - start);
}
At this time the go compiler has some bugs regarding the multiprocessor support. But sometimes I can see the use of my two processors.

I hope there will fix that bug fast. The first workaround for that bug is the GOMAXPROCS environment variable. I set this to 2. But this did’nt help everytime.
Google Go and the Mandelbrot Set
November 13, 2009 on 12:30 pm | In english, hacking, linux | 1 CommentLearning a new programming language is fun. Here is my version of calculating the mandelbrot set and save the result as a PNG picture with Google Go.
package main
import ( "image";
"image/png";
"bufio";
"fmt";
"os";
"math";
"time"; )
func PointIteration( cx, cy, maxValue float64, maxIter uint8) uint8{
quadValue := float64(0.0);
iter := uint8(0);
x := float64(0.0);
y := float64(0.0);
for quadValue <= maxValue && iter < maxIter {
xt:= ( x * x ) - ( y * y) + cx;
yt:= ( float64(2.0) * x * y ) + cy;
x = xt;
y = yt;
iter++;
quadValue = ( x * x ) + ( y * y );
}
return iter;
}
func main(){
start := time.Seconds();
const pictureSize = 500;
img := image.NewRGBA(pictureSize,pictureSize);
f, err := os.Open("mandel.png", os.O_WRONLY|os.O_CREAT, 0666);
if err != nil {
fmt.Printf("Can't create picture file\n");
}
deltaX := math.Fabs(float64(-2.0 - 1.0)) / float64(pictureSize);
deltaY := math.Fabs(float64(-1.0 - 1.0)) / float64(pictureSize);
cx := float64(-2.0);
for x:=0;x<pictureSize;x++{
cx+=deltaX;
cy := float64(-1.0);
for y:=0;y<pictureSize;y++{
cy+=deltaY;
iter := PointIteration(cx,cy,255.0,255);
color := new(image.NRGBAColor);
color.A = 255;
color.R = iter;
color.G = iter;
color.B = iter;
img.Set(x,y,color);
}
}
w := bufio.NewWriter(f);
png.Encode(w,img);
w.Flush();
fmt.Printf("Seconds needed %d\n",time.Seconds() - start);
}
And here the result.

Next step is trying to improve the speed by using goroutines and channels.



