3D flower twist in flash

HOW TO DESIGN A WATERCOLOR PORTRAIT

Step 1 – Create the Texture
Open the image in Photoshop. From here we need to create a high contrast side of the image. To do that we first need to desaturate the image (Ctrl+Shift+U) or (Image | Adjust | Desaturate). Then we need to punch up the contrast using levels (Image | Adjust | Levels).

img
image-2354

 

==================================

To create the texture, use a custom brush of solid text. You can use any font that you like, but I choose the Mutlu fonts for its eye-catching loops and curls.

img2
image-2355

 

Create new blank document 700×700 pixels and fill the document with a block of black text.

====================================

Now click (Edit | Define Brush Preset) to create the custom brush. Go to your portrait image again. create a layer mask for the girl’s layer.

img3
image-2356

 

===================================

Fill the layer mask with solid black, which will make the girl image to disappear. Using you’re newly created custom brush, select solid white for your foreground color and begin to click on the mask to reveal portions of the girl’s face. Experiment with the different opacity settings for your brush.

img4
image-2357

 

==========================================

Step 2 – Add the Watercolor

Now on a new layer above the portrait, begin adding watercolor with single click, then using a black brush. There’s no any particular method here. Just does what you feel look right. Don’t go extreme; less is more with these splatters. You don’t want them to underrate from the subjects face.

img5
image-2358

 

============================================

Step 3 – Add a Little Color

To add color, we need to create a Gradient Fill Adjustment Layer, and set its blending mode to Overlay. You can use any sort of color you prefer.

img6
image-2359

 

=========================================

As I specified before, this effect seems to work with just about any photo.

Tags: , ,

3D Particles rotation in flash

1. Open a new document and set background color as black.

2. Select Layer-1, Keyframe 1. Press F9 to write the following action script. I have explained the code in the comments.
import fl.motion.easing.Quartic;
import fl.motion.easing.Bounce;
import fl.motion.Animator3D;
import main.submain.loaders.*;
import main.submain.bitmapUtilities.PictureAtomizer;
import main.submain.objects.Particle3D;
import main.submain.geom3D.*;
import main.submain.display.*;
var picURLString:Array; // var is a variables, picURLString is a type and array is an atrribute
var picLoader:PictureLoader;
var pic:Array;
var atomizer:PictureAtomizer;
var particles:Array;
var blur:BlurFilter;
var darken:ColorTransform;
var board:RotatingParticleBoard;
var boardRect:Rectangle;
var filterPoint:Point;
var p:Particle3D;
var param:Number;

//////////////////////////////////////////////////
init(); // function name
//////////////////////////////////////////////////
function init():void {
picURLString= [“image/violet.jpg”]; //path of image
picLoader = new PictureLoader();
board = new RotatingParticleBoard(500,340,true, 0x00000000, 500); //set the width and height of rectangle box
board.setDepthDarken(-10,-80,1.5); // brightens and darken the image
board.makeFrame(1,0xffffff,5); // stroke and color of rectangle box
board.holder.x = stage.stageWidth/2 – board.width/2; // position of rectangle box in x-axis
board.holder.y = stage.stageHeight/2 – board.height/2; //position of rectangle box in y-axis
//set the starting rotation:
board.currentQ = new Quaternion(Math.cos(Math.PI/12), Math.sin(Math.PI/2)/Math.sqrt(2),0,-Math.sin(Math.PI/5)/Math.sqrt(2));
//set the automatic rotation to use while mouse is not dragging:
board.autoQuaternion = new Quaternion(Math.cos(Math.PI/300),0,Math.sin(Math.PI/300),0);
blur = new BlurFilter(50,50);
darken = new ColorTransform(500,1,1,0.9); // RGB colors and 0.9 gives the smoke effect
boardRect = new Rectangle(0,0,board.width,board.height);
filterPoint = new Point(0,0);
//add following code to see arcball silhouette:
/*
var ballOutline:Shape = new Shape();
ballOutline.graphics.lineStyle(1,0×888888);
ballOutline.graphics.drawCircle(0,0,board.arcballRad);
ballOutline.x = board.width/2;
ballOutline.y = board.height/2;
board.holder.addChild(ballOutline);
*/
picLoader.addEventListener(PictureLoader.ALL_PICS_LOADED, createParticles);
picLoader.loadPics(picURLString);
}
function createTextLabels():void {
var box:TextField = new TextField();
var format:TextFormat = new TextFormat(“Times New Roman”,16,0xffffff);
box.defaultTextFormat = format;
box.text = String(particles.length)+ ” particles.”;
box.x = board.holder.x+1;
box.y = board.holder.y+board.height+5;
stage.addChild(box);
var box2:TextField = new TextField();
box2.defaultTextFormat = format;
box2.multiline = false;
box2.autoSize = TextFieldAutoSize.RIGHT;
box2.x = board.holder.x+board.width-5-box2.width;
box2.y = board.holder.y+board.height+5;
stage.addChild(box2);
var box3:TextField = new TextField();
box3.defaultTextFormat = format;
box3.multiline = false;
box3.autoSize = TextFieldAutoSize.CENTER;
box3.text = “Drag the mouse to rotate”;
box3.x = board.holder.x+board.width/2-box3.width/2;
box3.y = board.holder.y-25;
stage.addChild(box3);
}
function createParticles(evt:Event):void {
pic = picLoader.picArray;
picLoader.removeEventListener(PictureLoader.ALL_PICS_LOADED, createParticles);
atomizer = new PictureAtomizer();
atomizer.sampling = 1;
atomizer.spread = 1.50;
atomizer.sampleFuzzX = 0;
atomizer.sampleFuzzY = 0;
atomizer.originX = Math.floor(pic[0].width/2);
atomizer.originY = Math.floor(pic[0].height/2);
atomizer.addEventListener(PictureAtomizer.PARTICLES_CREATED, go);
atomizer.createParticles(pic[0]);
}
function go(evt:Event):void {
particles = atomizer.particleArray;
atomizer.setPositionsByPic(0,0,0); //center position
stage.addChild(board.holder);
createTextLabels();
stage.addEventListener(Event.ENTER_FRAME, onEnter);
}
function onEnter(evt:Event):void {
//Viewpoint-independent changes to particle positions. Here we present an example of each particle oscillating in the z direction, with amplitude related to the luminance of the particle. //
param = 0.65*Math.min(1.75,Math.max(0,(1-Math.cos(getTimer()*.0003)-0.25*Math.cos(getTimer()*.0006))));
for (var i:Number = 0; i<= particles.length – 1; i++) {
p = particles[i];
p.z = param*(p.lum-128);
}
//apply Filters to effect fade-out of old pixels
board.bitmapData.applyFilter(board.bitmapData, boardRect, filterPoint, blur);
board.bitmapData.colorTransform(boardRect,darken);
//draw particles
board.drawParticles(particles);
}

3. Here the path of folder name is very important. So give the proper name to your folder and files and give the same path name in actionscript too. Keep your fla file in separate folder name it as your wish like “3Dparticles” and inside this folder create one folder in the name of “Image”. Place all your required pictures in this folder.

4. Create one folder inside the “3Dparticles” folder in the name of “main”. Again create one “submain” folder within the “main”.

5. it’s time to create five folders inside the “submain”. Name it as bitmapUtilities, display, geom3D, loaders, and objects.

6. Open actionscript file by press ctrl+n. Copy and paste the following code and save it as “PictureAtomizer” in “bitmapUtilities”:

package main.submain.bitmapUtilities {
import flash.display.*;
import flash.events.*;
import main.submain.geom3D.*;
import main.submain.objects.Particle3D;
public class PictureAtomizer extends EventDispatcher {
public static const PARTICLES_CREATED:String=”particlesCreated”;
public var pic:Bitmap;
public var sampling:Number;
public var spread:Number;
public var originX:Number;
public var originY:Number;
public var sampleFuzzX:Number;
public var sampleFuzzY:Number;
private var _particleArray:Array;
public function PictureAtomizer(inputSampling=1, inputSpread=1, inputOriginX=0, inputOriginY=0, inputFuzzX=0, inputFuzzY=0):void {
this.sampling = inputSampling;
this.spread = inputSpread;
this.originX = inputOriginX;
this.originY = inputOriginY;
this.sampleFuzzX = inputFuzzX;
this.sampleFuzzY = inputFuzzY;
this._particleArray = [];
}
public function createParticles(inputPic:Bitmap):void {
var c:uint;
var m:Number;
var num:Number = 0;
var x0:Number;
var y0:Number;
this.pic = inputPic;
//separate picture pixels into layers
for (var i:Number=0; i<=pic.width-1; i = i + sampling) {
for (var j:Number=0; j<=pic.height-1; j = j + sampling) {
//read pixel (i,j)
x0 = i + sampleFuzzX*sampling*(2*Math.random()-1);
y0 = j + sampleFuzzY*sampling*(2*Math.random()-1);
//create particle
c = pic.bitmapData.getPixel32(x0,y0);
var p:Particle3D = new Particle3D(c);
//set picture-based coordinates
p.picX = spread*(x0 – originX);
p.picY = spread*(y0 – originY);
//add to array
this.particleArray.push(p);
}
}
dispatchEvent(new Event(PictureAtomizer.PARTICLES_CREATED));
}
public function setProjectionCoords(fLen:Number):void {
var m:Number;
var p:Particle3D;
for (var t=0; t<= _particleArray.length – 1; t++) {
p = _particleArray[t];
m = fLen/(fLen – p.w);
p.projX = p.u*m + originX;
p.projY = p.v*m + originY;
}
}
public function setPositionsByPic(offsetX:Number, offsetY:Number, z0:Number):void {
var p:Particle3D;
for (var t=0; t<= _particleArray.length – 1; t++) {
p = _particleArray[t];
p.x = p.picX + offsetX;
p.y = p.picY + offsetY;
p.z = z0;
}
}
public function setGlobalAlpha(globalAlpha:Number):void {
var c:uint;
var p:Particle3D;
trace(_particleArray.length);
for (var t=0; t<= _particleArray.length – 1; t++) {
p = _particleArray[t];
p.setColor((uint(255*globalAlpha) << 24) | (p.color & 0x00FFFFFF));
}
}

public function buildDestinationArrays(numDestinations:Number):void {
var p:Particle3D;
for (var t=0; t<= _particleArray.length – 1; t++) {
p = _particleArray[t];
for (var n:Number = 0; n <= numDestinations-1; n++) {
var thisPoint3D:Point3D = new Point3D();
p.dest.push(thisPoint3D);
}
}
}
public function get particleArray():Array {
return _particleArray;
}
}
}

7. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “ParticleBoard” in “display”:
package main.submain.display {
import flash.display.*;
import main.submain.objects.Particle3D;
import main.submain.geom3D.*;
public class ParticleBoard extends Bitmap {
public var zBuffer:Array;
public var fLen:Number;
public var projOriginX:Number;
public var projOriginY:Number;
//darkening related variables
private var useDepthDarken:Boolean;
private var A:Number;
private var expRate:Number;
private var maxBrighten:Number;
private var bgColor;
//Vars used in functions
private var f:Number;
private var m:Number;
private var dColor:uint;
private var intX:int;
private var intY:int;
private var p:Particle3D;
private var X2:Number;
private var Y2:Number;
private var Z2:Number;
private var wX:Number;
private var wY:Number;
private var wZ:Number;
private var xX:Number;
private var xY:Number;
private var xZ:Number;
private var yY:Number;
private var yZ:Number;
private var zZ:Number;
public var frame:Shape;
public var holder:Sprite;
/*
frame = new Shape();
frame.graphics.lineStyle(2,0×444444);
frame.graphics.drawRect(0,0,board.width,board.height);
frame.x = 0;
frame.y = 0;
boardHolder = new Sprite();
boardHolder.x = stage.stageWidth/2 – board.width/2;
boardHolder.y = stage.stageHeight/2 – board.height/2;
stage.addChild(boardHolder);
boardHolder.addChild(board);
boardHolder.addChild(frame);
*/
public function ParticleBoard(w, h, transp=true, fillColor = 0x00000000, _fLen=200) {
var thisData:BitmapData = new BitmapData(w, h, transp, fillColor)
this.bitmapData = thisData;
this.zBuffer = [];
this.useDepthDarken = false; //changed to true in setDepthDarken
this.projOriginX = w/2;
this.projOriginY = h/2;
this.fLen = _fLen;
this.bgColor = fillColor;
this.holder = new Sprite();
this.holder.addChild(this);
this.x = 0;
this.y = 0;
}
public function makeFrame(thick:Number, c:uint, inputAlpha:Number):void {
this.frame = new Shape();
this.frame.graphics.lineStyle(thick, c, inputAlpha);
this.frame.graphics.drawRect(0,0,this.width,this.height);
this.frame.x = 0;
this.frame.y = 0;
this.holder.addChild(frame);
}
public function setDepthDarken(unityDepth:Number, halfDepth:Number, _maxBrighten):void {
this.useDepthDarken = true;
this.A = Math.pow(2, unityDepth/(halfDepth-unityDepth));
this.expRate = Math.LN2/(unityDepth-halfDepth);
this.maxBrighten = _maxBrighten;
}
public function clearBoard(particles:Array):void {
for (var i:Number = 0; i<=particles.length-1; i++) {
p = particles[i];
if (p.onScreen) {
intX = int(p.projX);
intY = int(p.projY);
zBuffer[intX+this.height*intY] = Number.NEGATIVE_INFINITY;
//could also insert the code below to erase pixels, but my method has been to use a blur filter and a colorTransform applied to whole bitmap, which creates “ghost” which fades out after a few frames. this.bitmapData.setPixel32(intX, intY, bgColor);
}
}
}//end of clearBoard
public function drawParticles(particles:Array, q:Quaternion):void {
//clear the zBuffer
clearBoard(particles);
for (var i:Number = 0; i<=particles.length-1; i++) {
p = particles[i];
//viewpoint-relative coordinates found by quaternion rotation. Quaternion has been converted to rotation matrix, using common subexpressions for efficiency. X2 = 2*q.x;
Y2 = 2*q.y;
Z2 = 2*q.z;
wX = q.w*X2;
wY = q.w*Y2;
wZ = q.w*Z2;
xX = q.x*X2;
xY = q.x*Y2;
xZ = q.x*Z2;
yY = q.y*Y2;
yZ = q.y*Z2;
zZ = q.z*Z2;
p.u = (1-(yY+zZ))*p.x + (xY-wZ)*p.y + (xZ+wY)*p.z;
p.v = (xY+wZ)*p.x + (1-(xX+zZ))*p.y + (yZ-wX)*p.z;
p.w = (xZ-wY)*p.x + (yZ+wX)*p.y + (1-(xX+yY))*p.z;
//Projection coordinates
m = fLen/(fLen – p.w);
p.projX = p.u*m + projOriginX;
p.projY = p.v*m + projOriginY;
//test if particle is in viewable region
if ((p.projX > this.width)||(p.projX<0)||(p.projY<0)||(p.projY>this.height)||(p.w>fLen-1)) {
p.onScreen = false;
}
else {
p.onScreen = true;
}
//drawing
intX = int(p.projX);
intY = int(p.projY);
if (p.onScreen) {
if (!(p.w < zBuffer[intX+this.height*intY])) {
if (this.useDepthDarken) {
//position-based darkening – exponential
f = A*Math.exp(expRate*p.w);
if (f>maxBrighten) {
f = maxBrighten;
}
dColor = (0xFF000000) |(Math.min(255,f*p.red) << 16) | (Math.min(255,f*p.green) << 8 ) | (Math.min(255,f*p.blue));
this.bitmapData.setPixel32(intX, intY, dColor);
}
else {
this.bitmapData.setPixel32(intX, intY, p.color);
}

this.zBuffer[intX+this.height*intY] = p.w;
}
}
}
}//end of drawParticles
}//end of class definition
}

8. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “RotatingParticleBoard” in “display”:

package main.submain.display {
import flash.display.*;
import flash.events.*;
import main.submain.objects.Particle3D;
import main.submain.geom3D.*;
import flash.events.MouseEvent;
public class RotatingParticleBoard extends Bitmap {
public var zBuffer:Array;
public var fLen:Number;
public var projOriginX:Number;
public var projOriginY:Number;
//darkening related variables
private var useDepthDarken:Boolean;
private var A:Number;
private var expRate:Number;
private var maxBrighten:Number;
private var bgColor;
//Vars used in functions
private var f:Number;
private var m:Number;
private var dColor:uint;
private var intX:int;
private var intY:int;
private var p:Particle3D;
private var X2:Number;
private var Y2:Number;
private var Z2:Number;
private var wX:Number;
private var wY:Number;
private var wZ:Number;
private var xX:Number;
private var xY:Number;
private var xZ:Number;
private var yY:Number;
private var yZ:Number;
private var zZ:Number;
public var frame:Shape;
public var holder:Sprite;
private var v1:Point3D;
private var v2:Point3D;
private var rSquare:Number;
private var invR:Number;
private var mouseDragging:Boolean;
private var lastQ:Quaternion;
private var changeQ:Quaternion;
private var requestQ:Quaternion;
private var inside:Boolean;
private var numRadii:Number;
public var arcballRad:Number;
public var currentQ:Quaternion;
public var autoQuaternion:Quaternion;
public var easingRatio:Number;
private var s:Number;
public function RotatingParticleBoard(w, h, transp=true, fillColor = 0x00000000, _fLen=200) {
var thisData:BitmapData = new BitmapData(w, h, transp, fillColor)
this.bitmapData = thisData;
this.zBuffer = [];
this.useDepthDarken = false; //changed to true in setDepthDarken
this.projOriginX = w/2;
this.projOriginY = h/2;
this.fLen = _fLen;
this.bgColor = fillColor;
this.holder = new Sprite();
this.holder.addChild(this);
this.x = 0;
this.y = 0;
this.arcballRad = 0.5*Math.sqrt(Math.pow(w,2)+Math.pow(h,2));
this.lastQ = new Quaternion();
this.currentQ = new Quaternion(1,0,0,0);
this.autoQuaternion = new Quaternion(1,0,0,0);
this.lastQ = this.currentQ.clone();
this.requestQ = new Quaternion();
this.changeQ = new Quaternion(1,0,0,0);
this.v1 = new Point3D;
this.v2 = new Point3D;
this.mouseDragging = false;
this.easingRatio = 0.4;
this.holder.addEventListener(Event.ADDED_TO_STAGE, addListeners);
}
private function addListeners(evt:Event):void {
this.holder.removeEventListener(Event.ADDED_TO_STAGE, addListeners);
this.holder.addEventListener(MouseEvent.MOUSE_DOWN, onDown);
this.holder.root.addEventListener(MouseEvent.MOUSE_UP, onUp);
}
public function makeFrame(thick:Number, c:uint, inputAlpha:Number):void {
this.frame = new Shape();
this.frame.graphics.lineStyle(thick, c, inputAlpha);
this.frame.graphics.drawRect(0,0,this.width,this.height);
this.frame.x = 0;
this.frame.y = 0;
this.holder.addChild(frame);
}
public function setDepthDarken(unityDepth:Number, halfDepth:Number, _maxBrighten):void {
this.useDepthDarken = true;
this.A = Math.pow(2, unityDepth/(halfDepth-unityDepth));
this.expRate = Math.LN2/(unityDepth-halfDepth);
this.maxBrighten = _maxBrighten;
}
public function clearBoard(particles:Array):void {
for (var i:Number = 0; i<=particles.length-1; i++) {
p = particles[i];
if (p.onScreen) {
intX = int(p.projX);
intY = int(p.projY);
zBuffer[intX+this.height*intY] = Number.NEGATIVE_INFINITY;
//could also insert the code below to erase pixels, but my method has been to use a blur filter and a colorTransform applied to whole bitmap, which creates “ghost” which fades out after a few frames. this.bitmapData.setPixel32(intX, intY, bgColor);
}
}
}//end of clearBoard
public function drawParticles(particles:Array):void {
clearBoard(particles);
///////////
//viewpoint change by mouse
if (mouseDragging) {
v2.x = (holder.mouseX-projOriginX)/arcballRad;
v2.y = (holder.mouseY-projOriginY)/arcballRad;
rSquare = v2.x*v2.x + v2.y*v2.y;
//for mouse position outside Arcball perimeter:
if (rSquare > 1) {
invR = 1/Math.sqrt(rSquare);
v2.x = v2.x*invR;
v2.y = v2.y*invR;
v2.z = 0;
}
//for mouse position inside Arcball perimeter:
else {
v2.z = Math.sqrt(1 – rSquare);
inside = true;
}
//interpret mouse movement as request for rotation change
requestQ.w = v1.x*v2.x + v1.y*v2.y + v1.z*v2.z;
requestQ.x = v1.y*v2.z – v2.y*v1.z;
requestQ.y = -v1.x*v2.z + v2.x*v1.z;
requestQ.z = v1.x*v2.y – v2.x*v1.y;
//smooth movement is accomplished by rotating only 40% towards the requested rotation in each frame. After about ten frames, the rotation will be within 1% of the requested rotation.
changeQ.w += easingRatio*(requestQ.w – changeQ.w);
changeQ.x += easingRatio*(requestQ.x – changeQ.x);
changeQ.y += easingRatio*(requestQ.y – changeQ.y);
changeQ.z += easingRatio*(requestQ.z – changeQ.z);
//ensure that the change quaternion is a unit quaternion:
s = 1/Math.sqrt(changeQ.w*changeQ.w +changeQ.x*changeQ.x+changeQ.y*changeQ.y+changeQ.z*changeQ.z);
changeQ.w *= s;
changeQ.x *= s;
changeQ.y *= s;
changeQ.z *= s;
}
else {
lastQ = currentQ.clone();
changeQ.w = autoQuaternion.w;
changeQ.x = autoQuaternion.x;
changeQ.y = autoQuaternion.y;
changeQ.z = autoQuaternion.z;
}
//find current resultant rotation by quaternion multiplication of
lastQ and changeQ
currentQ.w = changeQ.w*lastQ.w – changeQ.x*lastQ.x – changeQ.y*lastQ.y – changeQ.z*lastQ.z;
currentQ.x = changeQ.w*lastQ.x + lastQ.w*changeQ.x + changeQ.y*lastQ.z – lastQ.y*changeQ.z;
currentQ.y = changeQ.w*lastQ.y + lastQ.w*changeQ.y – changeQ.x*lastQ.z + lastQ.x*changeQ.z;
currentQ.z = changeQ.w*lastQ.z + lastQ.w*changeQ.z + changeQ.x*lastQ.y – lastQ.x*changeQ.y;
///////////
for (var i:Number = 0; i<=particles.length-1; i++) {
p = particles[i];
//viewpoint-relative coordinates found by quaternion rotation. Quaternion has been converted to rotation matrix, usingcommon subexpressions for efficiency.
X2 = 2*currentQ.x;
Y2 = 2*currentQ.y;
Z2 = 2*currentQ.z;
wX = currentQ.w*X2;
wY = currentQ.w*Y2;
wZ = currentQ.w*Z2;
xX = currentQ.x*X2;
xY = currentQ.x*Y2;
xZ = currentQ.x*Z2;
yY = currentQ.y*Y2;
yZ = currentQ.y*Z2;
zZ = currentQ.z*Z2;
p.u = (1-(yY+zZ))*p.x + (xY-wZ)*p.y + (xZ+wY)*p.z;
p.v = (xY+wZ)*p.x + (1-(xX+zZ))*p.y + (yZ-wX)*p.z;
p.w = (xZ-wY)*p.x + (yZ+wX)*p.y + (1-(xX+yY))*p.z;
//Projection coordinates
m = fLen/(fLen – p.w);
p.projX = p.u*m + projOriginX;
p.projY = p.v*m + projOriginY;
//test if particle is in viewable region
if ((p.projX > this.width)||(p.projX<0)||(p.projY<0)||(p.projY>this.height)||(p.w>fLen-1)) {
p.onScreen = false;
}
else {
p.onScreen = true;
}
//drawing
intX = int(p.projX);
intY = int(p.projY);
if (p.onScreen) {
if (!(p.w < zBuffer[intX+this.height*intY])) {
if (this.useDepthDarken) {
//position-based darkening – exponential
f = A*Math.exp(expRate*p.w);
if (f>maxBrighten) {
f = maxBrighten;
}
dColor = (0xFF000000) |(Math.min(255,f*p.red) << 16) | (Math.min(255,f*p.green) << 8) | (Math.min(255,f*p.blue));
this.bitmapData.setPixel32(intX, intY, dColor);
}
else {
this.bitmapData.setPixel32(intX, intY, p.color);
}
this.zBuffer[intX+this.height*intY] = p.w;
}
}
}
}//end of drawParticles
private function onDown(evt:MouseEvent):void {
mouseDragging = true;
changeQ = new Quaternion(1,0,0,0);
lastQ = currentQ.clone();
v1.x = (holder.mouseX-projOriginX)/arcballRad;
v1.y = (holder.mouseY-projOriginY)/arcballRad;
rSquare = v1.x*v1.x + v1.y*v1.y;
if (rSquare > 1) {
invR = 1/Math.sqrt(rSquare);
v1.x = v1.x*invR;
v1.y = v1.y*invR;
v1.z = 0;
inside = false;
}
else {
v1.z = Math.sqrt(1 – rSquare);
inside = true;
}
}
private function onUp(evt:MouseEvent):void {
mouseDragging = false;
}
}//end of class definition
}

9. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “Point3D” in “geom3D”:

package main.submain.geom3D {
public class Point3D {
public var x:Number;
public var y:Number;
public var z:Number;
public function Point3D(x1=0,y1=0,z1=0):void {
this.x = x1;
this.y = y1;
this.z = z1;
}
}
}

10. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “Quaternion” in “geom3D”:

package main.submain.geom3D {
public class Quaternion {
public var w;
public var x;
public var y;
public var z;
public function Quaternion(_w=0,_x=0, _y=0, _z=0) {
this.w = _w;
this.x = _x;
this.y = _y;
this.z = _z;
}
public function clone():Quaternion {
return new Quaternion(this.w, this.x, this.y, this.z);
}}}

11. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “IndexedLoader” in “loaders”:

package main.submain.loaders {
import flash.display.Loader;
public class IndexedLoader extends Loader {
public var which:Number;
public var done:Boolean;
function IndexedLoader(inputIndex):void {
this.which = inputIndex;
this.done = false;
}}}

12. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “PictureLoader” in “loaders”:

package main.submain.loaders {
import flash.display.*;
import flash.events.*;
import flash.net.URLRequest;
import main.submain.loaders.IndexedLoader;
public class PictureLoader extends EventDispatcher {
public static const ALL_PICS_LOADED:String=”allPicsLoaded”;
private function dispatch():void {
dispatchEvent(new Event(PictureLoader.ALL_PICS_LOADED));
}
public var picURLArray:Array = [];
private var picLoader:Array = [];
private var pic:Array=[];
private var loadCount:Number;
public var failPicSize:Number;
public var useFailPic:Boolean;
public function PictureLoader(_useFailPic = true, _failPicSize = 16) {
this.useFailPic = _useFailPic;
this.failPicSize = _failPicSize;
}
public function loadPics(inputURLArray:Array):void {
picURLArray = inputURLArray;
pic = [];
loadCount = 0;
setUpLoaders();
}
private function failPic():Sprite {
var thisPic:Sprite = new Sprite();
thisPic.graphics.lineStyle(2,0xdddddd);
thisPic.graphics.beginFill(0x000000);
thisPic.graphics.drawRect(0,0,failPicSize,failPicSize);
thisPic.graphics.endFill();
thisPic.graphics.lineStyle(2,0xdd0000);
thisPic.graphics.moveTo(2,2);
thisPic.graphics.lineTo(failPicSize-2,failPicSize-2);
thisPic.graphics.moveTo(failPicSize-2,2);
thisPic.graphics.lineTo(2,failPicSize-2);
return thisPic;
}
private function cleanUp():void {
var errorPic:Array = [];
for (var n:Number=0; n<= picURLArray.length-1; n++) {
if (pic[n]==null) {
//trace(“Picture “+String(n)+” not loaded.”);
picLoader[n].contentLoaderInfo.removeEventListener(Event.INIT, initListener);
picLoader[n].contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, errorHandler);
errorPic.push(n);
}
}
if (useFailPic) {
//place fail pic in bad spots
if (errorPic.length != 0) {
for (n = 0; n<= errorPic.length – 1; n++) {
var thisBitmapData:BitmapData = new BitmapData(failPicSize, failPicSize);
var thisBitmap:Bitmap = new Bitmap(thisBitmapData);
thisBitmapData.draw(failPic());
pic[errorPic[n]] = thisBitmap;
}
}
}
else {
//remove error pics from pic array
if (errorPic.length != 0) {
for (n = 0; n<= errorPic.length – 1; n++) {
pic.splice(errorPic[n],1);
}
}
}
}
private function setUpLoaders():void {
var thisURL:URLRequest; //create a loader for each picture, to load simultaneously.
for (var n:Number=0; n<= picURLArray.length-1; n++) {
var thisLoader:IndexedLoader = new IndexedLoader(n);
picLoader.push(thisLoader);
picLoader[n].load(new URLRequest(picURLArray[n]));
picLoader[n].contentLoaderInfo.addEventListener(Event.INIT, initListener);
picLoader[n].contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
}
}
private function errorHandler(evt:ErrorEvent):void {
loadCount++;
if (loadCount == picURLArray.length) {
cleanUp();
dispatch();
}
}
private function initListener(evt:Event):void {
//copy loaded picture to pic array
try {
var n:Number = evt.currentTarget.loader.which;
//trace(“picture “+String(n)+” loaded.”);
pic[n] = Bitmap(picLoader[n].content);
}
catch (err:Error) {
//trace(“picture “+String(n)+” unsuccessful.”);
}
//remove event listener
picLoader[n].contentLoaderInfo.removeEventListener(Event.INIT, initListener);
loadCount++;
if (loadCount == picURLArray.length) {
cleanUp();
dispatch();
}
}
public function get picArray():Array {
return pic;
}
}
}

12. Again open actionscript file by press ctrl+n. Copy and paste the following code and save it as “Particle3D” in “objects”:

package main.submain.objects {
import flash.display.*;
import main.submain.geom3D.*;
public class Particle3D extends Point3D {
//links, for creating linked lists
public var next:Particle3D;
public var prev:Particle3D;
public var onScreen:Boolean;
//velocity and acceleration vectors
public var vel:Point3D = new Point3D();
public var accel:Point3D = new Point3D();
public var lastX:Number;
public var lastY:Number;
public var lastZ:Number;
//projected coordinates
public var projX:Number;
public var projY:Number;
//coords WRT viewpoint axes
public var u:Number;
public var v:Number;
public var w:Number;
//location in source picture
public var picX:Number;
public var picY:Number;
//destination array
public var dest:Array;
//attributes
public var color:uint;
public var red:Number;
public var green:Number;
public var blue:Number;
public var lum:Number;
public var alpha:Number;
public var initColor:uint;
public var initRed:Number;
public var initGreen:Number;
public var initBlue:Number;
public var initLum:Number;
public var destColor:uint;
public var destRed:Number;
public var destGreen:Number;
public var destBlue:Number;
public var destLum:Number;
public var colorChanging:Boolean;
function Particle3D(thisColor=0xFFFFFFFF):void {
this.dest = [];
this.color = thisColor;
this.red = getRed(thisColor);
this.green = getGreen(thisColor);
this.blue = getBlue(thisColor);
this.alpha = getAlpha(thisColor);
this.lum = 0.2126*this.red + 0.7152*this.green + 0.0722*this.blue;
this.colorChanging = false;
this.onScreen = true;
}
public function setColor(thisColor):void {
this.color = thisColor;
this.red = getRed(thisColor);
this.green = getGreen(thisColor);
this.blue = getBlue(thisColor);
this.alpha = getAlpha(thisColor);
this.lum = 0.2126*this.red + 0.7152*this.green + 0.0722*this.blue;
}
public function getAlpha(c):Number {
return Number((c >> 24) & 0xFF);
}
public function getRed(c):Number {
return Number((c >> 16) & 0xFF);
}
public function getGreen(c):Number {
return Number((c >> 8) & 0xFF);
}
public function getBlue(c):Number {
return Number(c & 0xFF);
}
}
}

Run the program.

Tags:

Request a Free SEO Quote