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 / ECSExampleInES6.js
Last active September 16, 2022 21:41
ECS Example in Javascript / ES6
// HELPER FUNCTIONS
const has = (entity, components) => {
const exists = (x) => typeof x !== "undefined";
return components.map((component) => exists(entity[component]))
.reduce((x,y) => x && y);
};
const clone = (object) => {
if (object === null || typeof object !== 'object'){
return object;
@TheSeamau5
TheSeamau5 / ECSExampleInDartOOPStyle.dart
Created January 7, 2015 22:24
ECS Example in Dart using OOP
class Point {
final num x;
final num y;
const Point(this.x, this.y);
Point operator + (Point p) {
return new Point(p.x + x, p.y + y);
}
Point scale(num factor){
return new Point(x * factor, y * factor);
}
@TheSeamau5
TheSeamau5 / IdealizedECS
Last active January 27, 2018 10:31
Idealized vision of using Entity Component Systems
----------------------------
----- TYPE DEFINITIONS -----
----------------------------
Entity : Object
Component : Object
DeltaTime : Component
deltaTime : Number
@TheSeamau5
TheSeamau5 / SimpleHexGrid.elm
Last active February 8, 2016 22:05
Simple way to create a hexagonal grid in Elm
import List (..)
import Text (asText)
import Graphics.Collage (..)
import Graphics.Element (..)
import Color (..)
--Based on http://www.redblobgames.com/grids/hexagons/
type alias Point = {
x : Int,
@TheSeamau5
TheSeamau5 / Pong3D.elm
Last active August 29, 2015 14:13
Pong in 3d using Graphics Engine in Elm
import Engine (..)
import Engine.Material.Material (MaterialProperty)
import Math.Vector3 (vec3, Vec3)
import Engine.Shader.GouraudShader (gouraudShader)
import Time (..)
import Signal (..)
import Keyboard
import Window
@TheSeamau5
TheSeamau5 / shuffleList.elm
Created January 18, 2015 02:11
Function to shuffle a list (useful to shuffle cards for example)
import List (..)
import Random (..)
import Text (asText)
shuffle : List a -> List a
shuffle lt =
let len = length lt
fgen = float 0 1
lgen = list len fgen
rlist = fst <| generate lgen (initialSeed 31415)
@TheSeamau5
TheSeamau5 / Loops.elm
Created January 24, 2015 23:43
A neat construct to loop in Elm without worrying about stack problems
loop : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> b
loop start condition update return =
trampoline <|
loop' start condition update return
loop' : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> Trampoline b
loop' start condition update return =
case condition start of
True -> Done (return start)
@TheSeamau5
TheSeamau5 / QuadTree.elm
Created January 25, 2015 16:28
Quadtrees in Elm
import Array (..)
import Text (asText)
import Graphics.Collage (..)
import Color (..)
drawBox box =
move (box.horizontal.low + boxHalfWidth box, box.vertical.low + boxHalfHeight box) <|
outlined (solid black) <|
rect (boxWidth box) (boxHeight box)
@TheSeamau5
TheSeamau5 / mapAllArray.elm
Created January 25, 2015 19:00
mapAll for Arrays
mapAll : (a -> a -> a) -> Array a -> Array (Array a)
mapAll f array =
let innerMap tempArray =
case head tempArray of
Nothing -> empty
Just x -> push (map (f x) array) (innerMap (rest tempArray))
in
innerMap array
@TheSeamau5
TheSeamau5 / interface.elm
Last active August 29, 2015 14:14
Opinion on how typeclasses would look in Elm
interface Numerical a = {
(+) : a -> a -> a,
(-) : a -> a -> a,
(*) : a -> a -> a,
negate : a -> a,
abs : a -> a
}
implementation Numerical Float = {
(+) = Native.Float.add,