Author Archives: Zevan

Texture cos(atan2())

CLICK HERE TO COPY
Actionscript:

var col:int, i:int, j:int, s:int = 500, div:Number =20, outcoord:Point = new Point(), points:Vector.<Point> = new Vector.<Point>();

for (i = 0; i<5; i++) points.push(new Point(int(Math.random()*s),int(Math.random()*s)));

var canvas:Bitmap = Bitmap(addChild(new Bitmap(new BitmapData(s,s, false, 0xFF0000), "auto", true)));

for (i  = 0; i<canvas.width * canvas.height; i++){

    outcoord= new Point( i % canvas.width, i / canvas.width);

    col [...]

Posted in BitmapData, pixel manipulation, setPixel | Tagged , | Leave a comment

25 Lines Contest

CLICK HERE TO COPY
Actionscript:

for (var i:int = 1; i<26; i++) with(addChild(new TextField())) x = 10, y = i * 10, text = "line" + i;

code will create 25 TextFields that say "line1", "line2", "line3" etc...
If you don't already know, Keith Peters has started up the 25 line actionscript contest again... The first round of [...]

Posted in misc | Tagged , | Leave a comment

Yahoo Weather RSS

CLICK HERE TO COPY
Actionscript:

var temp:Number;

var weatherData:XML;

var yweather:Namespace;

 

var zipcode:String="11211";

var units:String = "f";  // "f" or "c" for Fahrenheit or Celsius

 

var yahooURL:String = "http://weather.yahooapis.com/forecastrss?p=" + zipcode + "&u=" + units;

 

var yahooWeather:URLLoader = new URLLoader();

 

yahooWeather.load(new URLRequest(yahooURL));

yahooWeather.addEventListener(Event.COMPLETE, onLoaded);

 

function onLoaded(evt:Event):void {

 

    weatherData=new XML(evt.target.data);

    yweather = weatherData.namespace("yweather");

   

    temp = weatherData.channel.item.yweather::condition.@temp;

     

    trace(temp);

}

This snippet comes [...]

Posted in XML, external data | Tagged , , , , , , | Leave a comment

2D Vector

CLICK HERE TO COPY
Actionscript:

var map:Vector.<Vector.<int>> = new Vector.<Vector.<int>>();

map[0] = new Vector.<int>();

map[0].push(1);

map[0].push(0);

map[0].push(0);

 

map[1] = new Vector.<int>();

map[1].push(0);

map[1].push(1);

map[1].push(0);

 

map[2] = new Vector.<int>();

map[2].push(0);

map[2].push(0);

map[2].push(1);

 

/*

map:

1,0,0

0,1,0

0,0,1

*/

This creates a two dimensional Vector of ints (flash 10 player only). The first line is the real snippet... took me a few minutes to get the syntax right the first time I needed a 2D Vector.

Posted in Vector, arrays | Tagged , | Leave a comment