This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.WebGL (..) | |
import Math.Vector3 (..) | |
import Math.Matrix4 (..) | |
type Attribute = {position : Vec3} | |
type Uniform = { rotationMatrix : Mat4} | |
type Varying = {} | |
mapMesh : (a -> b) -> [Triangle a] -> [Triangle b] | |
mapMesh = map << mapTriangle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
quickCheck : Generator a -> Int -> (a -> Bool) -> String | |
quickCheck randomGenerator numberOfCases testingCondition = | |
let listGenerator = list numberOfCases <| randomGenerator | |
testInputs = fst <| generate listGenerator (initialSeed 1) | |
getOutput input = (input, testingCondition input) | |
testOutputs = map getOutput testInputs | |
failingOutputs = filter (\x -> (snd x) == False) testOutputs | |
successString = "Ok, passed " ++ (toString numberOfCases) ++ " tests." | |
failingString fail = "The following input has failed the test: " ++ (toString fail) | |
in |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interleave : List a -> List a -> List a | |
interleave list1 list2 = | |
case list1 of | |
[] -> list2 | |
x :: xs -> | |
case list2 of | |
[] -> list1 | |
y :: ys -> y :: x :: interleave xs ys |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Graphics.Collage (move, filled, circle, Form, collage) | |
import Graphics.Element (Element) | |
import List (map, map2, (::), head, tail) | |
import Color (rgb) | |
--- GLOBALS YOU CAN MESS WITH | |
pointSize = 3 -- THE SIZE OF THE POINTS | |
pointColor = rgb 255 100 0 -- THE COLOR OF THE POINTS | |
iterations = 5 -- NUMBER OF ITERATIONS OF CATMULL-CLARK SUBDIVISION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mapAll : (a -> a -> a) -> List a -> List (List a) | |
mapAll f list = | |
let innerMapAll f tempList = | |
case tempList of | |
[] -> [] | |
x :: xs -> map (f x) list :: innerMapAll f xs | |
in innerMapAll f list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string> | |
using namespace std; | |
template <typename First, typename Second> | |
struct Tuple{ | |
First first; | |
Second second; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
compute : Int -> (a -> a) -> a -> a | |
compute iterations function argument = | |
if (iterations <= 0) then argument | |
else compute (iterations - 1) function (function argument) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |