Skip to content

Instantly share code, notes, and snippets.

View mimshwright's full-sized avatar

Mims H. Wright mimshwright

View GitHub Profile
@mimshwright
mimshwright / BitmapDrawComparison.as
Created January 11, 2010 07:45
On stage using bitmap caching
package {
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
[SWF(width="500", height="500", frameRate="50")]
public class BitmapDrawComparison extends Sprite {
public var timeDisplay:TextField;
@mimshwright
mimshwright / BitmapDrawComparison.as
Created January 11, 2010 07:52
Drawing directly to a bitmap
package {
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
[SWF(width="500", height="500", frameRate="50")]
public class BitmapDrawComparison extends Sprite {
public var timeDisplay:TextField;
@mimshwright
mimshwright / BitmapDrawComparison.as
Created January 11, 2010 07:54
On stage without caching
package {
import flash.display.*;
import flash.geom.*;
import flash.events.*;
import flash.text.*;
import flash.utils.*;
[SWF(width="500", height="500", frameRate="50")]
public class BitmapDrawComparison extends Sprite {
public var timeDisplay:TextField;
@mimshwright
mimshwright / autoSingletonMaker.as
Created January 30, 2010 22:52
using a whacky hack to create single instances of several classes at once.
/**
* creates a single instance of each state and stores them in a dictionary of states.
*/
// OH, HACKY! .... OR BRILLIANT?
protected function initializeStates():void {
allStates = new Dictionary( false );
//This vector contains several state classes i want to instantiate.
var stateClasses:Vector.<Class> = new Vector.<Class> ([MainMenuState, CreditsState, GameplayState]);
for each ( var stateClass:Class in stateClasses) {
@mimshwright
mimshwright / IDisplayObject.as
Created March 15, 2010 01:43
Solves the lack of interface for DisplayObject
package
{
import flash.display.DisplayObject;
/**
* An interface to work around the lack of interface for display objects.
*/
public interface IDisplayObject
{
/**
@mimshwright
mimshwright / limit.as
Created March 6, 2011 02:03
A shortcut function for limiting a value between a lower and upper boundary. I use this all the time.
package org.as3lib.math
{
/**
* Global function for returning a number within an upper and lower limit.
*
* @param value The number to limit
* @param lowLimit The lowest value that will be returned.
* @param highLimit The highest value that will be returned.
* @return value if lowLimit < value < highLimit, otherwise returns the lowLimit or highLimit.
*/
@mimshwright
mimshwright / isRoughlyEqual.as
Created March 6, 2011 19:17
Returns true if the two numbers are within "maxPercentDifferent" percent of each other.
package utils.number {
/**
* Returns true if the two numbers are within "maxPercentDifferent" percent of each other.
*
* @example <listing version='3.0'>
* FuzzyMath.roughlyEqual(0.7, 0.69); // true
* FuzzyMath.roughlyEqual(0.7, 0.5); // false
*
* FuzzyMath.roughlyEqual(123456789, 123450000); // true
@mimshwright
mimshwright / randomChoice.as
Created March 20, 2011 19:40
A quick way to select a random string or object.
// randomly returns one of the three strings
var word:String = ["Alpha", "Bravo", "Charlie"] [int(Math.random() * 3)];
@mimshwright
mimshwright / GridGenerator.html
Created December 9, 2011 00:21
Some code to create a grid using the <canvas> tag. Also animates the grid.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Grid!</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
@mimshwright
mimshwright / montecarlo.java
Created February 23, 2012 04:26
Solution to Monte Carlo problem for Coding Dojo Feb 2012 by Mims H. Wright
import java.io.*;
/**
* @author Mims H. Wright - mims@mimswright.com
*/
class montecarlo {
// To run, on command line type:
// javac montecarlo.java
// java montecarlo