Skip to content

Instantly share code, notes, and snippets.

func drawText(s: String, w: CGFloat, h: CGFloat, colour:CGColor) -> CGImageRef {
let bounds = CGRectMake(0, 0, w, h)
// Create the bitmap-backed CoreGraphics contexts
let context = CGBitmapContextCreate(nil, Int(w), Int(h), 8, 0,
CGColorSpaceCreateDeviceRGB(),
CGImageAlphaInfo.PremultipliedFirst.rawValue | CGBitmapInfo.ByteOrder32Little.rawValue)
CGContextSetFillColorWithColor(context, colour)
CGContextFillRect(context, bounds)
@voyce
voyce / EnumItemsSource.cs
Created September 16, 2013 09:14
WPF EnumItemsSource
/// <summary>
/// Allows us to use enum values as a data source; e.g. for providing as an ItemsSource
/// on a combo box control for user selection.
/// </summary>
public class EnumItemsSource : Collection<String>, IValueConverter
{
Type _type;
IDictionary<Object, Object> _valueToNameMap;
IDictionary<Object, Object> _nameToValueMap;
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>D3 and Knockout</title>
<script src="knockout-2.2.1.js"></script>
<script src="lib/d3.v2.js"></script>
<link rel="stylesheet" href="src/nv.d3.css" type="text/css"/>
<script>
var nrects = 1;
function Rect() {
@voyce
voyce / BlobShader.fsh
Last active January 19, 2017 08:32
Blob fragment shader
#define MAX_BALLS 10
precision mediump float;
varying lowp vec2 v_texCoord;
uniform float u_width;
uniform int numballs;
uniform vec3 balls[MAX_BALLS]; //.xy is position .z is radius
float energyField(in vec2 p, in float iso)
@voyce
voyce / maze.fs
Created January 22, 2012 23:03
Generic recursive path finder in F#
open System
/// Given a starting location, and functions for determining possible
/// moves and whether we're reached the goal.
/// Returns a tuple of boolean and a list of locations in the path
/// to the goal.
let tryFindPath (start : 'T) (neighbours : 'T -> 'T []) (isGoal : 'T -> bool) =
let rec tryPath l visited =
if isGoal l
then