示例#1
0
// Init specifies the size of the PixMap seen by subsequent calls to Draw
func Init(width, height int32) {
	if width < 0 || height < 0 {
		panic(fmt.Sprintf("radar.Init: width=%v height=%v\n", width, height))
	}
	xSize, ySize = width, height

	xScale = 2 / float32(width-1)
	yScale = 2 / float32(height-1)
	xOffset = 1.0 - xScale*float32(width)
	yOffset = 1.0 - yScale*float32(height)

	// Allocate clut
	clut = make([]rgb, height*width)

	// Allocate frames
	frameSize = height * width
	frameStorage = make([]nimble.Pixel, nFrame*frameSize)
	frameValid = make([]bool, nFrame)

	// Compute polar coordinates
	angle = make([]float32, height*width)
	for i := int32(0); i < height; i++ {
		for j := int32(0); j < width; j++ {
			x := float32(j)*xScale + xOffset
			y := float32(i)*yScale + yOffset
			if x*x+y*y <= 1 {
				angle[i*width+j] = math32.Atan2(-y, x)
			} else {
				angle[i*width+j] = outsideUnitCircle
			}
		}
	}
}
示例#2
0
func (scheme SchemeBits) Color(x, y float32) (r, g, b float32) {
	if scheme&RealBit == 0 {
		x = 0
	}
	if scheme&ImagBit == 0 {
		y = 0
	}
	θ := math32.Atan2(-y, x)
	d := math32.Hypot(x, y)
	if d > 1 || scheme&MagnitudeBit == 0 {
		d = 1.0
	}
	if scheme&PhaseBit == 0 {
		r, g, b = d, d, d
	} else {
		r, g, b = phaseColor(θ)
		r *= d
		g *= d
		b *= d
	}
	if scheme&RedBit == 0 {
		r = 0
	}
	if scheme&GreenBit == 0 {
		g = 0
	}
	if scheme&BlueBit == 0 {
		b = 0
	}
	return
}