Skip to content

Instantly share code, notes, and snippets.

@tuttlem
tuttlem / blockchain.cpp
Created August 15, 2017 13:25
Blockchain example
#include <chrono>
#include <sstream>
#include <string>
#include <memory>
#include <iostream>
#include <cstdlib>
#include "picosha2.h"
class block {
@tuttlem
tuttlem / DoubleBufferDemo.java
Created March 19, 2017 08:17
Basic Rendering Code
import java.awt.BorderLayout;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferStrategy;
import java.util.Timer;
import java.util.TimerTask;

Keybase proof

I hereby claim:

  • I am tuttlem on github.
  • I am tuttlem (https://keybase.io/tuttlem) on keybase.
  • I have a public key whose fingerprint is 4E3E ED83 4041 0AAD 58FC B89C 692A EBE9 0953 9D86

To claim this, I am signing this object:

@tuttlem
tuttlem / fork1.hs
Created January 20, 2014 22:15
fork1.hs
module Main where
import Control.Concurrent
main :: IO ()
main = do
-- grab the parent thread id and print it
parentId <- myThreadId
putStrLn (show parentId)
@tuttlem
tuttlem / texture.cpp
Created January 13, 2014 11:11
Texture class
class texture {
public:
// manage the generated texture id
texture(const GLuint t) : _reference(t) { }
// cleanup of the allocated resource
virtual ~texture(void);
// provide access to the reference
const GLuint reference() const { return _reference; }
@tuttlem
tuttlem / lua1.cpp
Last active January 2, 2016 13:29
Lua varaible reader
#include <iostream>
#include <lua.hpp>
int main(int argc, char *argv[]) {
// create a new lua context to work with
lua_State *L = luaL_newstate();
// open any library we may use
luaL_openlibs(L);
@tuttlem
tuttlem / noise.cpp
Created December 31, 2013 06:34
Noise 5
for (int x = 0; x < w; x ++) {
for (int y = 0; y < h; y ++) {
float xx = (float)x / (float)this->width;
float yy = (float)y / (float)this->height;
map[x + (y * w)] = perlin::perlin2d(
xx, yy,
6, 1.02f
);
}
@tuttlem
tuttlem / noise.cpp
Created December 31, 2013 06:32
Noise 4
float perlin2d(const float x, const float y,
const int octaves, const float persistence) {
float total = 0.0f;
for (int i = 0; i <= (octaves - 1); i ++) {
float frequency = powf(2, i);
float amplitude = powf(persistence, i);
total = total + interpolateNoise(x * frequency, y * frequency) * amplitude;
}
@tuttlem
tuttlem / noise.cpp
Created December 31, 2013 06:26
Noise 3
/* Linear interpolation */
float lerp(float a, float b, float x) {
return a * (1 - x) + b * x;
}
/* Trigonometric interpolation */
float terp(float a, float b, float x) {
float ft = x * 3.1415927f;
float f = (1 - cosf(ft)) * 0.5f;
@tuttlem
tuttlem / noise.cpp
Last active January 1, 2016 19:48
Noise 2
float smoothNoise(const float x, const float y) {
int ix = (int)x;
int iy = (int)y;
// sample the corners
float corners = (noise(ix - 1, iy - 1) +
noise(ix + 1, iy - 1) +
noise(ix - 1, iy + 1) +
noise(ix + 1, iy + 1)) / 16;