Skip to content

Instantly share code, notes, and snippets.

View leeprobert's full-sized avatar

Lee Probert leeprobert

View GitHub Profile
@leeprobert
leeprobert / NSTimer+Blocks.h
Created October 9, 2011 13:54
Category on NSTimer that adds Blocks support.
#import <Foundation/NSTimer.h>
@interface NSTimer (PSYBlockTimer)
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats usingBlock:(void (^)(NSTimer *timer))fireBlock;
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds repeats:(BOOL)repeats usingBlock:(void (^)(NSTimer *timer))fireBlock;
@end
@leeprobert
leeprobert / getNewBitmap.as
Created December 6, 2011 10:03
fit a bitmap image to its container regardless of aspect ratio
protected function getNewBitmap(data:BitmapData):Bitmap
{
var horizontalRatio:Number = this.width / data.width;
var verticalRatio:Number = this.height / data.height;
var ratio:Number = Math.max(horizontalRatio,verticalRatio);
var matrix:Matrix = new Matrix();
matrix.scale(ratio,ratio);
@leeprobert
leeprobert / Main.as
Created February 12, 2012 06:31
Flash application class for loading Flex SWF files and calling methods off them
package {
import flash.display.DisplayObject;
import flash.display.Loader;
import flash.display.MovieClip;
import flash.display.SWFVersion;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
@leeprobert
leeprobert / flash-unicode-table.xml
Created February 21, 2012 18:01
Flash Unicode range mapping XML
<?xml version="1.0" encoding="iso-8859-1" ?>
<!--
This file provides a convenient mapping of the Flash MX 2004 UnicodeTable.xml character ranges
for use in Macromedia Flex's configuration file. You can copy ranges from this reference list and add
them to Flex's configuration file.
Developers embed fonts into applications as not every client has the same fonts installed. To reduce
the size of the application developers often include a subset of the characters available in a font -
this subset is known as a character range.
@leeprobert
leeprobert / CaptureViewController.m
Created February 24, 2012 23:04
Cocoa class for capturing the web cam and building an image up by rows of pixels
//
// CaptureViewController.m
// TimeSmear
//
// Created by Lee Probert on 23/02/2012.
// Copyright (c) 2012 LyraSpace Ltd. All rights reserved.
//
#import "CaptureViewController.h"
@leeprobert
leeprobert / GridConstraintBasicLayout
Created March 5, 2012 09:52
A layout class for automatically positioning and resizing child elements of a container to a grid.
package com.cc.eurostarlive.layouts
{
import mx.core.ILayoutElement;
import mx.core.IVisualElement;
import spark.layouts.supportClasses.LayoutBase;
public class GridConstraintBasicLayout extends LayoutBase
{
/*
@leeprobert
leeprobert / Away3DFlexApplication.mxml
Created March 22, 2012 17:48
Away3D 4 Flex application example
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:loaders="away3d.loaders.*"
xmlns:a3d="*"
backgroundAlpha="0"
@leeprobert
leeprobert / PVPixelPrecision.as
Created March 23, 2012 10:17
The code required to make an object look pixel perfect in a 3D Papervision environment
Object.z = Math.round((camera.zoom * camera.focus) -Math.abs(camera.z))
+ Object.depth/2; // take or add 0.5 if it's still blurred
<?xml version="1.0" encoding="utf-8"?>
<s:Application
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
minWidth="955"
minHeight="600"
@leeprobert
leeprobert / Angle.as
Created April 23, 2012 14:40
A class for drawing a block of text and then drawing an extrusion path from the bounds of the rectangle
package com.cc.math
{
/**
* Full details: http://gamedev.michaeljameswilliams.com/2009/04/24/angles-in-flash/
* Hungarian notation idea: http://www.joelonsoftware.com/articles/Wrong.html
* Optimisation credit: http://www.nbilyk.com/optimizing-actionscript-3
*
* Usage: import com.michaeljameswilliams.gamedev.angles.Angle
* var degAngle:Number = Angle.degFromRad( radAngle );