Пример #1
0
func New(gradient *Gradient) *Fractal {
	var f = new(Fractal)
	f.width = 256
	f.height = 256
	f.gradient = gradient
	f.Iterations = 12
	f.Center = cx.New(0, 0)
	f.Z0 = cx.New(0, 0)
	f.Zoom = cx.New(3.5, 1.0)
	f.Precision = 64
	return f
}
Пример #2
0
//move vector in texcoords
func (f *Fractal) MoveCenter(v *Vec2) {
	var c = cx.NewFromVec2(v)
	var pointFive = cx.New(.5, .5)
	defer c.Clear()
	defer pointFive.Clear()
	c.Subi(pointFive)
	c.MuliComponents(f.Zoom)
	f.Center.Addi(c)
}
Пример #3
0
func (f *Fractal) CreateTexture() *texture.Texture {
	f.reloadPrecision()
	var ratio = cx.NewFloat(f.Ratio())
	f.Zoom.SetY(f.Zoom.X)
	f.Zoom.MulY(ratio)
	var halfToUpperRight = f.Zoom.MulsDouble(.5)
	var lowerLeft = f.Center.Sub(halfToUpperRight)
	var wh = cx.New(Double(f.width), Double(f.height))
	var fxy = f.Zoom.DivComponents(wh)
	var coord = lowerLeft.Copy()
	defer func() {
		ratio.Clear()
		halfToUpperRight.Clear()
		lowerLeft.Clear()
		wh.Clear()
		fxy.Clear()
		coord.Clear()
	}()
	var sum Double = 0.0
	var col *Color24 = NewColor24(0, 0, 0)
	var intensity Double
	Printf("Idle time: ")
	util.Ts()
	cx.SetIterations(f.Iterations)
	for y := 0; y < f.height; y++ {
		coord.SetX(lowerLeft.X)
		coord.AddY(fxy.Y)
		for x := 0; x < f.width; x++ {
			coord.AddX(fxy.X)
			intensity = Double(f.Z0.DoMandel(coord)) / Double(f.Iterations)
			//intensity = intensity.Sqrt()
			f.gradient.Interpolate(col, intensity)
			f.grid.SetPixel24(x, y, col)
		}
		sum += intensity
	}
	Printf(">>>>>>>>>>>>>>>> Math time: ")
	util.Ts()
	f.renewTexture()
	Printf("GL time: ")
	util.Ts()
	Println("Intensity sum:", sum, col)
	return f.tex
}