Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / PrettyBug.elm
Created December 18, 2014 02:29
Tried to make a sphere and all I got was this bug
sphereMesh : Int -> Vec3 -> Float -> Mesh
sphereMesh tesselation center radius =
let normalize = (flip (/)) (toFloat tesselation)
shift = (+) -0.5
scale = (*) (2 * radius)
transform = normalize >> shift >> scale
latitudes = map transform (map toFloat [0..tesselation])
longitudes = latitudes
plotPoint longitude latitude =
let cosLatitude = cos (pi * latitude / (toFloat tesselation))
@TheSeamau5
TheSeamau5 / FunctionalDataStructures.elm
Created December 25, 2014 00:03
Stacks and Queues
-- STACKS
type Stack a = Bottom | Element a (Stack a)
push : a -> Stack a -> Stack a
push element stack =
Element element stack
pop : Stack a -> (Maybe a, Stack a)
@TheSeamau5
TheSeamau5 / Maybe.cpp
Last active May 24, 2020 20:16
Maybe in C++
#include <string>
#include <functional>
using namespace std;
template <typename T>
struct Maybe{
T just;
bool isNothing;
};
@TheSeamau5
TheSeamau5 / Tuple.cpp
Created December 25, 2014 02:58
Tuples in C++
#include <string>
using namespace std;
template <typename First, typename Second>
struct Tuple{
First first;
Second second;
};
@TheSeamau5
TheSeamau5 / Compute.elm
Created December 29, 2014 15:29
Function to perform a given operation a given number of times
compute : Int -> (a -> a) -> a -> a
compute iterations function argument =
if (iterations <= 0) then argument
else compute (iterations - 1) function (function argument)
@TheSeamau5
TheSeamau5 / EntityComponentSystemExploration.md
Created December 29, 2014 23:16
An exploration of the Entity Component System in Elm

#Exploring Entity Component Systems in Elm

Entity-Component-System (or ECS) is a pattern for designing programs that is prevalent in the games industry. This pattern consists of three simple parts:

  • Entity : A uniquely identifiable object that may contain any number of components
  • Component : A property usually representing the raw data of one aspect of the object. (Position is a component, Velocity is a component, Strength is a component, etc...)
  • System : A continuous process performing actions on every entity that possesses a component of the same aspect as that system

To understand this, let us try to make a simple example: Boxes that move in space:

@TheSeamau5
TheSeamau5 / UpdateComponent.coffee
Created December 30, 2014 04:28
General Update Component in Coffeescript
updateComponent = (updater, componentName, entity, requirementList) ->
requirementList = requirementList || [];
if (requirementList[requirement] for requirement in requirementList)?
output = clone entity
output[componentName] = updater output[componentName], output
return output
@TheSeamau5
TheSeamau5 / UpdatePosition.coffee
Created December 30, 2014 04:30
Example of using updateComponent
Vector = (x,y) ->
x : x || 0,
y : y || 0
vAdd = (v,w) -> Vector (v.x + w.x), (v.y + w.y)
clone = (obj) ->
if not obj? or typeof obj isnt 'object'
return obj
@TheSeamau5
TheSeamau5 / NewRecordEntityComponentSystem.elm
Last active June 12, 2017 03:23
Example under the New Record Entity Component System
import List (map, (::))
import Color (Color, rgb)
import Keyboard (arrows)
import Signal (Signal, (<~), foldp)
import Graphics.Collage (square, circle, move, filled, collage, Form)
import Graphics.Element (Element)
type alias Vector = {
x : Float,
y : Float
type alias Entity = {
position : Vector,
velocity : Vector,
scale : Vector,
...
}
type alias World = List Entity
type alias ComponentCreator = Entity -> Entity