Tomorrow Evening

Digitially Driven

Find and Replace

A "Find and Replace" method is always handy when trying to avoid repetition in code (especially when replacing variables in XML Strings) and so here's a quick script everyone should know:

 
public static function replaceWord (searchString:String, find:String, replace:String) : String
{
	var wordLength = searchString.length;
	var result:String = '';
	for (var i = 0; i < wordLength; i++) {
		if (searchString.substr (i, find.length) == find) {
			result =	searchString.substr (0, i) +
						replace +
						searchString.substr (i + find.length, wordLength);
		}
	}
	if (result == '') result = searchString; // didn't replace anything
	return result;
}
 

Useful Trig Methods

I've recently been working on a physics/trigonometry project at home using Processing and memo's amazing MSARemote. In short, I realized I haven't posted anything on Tomorrow Evening in ages, I have a lot of cool things up my sleeve right now, just trying to find time to get all these ideas out. I'll be taking all of Thanksgiving week off to take a break from work and do some fun experiments. If I weren't a web developer I'd turn my internet off for a few weeks, I keep finding such great developers/art online that I start something new every other day and never finish what I was working on the day before! That needs to end soon :P. I know I said I was doing a Processing experiment and this code is in AS3 but I have a good reason why! My wordpress doesn't know how to format processing code and since it's only a few lines, I converted it to AS3.

function findDistance(x1:Number, y1:Number, x2:Number, y2:Number) : Number{
  var xd:Number = x1 - x2;
  var yd:Number = y1 - y2;
  var td:Number = Math.sqrt(xd * xd + yd * yd);
  return td;
}
 
function findAngle(x1:Number, y1:Number, x2:Number, y2:Number) : Number{
  var xd:Number = x1 - x2;
  var yd:Number = y1 - y2;
 
  var t:Number = Math.atan2(yd,xd);
  var a:Number = 180 + (-(180 * t) / Math.PI);
  return a;
}

Comment Generator

commentGenerator
Read the rest of this entry »

Quick Duplicate

quickDuplicate
Read the rest of this entry »

Layer Settings

layerSettings
Ever need to guide out a bunch of layers real quick? Change the outline color for multiple layers? This JSFL command let's you alter multiple layer settings all at once. Read the rest of this entry »

Authors

Posts

March 2010
S M T W T F S
« Jan    
 123456
78910111213
14151617181920
21222324252627
28293031