Skip to content

Instantly share code, notes, and snippets.

View NickBeeuwsaert's full-sized avatar

Nick Beeuwsaert NickBeeuwsaert

View GitHub Profile
@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 / 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");
#!/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 / 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();
@NickBeeuwsaert
NickBeeuwsaert / image.c
Last active September 2, 2024 06:53
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 / 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;