package elm_playground
Install
dune-project
Dependency
Authors
Maintainers
Sources
md5=0db3aca4366c3bfded23fc0b1dd54014
sha512=c2dc6e2dfe7e960370f22dbd1d65e6cf1a09deeb8f30932d781267c1563083e0a64707858d23c1a8ce9e3d66d7466e0e400e1c2bbabaa676dd2dbf1bc33acc33
doc/index.html
elm_playground
OCaml Elm Playground
Create pictures, animations, and games with OCaml!
This is a port of the excellent Elm playground package to OCaml.
This is the package I wanted when I was learning programming. Start by putting shapes on screen and work up to making games. I hope this package will be fun for a broad range of ages and backgrounds!
Pictures
A picture is a list of shapes. For example, this picture combines a brown rectangle and a green circle to make a tree
open Playground
let app =
picture [
rectangle brown 40. 200.;
circle green 100.
|> move_up 100.;
]
let main = Playground_platform.run_app appPlay around to get familiar with all the different shapes and transformations in the library.
Animations
An animation is a list of shapes that changes over time. For example, here is a spinning triangle:
open Playground
let view time = [
triangle orange 50.
|> rotate (spin 8. time);
]
let app = animation view
let main = Playground_platform.run_app appIt will do a full spin every 8 seconds.
Maybe try making a car with spinning octogons as wheels? Try using Playground.wave to move things back-and-forth? Try using Playground.zigzag to fade things in-and-out?
Games
A game lets you use input from the mouse and keyboard to change your picture. For example, here is a square that moves around based on the arrow keys:
open Playground
let view _computer (x, y) = [
square blue 40.
|> move x y
]
let update computer (x, y) =
(x +. to_x computer.keyboard, y +. to_y computer.keyboard)
let app =
game view update (0., 0.)
let main = Playground_platform.run_app appEvery game has three important parts:
memory- Store information. Our example stores(x,y)coordinates.update- Update the memory based on mouse movements, key presses, etc. Our example moves the(x,y)coordinate around based on the arrow keys.view- Turn the memory into a picture. Our example just shows one blue square at the(x,y)coordinate we have been tracking in memory.
When you start making fancier games, you will store fancier things in memory. There is a lot of room to develop your programming skills here: Making lists, using records, creating custom types, etc.
I started off trying to make Pong, then worked on games like Breakout and Space Invaders as I learned more and more. It was really fun, and I hope it will be for you as well!
Animated sprites
To make characters like Mario walk, see Making animated sprites.
Index of modules
PlaygroundPlayground_platform