func main() { var err error const a0, a1, a2 = 0x40, 0xc0, 0xff pixels := []uint8{ a0, a1, a1, a0, a1, a2, a2, a1, a1, a2, a2, a1, a0, a1, a1, a0, } brushImage, err = ebiten.NewImageFromImage(&image.Alpha{ Pix: pixels, Stride: 4, Rect: image.Rect(0, 0, 4, 4), }, ebiten.FilterNearest) if err != nil { log.Fatal(err) } canvasImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) if err != nil { log.Fatal(err) } canvasImage.Fill(color.White) if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } fiveyearsImage, _, err = common.AssetImage("fiveyears.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } maskImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) if err != nil { log.Fatal(err) } as := image.Point{128, 128} a := image.NewAlpha(image.Rectangle{image.ZP, as}) for j := 0; j < as.Y; j++ { for i := 0; i < as.X; i++ { r := as.X / 2 d := math.Sqrt(float64((i-r)*(i-r) + (j-r)*(j-r))) b := uint8(max(0, min(0xff, 3*0xff-int(d*3*0xff)/r))) a.SetAlpha(i, j, color.Alpha{b}) } } spotLightImage, err = ebiten.NewImageFromImage(a, ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func (g *Game) Run(width, height, scale int, title string) error { ticker := time.NewTicker(time.Millisecond * 70) go func() { for range ticker.C { if ebiten.IsKeyPressed(ebiten.KeyR) { g.Score = 0 g.newMaze() } if ebiten.IsKeyPressed(ebiten.KeyLeft) && g.canGoLeft() { g.X-- } if ebiten.IsKeyPressed(ebiten.KeyRight) && g.canGoRight() { g.X++ } if ebiten.IsKeyPressed(ebiten.KeyUp) && g.canGoUp() { g.Y-- } if ebiten.IsKeyPressed(ebiten.KeyDown) && g.canGoDown() { g.Y++ } } }() defer ticker.Stop() return ebiten.Run(g.update, width, height, scale, title) }
func main() { var err error bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } w, h := bgImage.Size() const repeat = 5 repeatedBgImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest) if err != nil { log.Fatal(err) } for j := 0; j < repeat; j++ { for i := 0; i < repeat; i++ { op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(w*i), float64(h*j)) if err := repeatedBgImage.DrawImage(bgImage, op); err != nil { log.Fatal(err) } } } groundImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "infinite scroll"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, initScreenWidth, initScreenHeight, initScreenScale, "Window Size (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "HSV (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error game, err = twenty48.NewGame() if err != nil { log.Fatal(err) } if err := ebiten.Run(update, twenty48.ScreenWidth, twenty48.ScreenHeight, 2, "2048 (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = ebitenutil.NewImageFromFile("images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Rotate (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Alpha Blending (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { flag.Parse() m = mandelbrot.New(*width, *height, iterations(), mandelbrot.Colors(hex(*inside), hex(*outside))).Image() if err := ebiten.Run(update, *width, *height, *scale, "Plasma GUI"); err != nil { log.Fatal(err) } }
func main() { population := int((screenWidth * screenHeight) / 10) scale := 2.0 world = NewWorld(screenWidth, screenHeight) world.RandomSeed(population) noiseImage = image.NewRGBA(image.Rect(0, 0, screenWidth, screenHeight)) if err := ebiten.Run(update, screenWidth, screenHeight, scale, "Game of Life (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { wavF, err := ebitenutil.OpenFile("_resources/audio/jab.wav") if err != nil { log.Fatal(err) } oggF, err := ebitenutil.OpenFile("_resources/audio/ragtime.ogg") if err != nil { log.Fatal(err) } const sampleRate = 22050 const bytesPerSample = 4 // TODO: This should be defined in audio package audioContext, err = audio.NewContext(sampleRate) if err != nil { log.Fatal(err) } go func() { s, err := wav.Decode(audioContext, wavF) if err != nil { log.Fatal(err) return } seCh <- s close(seCh) }() go func() { s, err := vorbis.Decode(audioContext, oggF) if err != nil { log.Fatal(err) return } p, err := audio.NewPlayer(audioContext, s) if err != nil { log.Fatal(err) return } musicCh <- &Player{ audioPlayer: p, total: time.Second * time.Duration(s.Size()) / bytesPerSample / sampleRate, } close(musicCh) // TODO: Is this goroutine-safe? p.Play() }() if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Audio (Ebiten Demo)"); err != nil { log.Fatal(err) } if musicPlayer != nil { if err := musicPlayer.close(); err != nil { log.Fatal(err) } } }
func main() { var err error textImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := parseFont(); err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 1, "Font (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } w, h := gophersImage.Size() gophersRenderTarget, err = ebiten.NewImage(w/mosaicRatio, h/mosaicRatio, ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Mosaic (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error gophersImage, _, err = ebitenutil.NewImageFromFile("_resources/images/gophers.jpg", ebiten.FilterNearest) if err != nil { log.Fatal(err) } w, h := gophersImage.Size() const repeat = 5 repeatedGophersImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest) if err != nil { log.Fatal(err) } for j := 0; j < repeat; j++ { for i := 0; i < repeat; i++ { op := &ebiten.DrawImageOptions{} op.GeoM.Translate(float64(w*i), float64(h*j)) if err := repeatedGophersImage.DrawImage(gophersImage, op); err != nil { log.Fatal(err) } } } groundWidth := screenWidth + 70 groundImage, err = ebiten.NewImage(groundWidth, screenHeight*2/3+50, ebiten.FilterNearest) if err != nil { log.Fatal(err) } const fogHeight = 8 fogRGBA := image.NewRGBA(image.Rect(0, 0, groundWidth, fogHeight)) for j := 0; j < fogHeight; j++ { a := uint32(float64(fogHeight-1-j) * 0xff / (fogHeight - 1)) clr := skyColor r, g, b, oa := uint32(clr.R), uint32(clr.G), uint32(clr.B), uint32(clr.A) clr.R = uint8(r * a / oa) clr.G = uint8(g * a / oa) clr.B = uint8(b * a / oa) clr.A = uint8(a) for i := 0; i < groundWidth; i++ { fogRGBA.SetRGBA(i, j, clr) } } fogImage, err = ebiten.NewImageFromImage(fogRGBA, ebiten.FilterNearest) if err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Air Ship (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error if cursorImage, err = ebiten.NewImage(4, 4, ebiten.FilterNearest); err != nil { log.Fatal(err) } cursorImage.Fill(color.White) var speed, scale, width, height int flag.IntVar(&speed, "speed", 15, "simulation steps per second") flag.IntVar(&scale, "scale", 16, "pixel scale factor") flag.IntVar(&width, "width", 64, "width of the simulation") flag.IntVar(&height, "height", 64, "height of the simulation") flag.Parse() flag.Args() cursorPosition = image.Point{width / 2, height / 2} simulationTimer = time.Tick(time.Second / time.Duration(speed)) if flag.NArg() == 1 { inputFileName := flag.Arg(0) in, err := os.Open(inputFileName) if err != nil { fmt.Println(err) os.Exit(1) } gifImage, err := gif.DecodeAll(in) if err != nil { log.Fatal(err) } simulationImage = gifImage.Image[0] simulationImage.Palette[0] = color.Transparent } else { p := color.Palette{ color.Black, color.RGBA{0x88, 0, 0, 0xFF}, color.RGBA{0xFF, 0, 0, 0xFF}, color.RGBA{0xFF, 0x22, 0, 0xFF}, color.RGBA{0xFF, 0x44, 0, 0xFF}, color.RGBA{0xFF, 0x66, 0, 0xFF}, color.RGBA{0xFF, 0x88, 0, 0xFF}, color.RGBA{0xFF, 0xAA, 0, 0xFF}, } simulationImage = image.NewPaletted(image.Rect(0, 0, width, height), p) } reloadSimulation() if err := ebiten.Run(update, simulationImage.Bounds().Dx(), simulationImage.Bounds().Dy(), scale, "Wired Logic"); err != nil { log.Fatal(err) } }
func main() { var err error ebitenImage, _, err = ebitenutil.NewImageFromFile("images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } tmpRenderTarget, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest) if err != nil { log.Fatal(err) } //update := update //f, _ := os.Create("out.gif") //update = ebitenutil.RecordScreenAsGIF(update, f, 100) if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Alpha Blending (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { flag.Parse() if *cpuProfile != "" { f, err := os.Create(*cpuProfile) if err != nil { log.Fatal(err) } pprof.StartCPUProfile(f) defer pprof.StopCPUProfile() } game := blocks.NewGame() update := game.Update if err := ebiten.Run(update, blocks.ScreenWidth, blocks.ScreenHeight, 2, "Blocks (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { s, err := NewSprite("images/actor37_0.png") if err != nil { log.Fatal(err) } w, h := s.Size() s.SetScale(0.5, 0.5) x := (screenWidth / 2) - (float64(w) / 2 * s.ScaleX()) + (screenWidth / 3) y := 0 + (float64(h) / 3 * s.ScaleY()) s.SetPosition(x, y) if err := Attach(s); err != nil { log.Fatal(err) } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Ebiten Demo"); err != nil { log.Fatal(err) } }
func main() { var err error ebitenImage, _, err = common.AssetImage("ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } ebitenImageWidth, ebitenImageHeight = ebitenImage.Size() for i := range sprites.sprites { w, h := ebitenImage.Size() x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h) vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1 sprites.sprites[i] = &Sprite{ image: ebitenImage, x: x, y: y, vx: vx, vy: vy, } } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { var err error ebitenImage, _, err = ebitenutil.NewImageFromFile("_resources/images/ebiten.png", ebiten.FilterNearest) if err != nil { log.Fatal(err) } ebitenImageWidth, ebitenImageHeight = ebitenImage.Size() for i := range sprites.sprites { w, h := ebitenImage.Size() x, y := rand.Intn(screenWidth-w), rand.Intn(screenHeight-h) vx, vy := 2*rand.Intn(2)-1, 2*rand.Intn(2)-1 sprites.sprites[i] = &Sprite{ imageWidth: w, imageHeight: h, x: x, y: y, vx: vx, vy: vy, } } if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Sprites (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { if err := ebiten.Run(update, screenWidth, screenHeight, 2, "PCM (Ebiten Demo)"); err != nil { log.Fatal(err) } }
func main() { wavF, err := ebitenutil.OpenFile("_resources/audio/jab.wav") if err != nil { log.Fatal(err) } oggF, err := ebitenutil.OpenFile("_resources/audio/game.ogg") if err != nil { log.Fatal(err) } // This sample rate doesn't match with wav/ogg's sample rate, // but decoders adjust them. const sampleRate = 48000 const bytesPerSample = 4 // TODO: This should be defined in audio package audioContext, err = audio.NewContext(sampleRate) if err != nil { log.Fatal(err) } go func() { s, err := wav.Decode(audioContext, wavF) if err != nil { log.Fatal(err) return } b, err := ioutil.ReadAll(s) if err != nil { log.Fatal(err) return } seCh <- b close(seCh) }() go func() { s, err := vorbis.Decode(audioContext, oggF) if err != nil { log.Fatal(err) return } p, err := audio.NewPlayer(audioContext, s) if err != nil { log.Fatal(err) return } musicCh <- &Player{ audioPlayer: p, total: time.Second * time.Duration(s.Size()) / bytesPerSample / sampleRate, } close(musicCh) // TODO: Is this goroutine-safe? if err := p.Play(); err != nil { log.Fatal(err) return } }() if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Audio (Ebiten Demo)"); err != nil { log.Fatal(err) } if musicPlayer != nil { if err := musicPlayer.close(); err != nil { log.Fatal(err) } } }
func main() { noiseImage = image.NewRGBA(image.Rect(0, 0, screenWidth, screenHeight)) if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Noise (Ebiten Demo)"); err != nil { log.Fatal(err) } }