Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. package main
  2.  
  3. import (
  4. "image"
  5. "image/color"
  6.  
  7. "github.com/faiface/pixel"
  8. "github.com/faiface/pixel/pixelgl"
  9. )
  10.  
  11. const (
  12. width = 512
  13. height = 512
  14. size = 256
  15. )
  16.  
  17. func run() {
  18. scale := float64(height) / float64(size)
  19.  
  20. win, err := pixelgl.NewWindow(pixelgl.WindowConfig{
  21. Bounds: pixel.R(0, 0, float64(width), float64(height)),
  22. VSync: true,
  23. Undecorated: true,
  24. Resizable: false,
  25. })
  26. if err != nil {
  27. panic(err)
  28. }
  29.  
  30. win.SetSmooth(false)
  31.  
  32. p := xorPicture(size, size)
  33. s := pixel.NewSprite(p, p.Bounds())
  34.  
  35. for !win.Closed() {
  36. win.Update()
  37.  
  38. s.SetMatrix(pixel.IM.Moved(win.Bounds().Center()).Scaled(
  39. win.Bounds().Center(), scale,
  40. ))
  41.  
  42. s.Draw(win)
  43.  
  44. if win.Pressed(pixelgl.KeyUp) {
  45. scale += 0.1
  46. }
  47.  
  48. if win.Pressed(pixelgl.KeyDown) {
  49. scale -= 0.1
  50. }
  51.  
  52. if win.JustPressed(pixelgl.KeyEscape) || win.JustPressed(pixelgl.KeyQ) {
  53. return
  54. }
  55. }
  56. }
  57.  
  58. func xorPicture(w, h int) *pixel.PictureData {
  59. m := image.NewRGBA(image.Rect(0, 0, w, h))
  60.  
  61. for x := 0; x < w; x++ {
  62. for y := 0; y < h; y++ {
  63. c := uint8(x ^ y)
  64.  
  65. m.Set(x, y, color.RGBA{c, c % 192, c, 255})
  66. }
  67. }
  68.  
  69. return pixel.PictureDataFromImage(m)
  70. }
  71.  
  72. func main() {
  73. pixelgl.Run(run)
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement