Sum of the Squares of the two legs of a right triangle is equal to the square of the hypotenuse.
A^2 + B^2 = C^2
var dist:Number;
var circle:Circle;
function onStageEnter(event) {
var dx:Number = event.target.x - mouseX;
var dy:Number = event.target.y - mouseY;
dist = Math.sqrt(dx*dx + dy*dy);
event.target.alpha = 1-(dist/250);
distText.text = String(dist);
distText.x = mouseX;
distText.y = mouseY+20;
}
for (var i:int = 1; i<=7; i++) {
for (var j:int = 1; j<=5; j++) {
circle = new Circle();
circle.x = (i*circle.width)-circle.width;
circle.y = (j*circle.height)-circle.height;
circle.addEventListener(Event.ENTER_FRAME, onStageEnter);
addChild(circle);
}
}
Showing posts with label action script. Show all posts
Showing posts with label action script. Show all posts
Thursday, June 3, 2010
Tuesday, March 9, 2010
Learn Actionscirpt Techniques - ColorPicker Gradient
By default, the component displays a single swatch of color on a square button. When the user clicks this button, a panel opens to display the complete list of swatches.
// Here is the Source Code
var startHex;
var endHex;
var spacing:int = 25;
var noOfBoxes:int = 13;
var endHex;
var spacing:int = 25;
var noOfBoxes:int = 13;
function fadeHex(ratio) {
var r = startHex >> 16;
var g = startHex >> 8 & 0xFF;
var b = startHex & 0xFF;
r += ((endHex >> 16 & 0xFF)-r)*ratio;
g += ((endHex >> 8 & 0xFF)-g)*ratio;
b += ((endHex & 0xFF)-b)*ratio;
return (r << 16 | g << 8 | b);
}
function drawSquare(x, y, color) {
graphics.beginFill(color);
graphics.moveTo(x,y);
graphics.lineTo(x+50,y);
graphics.lineTo(x+50,y+50);
graphics.lineTo(x,y+50);
graphics.lineTo(x,y);
}
function colorChange(e:Event) {
var cp:ColorPicker = e.target as ColorPicker;
if (cp==cp1) {
startHex = "0x"+e.target.hexValue ;
} else {
endHex = "0x"+e.target.hexValue;
}
for (var i = 0; i
var ratio = i/noOfBoxes;
var xx = spacing+(i*50);
var yy = 70;
var nowColor = fadeHex(ratio);
drawSquare(xx,yy,nowColor);
}
}
cp1.selectedColor = 0x990000;
cp2.selectedColor = 0x000000;
cp1.addEventListener(Event.CHANGE, colorChange);
cp2.addEventListener(Event.CHANGE, colorChange);
cp1.addEventListener(Event.RENDER, colorChange);
cp2.addEventListener(Event.RENDER, colorChange);
var r = startHex >> 16;
var g = startHex >> 8 & 0xFF;
var b = startHex & 0xFF;
r += ((endHex >> 16 & 0xFF)-r)*ratio;
g += ((endHex >> 8 & 0xFF)-g)*ratio;
b += ((endHex & 0xFF)-b)*ratio;
return (r << 16 | g << 8 | b);
}
function drawSquare(x, y, color) {
graphics.beginFill(color);
graphics.moveTo(x,y);
graphics.lineTo(x+50,y);
graphics.lineTo(x+50,y+50);
graphics.lineTo(x,y+50);
graphics.lineTo(x,y);
}
function colorChange(e:Event) {
var cp:ColorPicker = e.target as ColorPicker;
if (cp==cp1) {
startHex = "0x"+e.target.hexValue ;
} else {
endHex = "0x"+e.target.hexValue;
}
for (var i = 0; i
var ratio = i/noOfBoxes;
var xx = spacing+(i*50);
var yy = 70;
var nowColor = fadeHex(ratio);
drawSquare(xx,yy,nowColor);
}
}
cp1.selectedColor = 0x990000;
cp2.selectedColor = 0x000000;
cp1.addEventListener(Event.CHANGE, colorChange);
cp2.addEventListener(Event.CHANGE, colorChange);
cp1.addEventListener(Event.RENDER, colorChange);
cp2.addEventListener(Event.RENDER, colorChange);