예제 #1
0
// Requires visual inspection of stdout
func TestMakeFragments(t *testing.T) {
	const (
		w = 20
		h = 30
		a = 12
		b = 14
	)
	src := MakeAnimation(5, false, 1)
	dst := nimble.MakePixMap(w, h, make([]nimble.Pixel, w*h), w)
	background := nimble.RGB(0.5, 0.25, 1)
	foreground := nimble.RGB(0.25, 1, 0.25)
	dst.Fill(background)
	Draw(dst, a, b, src[0], foreground)

	// Result should be a filled circle
	for y := int32(0); y < dst.Height(); y++ {
		for x := int32(0); x < dst.Width(); x++ {
			r2 := (x-a)*(x-a) + (y-b)*(y-b)
			var e nimble.Pixel
			if r2 <= 25 {
				e = foreground
			} else {
				e = background
			}
			if e != dst.Pixel(x, y) {
				t.Fail()
				panic(fmt.Sprintf("x=%v y=%v e=%v\n", x, y, e))
			}
		}
	}
}
예제 #2
0
// CopyCLUT returns a PixMap copy the color lookup table.
// It is intended only for debugging.
func CopyCLUT() (pm nimble.PixMap) {
	pm = nimble.MakePixMap(clutSize, clutSize, make([]nimble.Pixel, clutSize*clutSize), clutSize)
	for y := int32(0); y < clutSize; y++ {
		copy(pm.Row(y), clut[y][:])
	}
	return
}
예제 #3
0
// Init prepares state used by Draw.
func Init(width, height int32) {
	if width < 3 || height < 3 {
		panic(fmt.Sprintf("score.Init: width=%v height=%v\n", width, height))
	}
	lightWidth = width / 6
	lightHeight = height
	lightStorage = make([]nimble.Pixel, nLight*2*lightHeight*lightWidth)
	xScale := 2.0 / float32(lightWidth-2)
	yScale := 2.0 / float32(lightHeight-2)
	xOffset := -.5 * xScale * float32(lightWidth)
	yOffset := -.5 * yScale * float32(lightHeight)
	for k, color := range lightColor {
		for s := state(0); s < state(2); s++ {
			pm := nimble.MakePixMap(lightWidth, lightHeight, getLight(k, s), lightWidth)
			for i := int32(0); i < lightHeight; i++ {
				for j := int32(0); j < lightWidth; j++ {
					x := float32(j)*xScale + xOffset
					y := float32(i)*yScale + yOffset
					factor := 1 - x*x - y*y
					if factor < 0 {
						factor = 0
					}
					if s == 0 {
						// The light is off, so dim the image
						factor *= .25
					}
					pm.SetPixel(j, i, nimble.RGB(color.r*factor, color.g*factor, color.b*factor))
				}
			}
		}
	}
}
예제 #4
0
// Draw draws the score (as binary lights) on the given PixMap.
func Draw(pm nimble.PixMap, scoreValue int) {
	if pm.Height() != lightHeight {
		panic(fmt.Sprintf("score.Draw: pm.Height()=%v lightHeight=%v\n", pm.Height(), lightHeight))
	}
	for k := range lightColor {
		s := state(scoreValue >> uint(nLight-k-1) & 1)
		src := nimble.MakePixMap(lightWidth, lightHeight, getLight(k, s), lightWidth)
		pm.Copy(lightWidth*int32(k), 0, &src)
	}
}
예제 #5
0
// PastelPalette returns a palette of pastel colors.
// The pallette is returned as a PixMap with one row for each hue,
// which fades to black with increasing column indices.
func PastelPalette(nHue, nShade int32) (pm nimble.PixMap) {
	pm = nimble.MakePixMap(nShade, nHue, make([]nimble.Pixel, nHue*nShade), nShade)
	for h := int32(0); h < nHue; h++ {
		r, g, b := rgbOfHue(h, nHue)
		scale := 1 / float32(nShade)
		row := pm.Row(h)
		for j := int32(0); j < nShade; j++ {
			f := float32(nShade-j) * scale
			row[j] = nimble.RGB(r*f, g*f, b*f)
		}
	}
	return
}
예제 #6
0
func Draw(pm nimble.PixMap, cm colorMap, running bool) {
	setColoring(cm)
	width, height := pm.Size()
	if width != xSize || height != ySize {
		panic(fmt.Sprintf("radar.Draw: (width,height)=(%v,%v) (xSize,ySize)=(%v,%v)\n",
			width, height, xSize, ySize))
	}
	src := nimble.MakePixMap(width, height, getFrame(frameCounter), width)
	pm.Copy(0, 0, &src)
	if running {
		frameCounter = (frameCounter + 1) % (int32(len(frameStorage)) / frameSize)
	}
}
예제 #7
0
	foreground := nimble.RGB(0.25, 1, 0.25)
	dst.Fill(background)
	Draw(dst, a, b, src[0], foreground)

	// Result should be a filled circle
	for y := int32(0); y < dst.Height(); y++ {
		for x := int32(0); x < dst.Width(); x++ {
			r2 := (x-a)*(x-a) + (y-b)*(y-b)
			var e nimble.Pixel
			if r2 <= 25 {
				e = foreground
			} else {
				e = background
			}
			if e != dst.Pixel(x, y) {
				t.Fail()
				panic(fmt.Sprintf("x=%v y=%v e=%v\n", x, y, e))
			}
		}
	}
}

var src = MakeAnimation(10, false, 1)
var dst = nimble.MakePixMap(500, 500, make([]nimble.Pixel, 500*500), 500)

func BenchmarkDraw(b *testing.B) {
	for n := 0; n < b.N; n++ {
		Draw(dst, 250, 250, src[0], nimble.Gray(1))
	}
}
예제 #8
0
// Init initializes state used by Draw.  Init should be called once with width and
// height values matching the size of the PixMap passed to future calls to Draw.
func Init(width, height int32) {
	background = nimble.MakePixMap(width, height, make([]nimble.Pixel, height*width), width)
	background.Fill(nimble.Black)
}