summaryrefslogtreecommitdiff
path: root/src/main.scala
blob: 8883cc7d75c18a489f0bc7dda01eebe3f0166605 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import net.iximeow.raytrace._
import Objects._

object main extends App {
//  val mirror = Scene(Scene.generateMirror(10, 60, Raymath.toRadians(180), Point(0, 0), 0))
  val offset = Point(0.0, -9)
  val mirror = Scene(Scene.generateParabola(-0.9, -0.0075, 16, 0, 42, Point(0, 14), 0) :+ Segment.fromPoints(
    Point(-0.5, 0.5) + offset,
    Point(0.5, -0.5) + offset
  ))
//  val mirror = Scene(Seq(Segment(4, -4, Point(-2, 2))))
  //val ray = mirror.cast(Ray(0, 2, Point(0.8, -1)), 4)
  mirror.render(scale = 20, color = 0xc0c0c0, normals = true)
  //for (segment <- ray) {
  //  segment.renderTo(mirror.buffer, 20, 400, 300)
  //}
/*
  for (i <- -4 to 4 by 1) {
    for (segment <- mirror.cast(Ray(i / 2.0, 2, Point(0.8, -1)), 4)) {
      segment.renderTo(mirror.buffer, 20, 400, 300)
    }
  }
*/
  def rays(number: Int, spacing: Double, centerpoint: Point, direction: Point): Seq[Ray] = {
    (0 until number).map { i =>
      val x = (i.toDouble - number.toDouble / 2) * spacing
      val y = 0
      val dx = direction.x
//        * Math.cos((i.toDouble - number.toDouble) / (number.toDouble / 4))
      val dy = direction.y
      Ray(dx, dy, Point(x, y) + centerpoint)
    }
  }

  rays(63, 0.165, Point(-0, -10), Point(0.0, 2))
    .flatMap(x => mirror.cast(x, 30))
    .map(_.renderTo(mirror.buffer, 20, 400, 300))
  //println(ray)
  mirror.save()
}