Skip to content

Instantly share code, notes, and snippets.

var magnitude = function(xcomp,ycomp) { return Math.sqrt(xcomp*xcomp + ycomp*ycomp); };
var RESOLUTION = window.innerWidth/2; // 320;
var HEIGHT = window.innerHeight/2; //480;
var div = function(x,y){ return Math.floor(x/y) };
var mod
var CIRCLE = Math.PI * 2;
function Controls() {
this.codes = { 37: 'left', 39: 'right', 38: 'forward', 40: 'backward' };
@svanellewee
svanellewee / prototypal.lua
Created August 21, 2014 07:40
So Lua supports prototypal OOP!
--[[
javascript:
function SomeObject(name) {
this.name = name
}
SomeObject.prototype.getName = function() {
return "My Name is "+this.name+"!";
}
/* lessons learnt:
- inside other functions you can't do func bla ();
(use bla := func() ...)
- Too many values usually indicates you didnt specify return values in prototype
*/
type cbfunc func(int,float64);
foreach64 := func (xs []float64, fn func(int, float64)) {
for i,v := range(xs) {
fn(i,v);
@svanellewee
svanellewee / output.txt
Last active August 29, 2015 14:06
Simple Monad Experiment
20 [10.000000, was multiplied by 2]
23 [10.000000, was added to 13]
24 [12.000000, was multiplied by 2]
37 [12.000000, was multiplied by 2][24.000000, was added to 13]
56 [15.000000, was + 13][28.000000, was X2]
@svanellewee
svanellewee / lwjgl-not-boids-core.clj
Last active August 29, 2015 14:10
Kind of boids... but not really
(ns boids-gl.core
(:import (org.lwjgl LWJGLException )
(org.lwjgl.opengl Display DisplayMode GL11))
(:gen-class))
(defn start []
(let [ display (DisplayMode. 800 600) ]
(try
(do
@svanellewee
svanellewee / lwjgl-input-project.clj
Last active August 29, 2015 14:10
setting up user input
(defproject roggy "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[org.lwjgl.lwjgl/lwjgl "2.9.1"]
[org.lwjgl.lwjgl/lwjgl-platform "2.9.1"
:classifier "natives-osx"
;; LWJGL stores natives in the root of the jar; this
@svanellewee
svanellewee / blockmove.go
Last active April 21, 2019 17:09
Get a block to move with SDL2 and GoLang
package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
)
var winTitle string = "Go-SDL2 Events"
var winWidth, winHeight int = 800, 600
@svanellewee
svanellewee / ces_breakout.go
Created January 20, 2015 04:05
Component Entity System Golang SDL
package main
import (
"fmt"
"github.com/veandco/go-sdl2/sdl"
"os"
)
type (
AnyType interface{}
@svanellewee
svanellewee / lambda-functional-coolness.js
Last active August 29, 2015 14:14
Javascript + Church + Mcarthy
/*
according to Church you can represent a datastructure by means of a function like so:
\x\a\b.x(a,b) where a and b are given constants and x is a function to be provided later...
*/
function cons(head, tail) {
return function (e) {
return e(head, tail);
}
}
/*
@svanellewee
svanellewee / lisp.go
Last active August 29, 2015 14:16
Church Lambda; LISP in Go
package main
import "fmt"
type Any interface{}
type FuncType func(Any, Any) Any
type ConsType func(FuncType) Any
func Cons(a, b Any) ConsType {
return func(fn FuncType) Any {