Beispiel #1
0
// Render a mandelbrot fractal onto the given sdl surface
func Mandelbrot(state *FractalData, screen *sdl.Surface, pal []uint32) {
	fmt.Println("Beginning Mandelbrot")
	var wg sync.WaitGroup
	aspect := state.FractalState.Aspect()
	xincr, yincr := state.FractalState.Increments()
	y_cur := imag(state.Center) + (state.Scale/aspect)/2.0

	wg.Add(state.Height)
	for y := 0; y < state.Height; y++ {
		x_cur := real(state.Center) - state.Scale/2.0
		go mandelbrot_row(x_cur, y_cur, xincr, y, state, &wg)
		y_cur -= yincr
	}
	wg.Wait()
	fmt.Println("Rendering mandelbrot")

	screen.Lock()
	defer screen.Unlock()

	wg.Add(state.Height)
	offset := uintptr(unsafe.Pointer(screen.Pixels))
	delta := uintptr(screen.Pitch / 1)
	for y := 0; y < state.Height; y++ {
		go renderRow(offset, y, state, pal, &wg)
		offset += delta
	}
	wg.Wait()
	//invocations++
	fmt.Println("Mandeblrot completed")
}