A Billiards Simulator in Elm

Image for post
Image for post

About developing with Elm

About the code

Billiards

type alias Model =
{ simulatorState : SimulatorState
, count : Int
, x_max : Float
, y_max : Float
, particles : Particles
, graphMap : Graph.GraphMap
, message : String
, info : String
}
type alias Particles =
{ a : Particle, b : Particle }
renderParticle : Model -> Particle -> S.Svg msgrenderParticle model particle =
Graph.drawCircle model.graphMap particle.circle

XColor

type alias XColor =
{ r : Int, g : Int, b : Int, a : Float }
blueColor =
XColor 0 0 255 1.0

Geometry

type alias Circle =
{ center : Point, radius : Float, fillColor : XColor,
strokeColor : XColor }
distance : Point -> Point -> Float

Physics

type alias Vector =
{ x : Float, y : Float }
type alias Particle =
{ circle : Geometry.Circle
, velocity : Vector
, mass : Float
}

Graphics

type alias GraphMap =
{ sourceRect : Rect
, targetRect : Rect
}

Written by

jxxcarlson on elm slack, http://jxxcarlson.github.io

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store