Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@NickBeeuwsaert
NickBeeuwsaert / Verlet.js
Created February 12, 2013 04:10
Vector. Verlet, and Linear Constraints in javascript (so I don't have to write a new one every week... :P)
function Vector(x,y){
this.x = x;
this.y = y;
};
Vector.prototype.iadd = function(x, y){
if(typeof(x)=="number"){
this.x += x;
this.y += y;
}else{
this.x += x.x;
@NickBeeuwsaert
NickBeeuwsaert / image.c
Last active December 18, 2015 08:19
example of a bilinear interpolating thingy.
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "image.h"
uint32_t getpixel(image_t *image, unsigned int x, unsigned int y){
return image->pixels[(y*image->w)+x];
}
float lerp(float s, float e, float t){return s+(e-s)*t;}
@NickBeeuwsaert
NickBeeuwsaert / cypher.py
Created August 1, 2013 01:02
Fun with one time pads!
#!/usr/bin/env python
import Image
import os, sys
if __name__ == "__main__":
if len(sys.argv) != 4:
print("Usage: %s secret pad output"%(sys.argv[0],))
sys.exit(0);
secret = Image.open(sys.argv[1])
secret.convert("RGB");
secretPixels = secret.load();
#!/bin/env python
import sys
import time
import string
import random
import hashlib
import os
out = "ERROR: No argument was given or the given argument was invalid."
@NickBeeuwsaert
NickBeeuwsaert / GGR2Canvas.py
Created August 16, 2013 19:59
Quic n' dirty tool to convert a gimp gradient to a HTML5 Canvas Gradient (or with a little bit of modification, any other type gradient)
#!/usr/bin/env python
import sys
def lerp(s,e,t):
return s + (e-s)*t
def printStop(gradient_name, t, rgba):
newRGBA = [int(c*255) for c in rgba]
format_args = tuple([gradient_name, t] + newRGBA)
return "%s.addColorStop(%f, \"rgba(%d, %d, %d, %d)\");\n"%format_args;
def parseGimpGradient(filename):
file = open(filename, "r");
@NickBeeuwsaert
NickBeeuwsaert / Gradient.cpp
Last active February 24, 2024 16:14
Small C++ Gradient class
#include "Gradient.h"
#include <vector>
Gradient::GradientColor::GradientColor(float _r, float _g, float _b, float _a):r(_r), g(_g), b(_b), a(_a) {}
Gradient::GradientColor::GradientColor():r(), g(0), b(0), a(0) {}
const Gradient::GradientColor & Gradient::GradientColor::operator+=(const GradientColor &lhs){
r += lhs.r;
g += lhs.g;
b += lhs.b;
a += lhs.a;
@NickBeeuwsaert
NickBeeuwsaert / SVG_Load.c
Created September 3, 2013 20:36
Loads a SVG file into a SDL_Texture
/* Reads a SVG file into a SDL_Texture
inputs:
SDL_Renderer *r: the SDL_Renderer to use,
const char *filename: the file to load
returns:
SDL_Texture*: the loaded texture, or NULL if something went wrong
*/
SDL_Texture *SDL_TextureFromSVG(SDL_Renderer *r, const char *filename){
SDL_Texture *texture = NULL;
SDL_Surface *tmpSurface = NULL;
all: main.c
gcc -o main main.c -I/opt/X11/include/cairo -I/opt/X11/include/pixman-1 -I/opt/X11/include -I/opt/X11/include/freetype2 -I/opt/X11/include -I/opt/X11/include/libpng15 -I/opt/X11/include -I/usr/include/libxml2 -I/usr/local/Cellar/libsvg-cairo/0.1.6/include -I/usr/local/Cellar/libsvg/0.1.4/include -L/opt/X11/lib -L/usr/local/Cellar/libsvg-cairo/0.1.6/lib -L/usr/local/Cellar/libsvg/0.1.4/lib -lsvg-cairo -lsvg -lpng -ljpeg -lz -lxml2 -lcairo
@NickBeeuwsaert
NickBeeuwsaert / why.py
Created November 2, 2013 03:59
Some stupid programmer humor
#!/usr/bin/env python
if __name__ == "__main__":
print("Why do programmers confuse Halloween and Christmas?");
print("Because oct %o == dec %d!"%(25, 031));
@NickBeeuwsaert
NickBeeuwsaert / fox.cow
Last active December 28, 2015 07:09
a fox cowsay cow WHAT DOES THE FOX SAY? Sorry I am not a ascii artist :(
$the_cow = <<"EOC";
$thoughts
$thoughts
$thoughts
$thoughts _
|\\ _/ \\
| \\------/ , )
| \\ | | |
\\ / /
___,--------____ / \\