Exemple #1
0
// relative value
func (p *Parameters) MoveRelativeLocation(x, y float64) {

	normRelativeValue := func(x float64) float64 {
		if x < -1 {
			x = -1
		}
		if x > 1 {
			x = 1
		}
		return x
	}

	x = normRelativeValue(x)
	y = normRelativeValue(y)

	loc := &(p.FractalInfo.Location)

	var m mth2d.Matrix
	m.InitIdendity()
	m.Scale(loc.Radius, loc.Radius)
	m.Rotate(degToRad(loc.Angle))
	m.Translate(loc.Center.Re, loc.Center.Im)

	loc.Center.Re, loc.Center.Im = m.TransformPoint(x, y)
}
Exemple #2
0
func RenderImageRGBA(m *image.RGBA, params Parameters) {

	var (
		nX = m.Rect.Dx()
		nY = m.Rect.Dy()

		fi         = params.FractalInfo
		pixelWidth = 2 * fi.Location.Radius / float64(min(nX, nY))
		center     = fi.Location.Center
	)

	var transform mth2d.Matrix
	transform.InitIdendity()
	transform.Translate(-float64(nX)/2, -float64(nY)/2)
	transform.Scale(pixelWidth, pixelWidth)
	mth2d.ReflectAxisX(&transform)
	transform.Rotate(degToRad(fi.Location.Angle))
	transform.Translate(center.Re, center.Im)

	numCPU := runtime.NumCPU()
	countY, countX := nearDivs(numCPU)

	var (
		xIns = interval.Interval{Max: nX}.Split(countX)
		yIns = interval.Interval{Max: nY}.Split(countY)
	)

	si := newSyncImage(m)
	c := newColorСomputer(params, transform)

	wg := new(sync.WaitGroup)

	for _, yIn := range yIns {
		for _, xIn := range xIns {

			var (
				r = image.Rectangle{
					Min: image.Point{xIn.Min, yIn.Min},
					Max: image.Point{xIn.Max, yIn.Max},
				}
				cc = c.Clone()
			)

			wg.Add(1)
			go renderRectangle(wg, r, cc, si)
		}
	}

	wg.Wait()
}