An FP game engine for Scala.

Shapes

Shapes allow you to draw simple graphics without needing images.

There are four Shape types that come shipped with Indigo at the time of writing, although we may add more in the future:

  1. Shape.Box - Any rectangle
  2. Shape.Circle - A circle centered around a point
  3. Shape.Line - A straight line made of two points
  4. Shape.Polygon - An arbitrary shape with up to 16 vertices.

They all share similar properties:

One limitation that shape strokes have, is that they are all solid and all use rounded corners. This is because of the way they are calculated. If there is interest we may look at adding more stroke effects like dashed lines or alternate capping types.

Below are examples of each to help get you started.

Box

import indigo.*

Shape.Box(
  Rectangle(Point(100, 100), Size(50, 50)),
  Fill.Color(RGBA.White),
  Stroke(4, RGBA.Blue)
)

Circle

Shape.Circle(
  center = Point(30, 30),
  radius = 20,
  fill = Fill.RadialGradient(
    Point(20),
    RGBA.Magenta,
    Point.zero,
    RGBA.Cyan
  ),
  stroke = Stroke(3, RGBA.White)
)

Line

Shape.Line(Point(30, 80), Point(100, 20), Stroke(6, RGBA.Cyan))

Polygon

Shape.Polygon(
  Fill.LinearGradient(Point(0), RGBA.Magenta, Point(45), RGBA.Cyan),
  Stroke(4, RGBA.Black)
)(
  Point(10, 10),
  Point(20, 70),
  Point(90, 90),
  Point(70, 20)
)