Skip to content

Instantly share code, notes, and snippets.

View BrianMacIntosh's full-sized avatar

Brian MacIntosh BrianMacIntosh

View GitHub Profile
@BrianMacIntosh
BrianMacIntosh / RasterLineIterator.cs
Created November 3, 2013 21:37
This class provides a mechanism to iterate through the pixels in a rasterized line. The pixels are returned in order by distance from the point 'start'. The iterator acts like a raycast, not like e.g. Bresenham's line algorithm, in that it returns every pixel intersected by the ray.
using System;
// RasterLineIterator.cs
// 3 November 2013
// Author: Brian MacIntosh
/// <summary>
/// A simple two-dimensional vector. Replace with any 2d vector class.
/// </summary>
class Vector2
@BrianMacIntosh
BrianMacIntosh / gcd.c
Last active December 29, 2015 07:19
Calculate the GCD (greatest common denominator) of two integers using the Euclidean algorithm. Recursive or iterative functions.
//Helper fn
int pgcdr(int a, int b)
{
if (a) return pgcdr(b % a, a);
else return b;
}
//Recursive gcd fn
int gcdr(int a, int b)
{
@BrianMacIntosh
BrianMacIntosh / DegreesRadians.cs
Last active August 9, 2017 16:49
Shows how type-safe, automatically-converted degree and radian types could be created in C#.
using System;
class Program
{
static void Main(string[] args)
{
AngleDegrees angleA = new AngleDegrees(90);
AngleRadians angleB = new AngleRadians(Math.PI / 2);
// angleA will be implicitly converted to AngleRadians because that's what the method parameter is
@BrianMacIntosh
BrianMacIntosh / Sprites.cs
Created May 28, 2018 04:47
These classes provide easy methods for displaying animated sprites in XNA.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
/*
* XNA Lightweight Sprite Animation
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
@BrianMacIntosh
BrianMacIntosh / Microphone.cs
Last active May 28, 2018 04:47
This class provides easy access to the Windows Phone microphone hardware with XNA.
using System;
using System.IO;
using Microsoft.Xna.Framework.Audio;
/*
* XNA Windows Phone Easy Microphone Access
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
*
* Version: 1.1
*
@BrianMacIntosh
BrianMacIntosh / Accelerometer.cs
Last active May 28, 2018 04:50
This class greatly simplifies access to the accelerometer on the Windows Phone with XNA. Features include easy zeroing and "shake" gesture detection.
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Devices.Sensors;
/*
* XNA Windows Phone Easy Accelerometer Access
* by Brian MacIntosh for ThunderFish Entertainment/BoneFish Studios
*
* Version: 1.0
@BrianMacIntosh
BrianMacIntosh / DynamicAckermannFunction.cs
Last active February 14, 2019 19:34
Demo implementation of the Ackermann Function in C# using dynamic programming.
using System;
using System.Threading;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
private static int answer;
private static int iterations = 0;
@BrianMacIntosh
BrianMacIntosh / ContactListenerSample.js
Last active June 4, 2019 07:55
Sample code showing how to create a contact listener in box2d.js
//sample code showing how to create a contact listener with
//kripken's Javascript port of Box2D.js
//https://github.com/kripken/box2d.js/
var gravity = new Box2D.b2Vec2(0.0, 10.0);
var world = new Box2D.b2World(gravity);
var contactListener = new Box2D.JSContactListener();
contactListener.BeginContact = function(contact)
@BrianMacIntosh
BrianMacIntosh / ItemQuantityPropertyDrawer.cs
Created December 9, 2019 01:33
Base class for a Unity property drawer for structures like "quantity" of "thing"
using UnityEditor;
using UnityEngine;
// Author: Brian MacIntosh (The Periodic Group)
// MIT License
/// <summary>
/// Base class that can be extended to quickly create a property drawer for a structure containing
/// data like "quantity" of "thing".
/// </summary>
using System.Collections.Generic;
using System.Globalization;
using UnityEditor;
using UnityEngine;
/*
Copyright (c) 2019-2020 Brian MacIntosh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal