Guest User

Untitled

a guest
Dec 12th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. package s1.demo
  2. import scala.collection.mutable.Queue
  3. import scala.math._
  4.  
  5.  
  6. import java.awt.Color._
  7. import java.awt.BasicStroke
  8. import scala.util.Random
  9. import o1._
  10. import o1.gui._
  11.  
  12.  
  13. case class Pukki(x: Double, y: Double) {
  14. //Circles do not like being too close to each other.
  15. // def tooNear(other: Triangle) = math.hypot(this.x - other.x, this.y - other. y) < 5
  16. }
  17.  
  18. object omaLuomus extends Effect(500,500) {
  19.  
  20.  
  21. var last = Pukki(0,250)
  22.  
  23. val y1 = (0 until 500).map(_ / 10.0).map(i => sin(i)).toVector
  24. val x1 = (0 until 500).toVector
  25. var k = 0
  26. val random = new Random
  27.  
  28.  
  29.  
  30.  
  31. val snowRadius = 5
  32. private val snowSpeed1 = 5
  33. private val snowSpeed2 = 10
  34. private var currentPos = randomLaunchPosition
  35.  
  36. def pos = this.currentPos
  37.  
  38. private def randomLaunchPosition() = {
  39. val launchX = snowRadius + 1000 + Random.nextInt(499)
  40. val launchY = Random.nextInt(400)
  41. new Pos(launchX, launchY)
  42. }
  43.  
  44. def lumiIsActive = {
  45. if (pos.x >= -snowRadius) true
  46. else false
  47. }
  48.  
  49. def lumiApproach() = {
  50. if (lumiIsActive == true) this.currentPos = this.currentPos.addX(-snowSpeed1)
  51. else {
  52. this.currentPos = randomLaunchPosition
  53.  
  54. }
  55. }
  56.  
  57.  
  58. def changeThings() = {
  59.  
  60. // Calculate the new coordinates
  61. val xdiff = x1(k) * 2
  62. val ydiff = y1(k) * 30
  63.  
  64. val x = xdiff
  65. val y = (250 + ydiff)
  66. last = new Pukki(x,y)
  67.  
  68. k += 1
  69.  
  70. if(last.x == 500 || last.y == 500) {
  71. k = 0
  72. last = new Pukki(0,250)
  73. }
  74.  
  75.  
  76. this.lumiApproach
  77.  
  78.  
  79.  
  80.  
  81.  
  82. }
  83.  
  84.  
  85. override def makePic(): Pic = {
  86. val background = rectangle(this.width, this.height, Black)
  87. var pic = background
  88.  
  89.  
  90. var paa = (circle(25,White).below(triangle(10,5,Red)))
  91.  
  92. pic = paa.against(pic, new Pos(last.x, last.y))
  93.  
  94.  
  95.  
  96. val lumet1 = Vector(circle(snowRadius, White), circle(snowRadius, White))
  97. val lumet2 = Vector(circle(snowRadius, Grey), circle(snowRadius, Grey))
  98.  
  99. for{lumi <- lumet1
  100. x <- lumet2 }{
  101.  
  102. pic = lumi.against(pic, this.pos)
  103. pic = x.against(pic,this.pos)
  104. }
  105.  
  106.  
  107. pic
  108. }
  109.  
  110.  
  111. override def next = false
  112. }
Advertisement
Add Comment
Please, Sign In to add comment