Source file: /examples/gizmos/2d/shapes.js

import {
  createCamera2D,
  EntityCommands,
  World,
  Color,
  Vector2,
  GizmoLineStyle,
  App,
  AppSchedule,
  Canvas2DRendererPlugin,
  DefaultPlugin,
  DOMWindowPlugin,
  FPSDebugger,
  Gizmo2D,
  Gizmo2DPlugin,
  typeidGeneric
} from 'wima'

class Demo { }

/**
 * @augments {Gizmo2D<Demo>}
 */
class DemoGizmo2D extends Gizmo2D { }

const app = new App()

// We have to alias the gizmo resource manually

app
  .setResourceAlias(typeidGeneric(Gizmo2D, [Demo]), DemoGizmo2D)
  .registerPlugin(new DefaultPlugin())
  .registerPlugin(new DOMWindowPlugin())
  .registerPlugin(new Canvas2DRendererPlugin())
  .registerPlugin(new Gizmo2DPlugin({
    label: Demo
  }))
  .registerSystem({ schedule: AppSchedule.Startup, system: init })
  .registerSystem({ schedule: AppSchedule.Startup, system: addDefaultCamera2D })
  .registerSystem({ schedule: AppSchedule.Update, system: update })
  .registerDebugger(new FPSDebugger())
  .run()

/**
 * @param {World} world
 */
function addDefaultCamera2D(world) {
  const commands = new EntityCommands(world)

  commands
    .spawn()
    .insertPrefab([...createCamera2D()])
    .build()
}

/**
 * @param {World} world
 */
function init(world) {
  const gizmo = world.getResource(DemoGizmo2D)

  gizmo.settings.lineWidth = 2
  gizmo.settings.lineStyle = GizmoLineStyle.Solid
}

/**
 * @param {World} world
 */
function update(world) {
  const gizmo = world.getResource(DemoGizmo2D)

  gizmo
    .translate(100, 150)
    .rect(50, 50, new Color(1, 1, 1, 1))
    .axes(20)
    .translate(150, 0)
    .ellipse(60, 40, new Color(1, 1, 1, 1))
    .axes(20)
    .translate(150, 0)
    .circle(50, new Color(1, 1, 1, 1))
    .axes(20)
    .reset()
    .translate(100, 300)
    .grid(new Vector2(10, 10), new Vector2(10, 10))
    .axes(20)
    .translate(150, 0)
    .line(new Vector2(-50, 0), new Vector2(50, 0))
    .axes(20)
    .reset()
}