Drawing app

Right now I’m still reading “Learning ActionScript 3.0” book so I can improve my AS 3 skills. In the “Draving with pixels” chapter there is a great example of a little drawing application that I like. Here you can see the code for that little application:

var mouseIsDown:Boolean;
var erasing:Boolean;
 
var canvas:Sprite = new Sprite();
addChild(canvas);
 
var w:Number = stage.stageWidth;
var h:Number = stage.stageHeight;
var bmd:BitmapData = new BitmapData(w, h, false, 0xffffffff);
var bm:Bitmap = new Bitmap(bmd);
canvas.addChild(bm);
 
var brush:Sprite = createBrush(0x66cc00);
var eraser:Sprite = createBrush(0xffffff);
 
function createBrush(col:uint):Sprite{
	var sp:Sprite = new Sprite();
	sp.graphics.beginFill(col, 1);
	sp.graphics.drawCircle(0, 0, 30);
	sp.graphics.endFill();
	return sp;
}
 
canvas.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
canvas.addEventListener(MouseEvent.MOUSE_UP, onUp);
this.addEventListener(Event.ENTER_FRAME, onLoop);
 
function onDown(e:MouseEvent):void{
	mouseIsDown = true;
	if(e.shiftKey)
		erasing = true;
}
 
function onUp(e:MouseEvent):void{
	mouseIsDown = false;
	erasing = false;
}
 
function onLoop(e:Event):void{
	if(mouseIsDown && erasing){
		eraser.x = mouseX;
		eraser.y = mouseY;
		bmd.draw(eraser, eraser.transform.matrix);
	}else if(mouseIsDown){
		brush.x = mouseX;
		brush.y = mouseY;
		bmd.draw(brush, brush.transform.matrix);
	}
}

And if you click here you can see the result (click to draw and hold the shift key + click to erase)
This book has a lot of good examples and it’s very easy to understand. I recommend it to anyone how wants to start with ActionScript 3.0 😉

The best TED ever – Lennart Green: Close-up card magic

This is a very funny episode and one of the best TED episodes I’ve seen 😀

Canon EF-S 17-55 f/2.8

At work playing with Canon EF-S 17-55 f/2.8 lens 😀

The bags

I found this somewhere on tumblr, it was a gif animation. This is a very interesting idea. I really love it. But it seems to work better with this mouse over effect 😀

Random number except number 7

Today I had this little problem. I needed to generate a random number from 1 to 30 and the result had to except a specific number (as in this example, any number from 1 to 30 except the number 7 )
The code is done now, it’s working as it should and I posted it in case someone else needs this same code.

var randomNumber:Number;
var minNumber:Number = 1;
var maxNumber:Number = 30;
 
function generateRandomNumber():void{
	randomNumber = Math.round(Math.random() * (maxNumber - minNumber)) + minNumber;
	if(randomNumber == 7){
		generateRandomNumber();
	}
	trace(randomNumber)
}
generateRandomNumber();

By the way, the code here is ActionScript 3 but if you remove “:void” you can use it in ActionScript 2 too 😉

New flickr slideshow

The new flickr flash slideshow dose have an embedding feature… it’s great because you can easily place your flickr images on your blog/website and you can view them in full screen as well 😀
Here are some of my images: