Articles Tagged "Code"

Hexadecimal Color Fading Array

A while ago I wrote a Hexadecimal Color Fading Tutorial explaining how to select a single color at any point on a gradient between two specified colors. In that tutorial there was a function which efficiently broke each of the 2 specified colors into their Red, Green and Blue components and then calculated a single new color at a specified point between them.

Here's what the code looks like: ...
Read More

How to Draw a Logarithmic Spiral

What is a Logarithmic spiral? A logarithmic spiral steps around center at an additive rate while stepping away from center at a multiplicative rate. Increasing the distance from center at a multiplicative rate causes the arm of a logarithmic spiral to increase in size as it gets further from center. To illustrate, take a look at this photo of a spiral staircase:

bottom-up view
Photo by: darijus

As you can see in the above photo, the number of steps ...
Read More

How to Draw a Spiral

This tutorial covers the basic concepts needed to draw a simple spiral with ActionScript. A "simple spiral" or an "Archimedean spiral" is created by moving 'away from' and 'around' a central point at a constant additive rate. If that sounds a bit foreign to you, don't worry it's nothing new. If you've coiled a hose or rope on a flat surface, you have experience working with Archimedean spirals.

Archimedean Spiral
(Photo by Paul Needham)

The most notable characteristic of the simple spiral above is that each coil (a full rotation around center) will always increase the spiral's radius by the same amount (the width of the rope).

Now that you understand what a simple spiral is, I'd like to jump ahead a bit and show you the final state of our code: ...
Read More

Code Highlighting and Formatting in WordPress

I tried a couple different code highlighting plugins for WordPress and decided to use the aptly named "CodeHighlighter" by Wongoo Lee which is essentially an implementation of the well established and tested GeSHi - Generic Syntax Highlighter. Installation follows the usual pattern: unzip, upload to your plugins directory, and activate the plugin from your Plugin Management screen in WordPress.

Once installed, adding highlighted code to your blog is as easy as ...
Read More

FireBug is Way Handy

I'm not a big-time web developer so I'm often a bit behind the curve when it comes to cool new tools. If you're like me and you happened to miss the seemingly omnipresent buzz, Firebug is one of the few web development tools worthy of the praise heaped upon it. It has so many features it's easy to be overwhelmed by them all. I don't claim to know everything about this Firefox plugin, but one thing I know how to do is use Firebug to edit CSS right inside the browser. Not only that, ...
Read More

ActionScript Code Highlighting in WordPress

I wonder what ActionScript looks like:

//
//
import flash.display.*;
import flash.geom.Matrix;
//
//
lineStyle(1);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
//
//
function createClipGrid(name, depth, rows, cols, bmp){
	var clp = this.createEmptyMovieClip(name, depth);
	var wi = bmp.width;
	var hi = bmp.height;
	var cellWi = wi/cols;
	var cellHi = hi/rows;
	var lastX = 0;
	var lastY = 0;
	var cWi = 0;
	var goalX = 0;
	var cHi = 0;
	var goalY = 0;
	var count = 0;
	clp.allCells = [];
	for(var i=0; i<cols ; i++){
		goalX = Math.round((i+1)*cellWi);
		cWi = goalX - lastX;
		for(var j=0; j<rows; j++){
			count++;
			goalY = Math.round((j+1)*cellHi);
			cHi = goalY - lastY;
			var trans = new Matrix();
			trans.translate(-lastX, -lastY);
			var cell = clp.createEmptyMovieClip("Cell"+i+"_"+j, count);
			clp.allCells.push(cell);
			cell.bmp = new BitmapData(cWi, cHi, bmp.transparent);
			cell.attachBitmap(cell.bmp, 10, "never");
			cell.bmp.draw(bmp, trans);
			cell._x = lastX;
			cell._y = lastY;
			lastY = goalY%hi;
		}
		lastX = goalX%wi;
	}
	return clp;
}
//
//
function drawLine (){
	lineTo(_xmouse, _ymouse);
}
onMouseDown = function(){
	lineStyle(4, Math.random()*0xFFFFFF);
	moveTo(_xmouse, _ymouse);
	onMouseMove = drawLine;
}
onMouseUp = function(){
	onMouseMove = null;
}
//
//
onKeyDown = function(){
	var myBmp = new BitmapData(200, 200, false, 0xFFFFFF);
	myBmp.draw(_root);
	createClipGrid("CG", 20, 5, 8, myBmp);
	//CG._x = CG._y = 200;
	for(var k in CG.allCells){
		var c = CG.allCells[k];
		c.xd = Math.random()*6-3;
		c.yd = Math.random()*6-3;
		c.onEnterFrame = tumble;
	}
}
Key.addListener(this);
function tumble(){
	with(this){
		_x += xd;
		_y += yd;
		_yscale -= Math.random()*5;
		_xscale -= Math.random()*5;
		if(_xscale<0 || _yscale<0)removeMovieClip();
	}
}
//
//

That's not too shabby.

© Sean O'Shell 2007-2008