// Draw the "fall" view onto the given PixMap. func Draw(pm nimble.PixMap, invaders []Invader) { if pm.Width() != background.Width() || pm.Height() != background.Height() { panic("fall.Draw: pm and background differ in size") } drawDot := false time := nimble.Now() if time-lastDotTime >= dotTimeInterval { lastDotTime = time drawDot = true } pm.Copy(0, 0, &background) xScale := float32(pm.Width() - tickHalfWidth) // Avoid clipping tic on right side yScale := float32(pm.Height() - tickHalfHeight) // Avoid clippling tic on bottom xOffset := float32(0) yOffset := float32(0) for _, inv := range invaders { x := int32(inv.Amplitude*xScale + xOffset) y := int32(inv.Progress*yScale + yOffset) r := nimble.Rect{ Left: x - tickHalfWidth, Top: y - tickHalfHeight, Right: x + tickHalfWidth, Bottom: y + tickHalfHeight, } pm.DrawRect(r, inv.Color) background.DrawRect(r, nimble.Black) if drawDot { if doty := r.Top - 1; background.Contains(x, doty) { background.SetPixel(x, doty, inv.Color) } } } }
// 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) } }
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) } }