Skip to content

Instantly share code, notes, and snippets.

View jackmott's full-sized avatar

Jack Mott jackmott

  • Olo
  • Texas,USA
View GitHub Profile
@jackmott
jackmott / json.fs
Created June 19, 2018 12:59
customizing newtonsoft
namespace AlphaFront
module JsonCustomConverters =
open Newtonsoft.Json
open Microsoft.FSharp.Reflection
open System
open System.IO
type DuConverter() =
inherit JsonConverter()
@jackmott
jackmott / rustvc.c
Last active June 13, 2018 13:19
rust vs c
// An example of how tuples and treating if statements as expressions makes things nicer
// C version, a snippet from simlpex noise.
int i1, j1, k1; // Offsets for second corner of simplex in (i,j,k) coords
int i2, j2, k2; // Offsets for third corner of simplex in (i,j,k) coords
if (x0 >= y0) {
if (y0 >= z0) {
i1 = 1; j1 = 0; k1 = 0; i2 = 1; j2 = 1; k2 = 0;
}
@jackmott
jackmott / ast.rs
Created May 17, 2018 21:22
how to ast in rust
//represents an AST - such as Plus(Sin(x),y)
pub enum Op {
Plus ( Vec<Op> ),
Sin ( Vec<Op> ),
X,
Y,
Constant (f32),
Empty
}
@jackmott
jackmott / verts.go
Created April 17, 2018 23:50
vertices for opengl cube
vertices := []float32{
-0.5, -0.5, -0.5, 0.0, 0.0,
0.5, -0.5, -0.5, 1.0, 0.0,
0.5, 0.5, -0.5, 1.0, 1.0,
0.5, 0.5, -0.5, 1.0, 1.0,
-0.5, 0.5, -0.5, 0.0, 1.0,
-0.5, -0.5, -0.5, 0.0, 0.0,
-0.5, -0.5, 0.5, 0.0, 0.0,
0.5, -0.5, 0.5, 1.0, 0.0,
@jackmott
jackmott / img2tex.go
Created April 13, 2018 00:33
Golang img to sdl texture
func imgFileToTexture(renderer *sdl.Renderer, filename string) *sdl.Texture {
infile, err := os.Open(filename)
if err != nil {
panic(err)
}
defer infile.Close()
img, err := png.Decode(infile)
if err != nil {
@jackmott
jackmott / macfix.go
Created March 9, 2018 03:22
mac fix for rpg
package main
import (
"github.com/jackmott/rpg/game"
"github.com/jackmott/rpg/ui2d"
)
func main() {
game := game.NewGame(1, "game/maps/level1.map")
@jackmott
jackmott / apt.go
Created February 24, 2018 01:48
Expressions in Go
type Node interface {
Eval(x, y float32) float32
String() string
SetParent(parent Node)
GetParent() Node
GetChildren() []Node
SetChildren([]Node)
AddRandom(node Node)
AddLeaf(leaf Node) bool
NodeCount() int
@jackmott
jackmott / if.fs
Created February 12, 2018 01:43
if expression
x :=
if foo {
do_stuff() // returns an int
} else if bar {
a := do_stuff()
print("stuff"
3*a
} else {
5
}
@jackmott
jackmott / apt.go
Last active February 10, 2018 18:28
abstract picture tree
package apt
import (
"github.com/jackmott/noise"
"math"
"math/rand"
"strconv"
)
@jackmott
jackmott / draw.cs
Created December 22, 2017 18:33
monogame problem
public static void Draw(GameTime gameTime)
{
var effect = DDGame.contentManager.Load<Effect>("road");
effect.Parameters["TerrainTexture"].SetValue(MainState.level.tex);
effect.Parameters["MaskTexture"].SetValue(MainState.maskTex);
DDGame.batch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, effect);
DDGame.batch.Draw(MainState.roadTex, new Rectangle(0, 0, Settings.WINDOW_WIDTH, Settings.WINDOW_HEIGHT), Color.White);
DDGame.batch.End();
}