Git Product home page Git Product logo

webgl-playground's Introduction

WebGL Playground

Fork of evancz/elm-playground, but with WebGL backend.

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!

Changelog

4.0.0 -> 5.0.0

  1. Update WebGL.Shape2d to 3.0.0

3.0.1 -> 4.0.0

  1. Playground.Advanced move to own package WebGL.Shape2d example
  2. Playground.Keyboard.keys now is filled with the event.code instead of event.key
  3. Playground.delta computer.time - computer.time.delta
  4. Playground.now computer.time - computer.time.now
  5. Playground.Extra.scaleX moved to Playground.scaleX
  6. Playground.Extra.scaleY moved to Playground.scaleY

Type changes:

  1. Was Playground.Game - now is Playground.Playground
  2. Was Playground.Animation - now is Playground.Playground ()
  3. Was Playground.Picture - now is Playground.Playground ()
  4. Number - removed - just use Float

webgl-playground's People

Contributors

dependabot[bot] avatar justgook avatar passiomatic avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.