• Stars
    star
    107
  • Rank 323,587 (Top 7 %)
  • Language
    Elm
  • License
    BSD 3-Clause "New...
  • Created over 8 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create pictures, animations, and games with Elm!

Elm Playground

Create pictures, animations, and games with Elm!

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:

import Playground exposing (..)

main =
  picture
    [ rectangle brown 40 200
    , circle green 100
        |> moveUp 100
    ]

Play 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:

import Playground exposing (..)

main =
  animation view

view time =
  [ triangle orange 50
      |> rotate (spin 8 time)
  ]

It will do a full spin every 8 seconds.

Maybe try making a car with spinning octogons as wheels? Try using wave to move things back-and-forth? Try using 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:

import Playground exposing (..)

main =
  game view update (0,0)

view computer (x,y) =
  [ square blue 40
      |> move x y
  ]

update computer (x,y) =
  ( x + toX computer.keyboard
  , y + toY computer.keyboard
  )

Every game has three important parts:

  1. memory - Store information. Our examples stores (x,y) coordinates.
  2. update - Update the memory based on mouse movements, key presses, etc. Our example moves the (x,y) coordinate around based on the arrow keys.
  3. 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!

Share Your Results!

If you make something cool, please share a picture, GIF, or video on Twitter! Add #elmlang so we can find it!

And if you start using this package for teaching, please share about that the same way! I know McMaster Outreach has been using a previous iteration of this package to help 4th through 8th graders learn some programming, and I love seeing all the pictures and animations that have come out of that!

Future Work

I think it would be great to develop some learning resources that use "making games" as motivation for learning lists, records, custom types, etc.

My learning path was attempting to recreate Pong, then Breakout, then Space Invaders, and then Zelda. This sequence of games started me off just thinking about math for collisions, then about using lists to track many collisions, then making things fancier to handle moving ships, and finally, working with complex characters with health and inventory. Each new game built on the ones before, introducing new concepts gradually and giving me a long time to get comfortable with them.

That is what I did, but I think people should explore this independently! Maybe you have a path that works well for their 10th graders, maybe someone else has a path that works well for their 5th graders, etc.

My instinct is that we can make it really fun to learn programming, and I am excited to hear about anyone who makes progress in that general direction. So please share your materials and results!

More Repositories

1

elm-architecture-tutorial

How to create modular Elm code that scales nicely with your app
Elm
4,171
star
2

elm-todomvc

The TodoMVC app written in Elm, nice example for beginners.
Elm
1,220
star
3

start-app

DEPRECATED. Moved to elm-lang/html
Elm
392
star
4

elm-html

DEPRECATED. Moved to elm-lang/html
Elm
336
star
5

guide.elm-lang.org

My book introducing you to Elm!
Elm
318
star
6

elm-sortable-table

Sortable tables for whatever data you want to display
Elm
284
star
7

functional-programming-in-elm

DRAFT outlining some techniques of functional programming
Shell
230
star
8

airplane-mode

Airplanes are programming heaven. Airplane Mode turns off the bad internet. Yes docs, no facebook!
Python
122
star
9

url-parser

Parse URLs into nicely structured data
Elm
114
star
10

elm-html-and-js

Example of how to integrate Elm with HTML and JS
HTML
93
star
11

react-angular-ember-elm-performance-comparison

Comparing performance of Elm, React, Angular, and Ember
JavaScript
91
star
12

elm-http

DEPRECATED. This library is now called elm-lang/http
Elm
89
star
13

elm-markdown

Markdown parsing within Elm
Elm
88
star
14

first-person-elm

First-person navigation in a simple 3D world, written in Elm
Elm
85
star
15

focus

A library for getting and setting values in deeply nested data structures.
Elm
80
star
16

TodoFRP

Basic Todo list example, written with FRP in Elm
Elm
75
star
17

elm-graphics

The graphical building blocks that inspired Elm in the first place
Elm
55
star
18

elm-effects

DEPRECATED. Moved to elm-lang/core
Elm
46
star
19

automaton

experimental library for Arrowized FRP in Elm
Elm
41
star
20

elm-svg

DEPRECATED. Moved to elm-lang/svg
Elm
30
star
21

elm-syntax-highlighting

Syntax Highlighting for Elm in Sublime Text
30
star
22

time-zone-proposal

A proposal for accurately computing local time in JavaScript
29
star
23

elm-hack-night

Elm
28
star
24

virtual-dom

DEPRECATED. Full rewrite in elm-lang/virtual-dom
JavaScript
25
star
25

elm-format-on-save

Sublime Text plugin to run elm-format on save
Python
23
star
26

local-channel

Helps you write self-contained components in Elm
Elm
16
star
27

elm-project-survey

How do build times and asset sizes change as Elm projects grow larger?
Haskell
13
star
28

task-tutorial

Friendly functions for getting started with tasks
JavaScript
11
star
29

elm-at-strangeloop

6
star
30

elm-at-mloc-js

Slides and resources from the mloc.js conference in Budapest! Graciously hosted by Prezi :)
5
star
31

elm-at-pldi-2013

A presentation written entirely in Elm, made for a talk at PLDI 2013.
Elm
4
star
32

codemesh-tutorial

self-contained exercises that emphasize fundamentals and the Elm Architecture
JavaScript
4
star
33

cufp-tutorial

Practice problems for the Elm tutorial at CUFP 2014
Elm
2
star