main.nim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import nodesnim
  2. import random
  3. randomize()
  4. Window("ScreenSaver", 720, 480)
  5. var
  6. main = Scene("Main")
  7. img = load("img.png", GL_RGBA)
  8. sprite = Sprite()
  9. direction = Vector2()
  10. speed = 3f
  11. sprite.centered = false
  12. sprite.setTexture(img)
  13. sprite.process =
  14. proc() =
  15. let rect = Rect2(sprite.global_position, sprite.rect_size)
  16. if rect.x <= 0:
  17. direction = sprite.global_position.directionTo(Vector2(main.rect_size.x, rand(main.rect_size.y.int).float))
  18. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  19. elif rect.x+rect.w >= main.rect_size.x:
  20. direction = sprite.global_position.directionTo(Vector2(0, rand(main.rect_size.y.int).float))
  21. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  22. elif rect.y <= 0:
  23. direction = sprite.global_position.directionTo(Vector2(rand(main.rect_size.x.int).float, main.rect_size.y))
  24. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  25. elif rect.y+rect.h >= main.rect_size.y:
  26. direction = sprite.global_position.directionTo(Vector2(rand(main.rect_size.x.int).float, 0))
  27. sprite.filter = Color(rand(1f) + 0.5, rand(1f) + 0.5, rand(1f) + 0.5)
  28. sprite.move(direction*speed)
  29. main.addChild(sprite )
  30. addScene(main)
  31. setMainScene("Main")
  32. windowLaunch()