RE: [Flashcoders] Trigonometry Problem

2010-08-16 Thread Merrill, Jason
 have the items align into a circle at the nearest point, *keeping the
   same angle*

I'm not sure what that means exactly, but check out Point.polar()


Jason Merrill 

Instructional Technology Architect
Bank of America   Global Learning 

Join the Bank of America Flash Platform Community  and visit our
Instructional Technology Design Blog
(Note: these resources are only available for Bank of America
associates)






-Original Message-
From: flashcoders-boun...@chattyfig.figleaf.com
[mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jared
stanley
Sent: Wednesday, August 11, 2010 3:51 PM
To: Flash Coders List
Subject: [Flashcoders] Trigonometry Problem

hey all,

working on getting a grid to expand into a circle.

I would like to:

   - place items in a grid
   - calculate angle from centerpoint(or any desired point)
   - have the items align into a circle at the nearest point, *keeping
the
   same angle*


here's my progress:
http://lab.freestyleinteractive.com/jared/maths/radius.html

the start and end is pretty close to what i want, but i'd like the items
to rearrange keeping the same angle, so an item that was on the top left
would stay on the top left area and an item to the right in the grid
would stay to the right in a circle.

hope this makes sense.

code is below, thanks for any help!

private function init():void{
//create and center container clip
mainClip = new MovieClip(); //container clip for all items
addChild(mainClip);
mainClip.x = stage.stageWidth / 2;
mainClip.y = stage.stageHeight / 2;

createParticles();

//draw circle around centerpoint for visual reference
mainClip.graphics.lineStyle(2, 0xff, .5);
mainClip.graphics.drawCircle(0, 0, 100);
//
stage.addEventListener(MouseEvent.CLICK, expand);

}

private function createParticles():void{
for(var i:int = 0; imaxParticles; i++){

var particle:Particle = new Particle();//just a sprite
with some properties
   //create grid, calculate original X  Y positons;
particle.i = i;
particle.x = (particle.width + 5) * (i % 20);
particle.y = (particle.height + 5) * Math.floor(i / 20);
particle.ox = particle.x;
particle.oy = particle.y;
//calculate angle from the 0 point;
var rad:Number = Math.atan2(mainClip.x-particle.y,
mainClip.y-particle.x);
var angle:Number = rad * 180 / Math.PI;
particle.angle = angle;
mainClip.addChild(particle);
//put all particles in an array to be referenced below
particlesArr.push(particle);
}

//code below is to recenter the grid on the centerpoint
instead of top left
var tmpw:Number = mainClip.width;
var tmph:Number = mainClip.height;
//loop through to offset the grid so it's even within the
page
for(i = 0; iparticlesArr.length; i++){
var p:Particle = particlesArr[i];
p.x -= tmpw* 0.5;
p.y -= tmph* 0.5;
p.ox = p.x;
p.oy = p.y
}

addEventListener(Event.ENTER_FRAME, moveAll);
}


private function expand(e:MouseEvent):void{
isGrid = !isGrid;

for each (var p in particlesArr) {
p.tgtx = Math.cos(p.angle)*mag;
p.tgty = Math.sin(p.angle)*mag;
}

}


private function moveAll(e:Event):void{
var mainTgtX:Number;
var mainTgtY:Number;

if(!isGrid){
for each (var p in particlesArr) {
p.x += (p.tgtx - p.x) /20;
p.y += (p.tgty - p.y) /20;
}

}else {

   for each (p in particlesArr) {
p.x += (p.ox - p.x) /20;
p.y += (p.oy- p.y) /10;
}

}
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


Re: [Flashcoders] Trigonometry Problem

2010-08-16 Thread Patrick Matte
I always refer to this for all my trigonometry needs

http://www.actionscript.org/resources/articles/155/1/trigonometry-and-flash/
Page1.html




 From: Merrill, Jason jason.merr...@bankofamerica.com
 Reply-To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Date: Mon, 16 Aug 2010 12:57:22 -0400
 To: Flash Coders List flashcoders@chattyfig.figleaf.com
 Conversation: [Flashcoders] Trigonometry Problem
 Subject: RE: [Flashcoders] Trigonometry Problem
 
 have the items align into a circle at the nearest point, *keeping the
same angle*
 
 I'm not sure what that means exactly, but check out Point.polar()
 
 
 Jason Merrill 
 
 Instructional Technology Architect
 Bank of America   Global Learning
 
 Join the Bank of America Flash Platform Community  and visit our
 Instructional Technology Design Blog
 (Note: these resources are only available for Bank of America
 associates)
 
 
 
 
 
 
 -Original Message-
 From: flashcoders-boun...@chattyfig.figleaf.com
 [mailto:flashcoders-boun...@chattyfig.figleaf.com] On Behalf Of jared
 stanley
 Sent: Wednesday, August 11, 2010 3:51 PM
 To: Flash Coders List
 Subject: [Flashcoders] Trigonometry Problem
 
 hey all,
 
 working on getting a grid to expand into a circle.
 
 I would like to:
 
- place items in a grid
- calculate angle from centerpoint(or any desired point)
- have the items align into a circle at the nearest point, *keeping
 the
same angle*
 
 
 here's my progress:
 http://lab.freestyleinteractive.com/jared/maths/radius.html
 
 the start and end is pretty close to what i want, but i'd like the items
 to rearrange keeping the same angle, so an item that was on the top left
 would stay on the top left area and an item to the right in the grid
 would stay to the right in a circle.
 
 hope this makes sense.
 
 code is below, thanks for any help!
 
 private function init():void{
 //create and center container clip
 mainClip = new MovieClip(); //container clip for all items
 addChild(mainClip);
 mainClip.x = stage.stageWidth / 2;
 mainClip.y = stage.stageHeight / 2;
 
 createParticles();
 
 //draw circle around centerpoint for visual reference
 mainClip.graphics.lineStyle(2, 0xff, .5);
 mainClip.graphics.drawCircle(0, 0, 100);
 //
 stage.addEventListener(MouseEvent.CLICK, expand);
 
 }
 
 private function createParticles():void{
 for(var i:int = 0; imaxParticles; i++){
 
 var particle:Particle = new Particle();//just a sprite
 with some properties
//create grid, calculate original X  Y positons;
 particle.i = i;
 particle.x = (particle.width + 5) * (i % 20);
 particle.y = (particle.height + 5) * Math.floor(i / 20);
 particle.ox = particle.x;
 particle.oy = particle.y;
 //calculate angle from the 0 point;
 var rad:Number = Math.atan2(mainClip.x-particle.y,
 mainClip.y-particle.x);
 var angle:Number = rad * 180 / Math.PI;
 particle.angle = angle;
 mainClip.addChild(particle);
 //put all particles in an array to be referenced below
 particlesArr.push(particle);
 }
 
 //code below is to recenter the grid on the centerpoint
 instead of top left
 var tmpw:Number = mainClip.width;
 var tmph:Number = mainClip.height;
 //loop through to offset the grid so it's even within the
 page
 for(i = 0; iparticlesArr.length; i++){
 var p:Particle = particlesArr[i];
 p.x -= tmpw* 0.5;
 p.y -= tmph* 0.5;
 p.ox = p.x;
 p.oy = p.y
 }
 
 addEventListener(Event.ENTER_FRAME, moveAll);
 }
 
 
 private function expand(e:MouseEvent):void{
 isGrid = !isGrid;
 
 for each (var p in particlesArr) {
 p.tgtx = Math.cos(p.angle)*mag;
 p.tgty = Math.sin(p.angle)*mag;
 }
 
 }
 
 
 private function moveAll(e:Event):void{
 var mainTgtX:Number;
 var mainTgtY:Number;
 
 if(!isGrid){
 for each (var p in particlesArr) {
 p.x += (p.tgtx - p.x) /20;
 p.y += (p.tgty - p.y) /20;
 }
 
 }else {
 
for each (p in particlesArr) {
 p.x += (p.ox - p.x) /20;
 p.y += (p.oy- p.y) /10;
 }
 
 }
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
 ___
 Flashcoders mailing list
 Flashcoders

[Flashcoders] Trigonometry Problem

2010-08-11 Thread jared stanley
hey all,

working on getting a grid to expand into a circle.

I would like to:

   - place items in a grid
   - calculate angle from centerpoint(or any desired point)
   - have the items align into a circle at the nearest point, *keeping the
   same angle*


here's my progress:
http://lab.freestyleinteractive.com/jared/maths/radius.html

the start and end is pretty close to what i want, but i'd like the items to
rearrange keeping the same angle,
so an item that was on the top left would stay on the top left area and an
item to the right in the grid would stay to the right in a circle.

hope this makes sense.

code is below, thanks for any help!

private function init():void{
//create and center container clip
mainClip = new MovieClip(); //container clip for all items
addChild(mainClip);
mainClip.x = stage.stageWidth / 2;
mainClip.y = stage.stageHeight / 2;

createParticles();

//draw circle around centerpoint for visual reference
mainClip.graphics.lineStyle(2, 0xff, .5);
mainClip.graphics.drawCircle(0, 0, 100);
//
stage.addEventListener(MouseEvent.CLICK, expand);

}

private function createParticles():void{
for(var i:int = 0; imaxParticles; i++){

var particle:Particle = new Particle();//just a sprite with
some properties
   //create grid, calculate original X  Y positons;
particle.i = i;
particle.x = (particle.width + 5) * (i % 20);
particle.y = (particle.height + 5) * Math.floor(i / 20);
particle.ox = particle.x;
particle.oy = particle.y;
//calculate angle from the 0 point;
var rad:Number = Math.atan2(mainClip.x-particle.y,
mainClip.y-particle.x);
var angle:Number = rad * 180 / Math.PI;
particle.angle = angle;
mainClip.addChild(particle);
//put all particles in an array to be referenced below
particlesArr.push(particle);
}

//code below is to recenter the grid on the centerpoint instead
of top left
var tmpw:Number = mainClip.width;
var tmph:Number = mainClip.height;
//loop through to offset the grid so it's even within the page
for(i = 0; iparticlesArr.length; i++){
var p:Particle = particlesArr[i];
p.x -= tmpw* 0.5;
p.y -= tmph* 0.5;
p.ox = p.x;
p.oy = p.y
}

addEventListener(Event.ENTER_FRAME, moveAll);
}


private function expand(e:MouseEvent):void{
isGrid = !isGrid;

for each (var p in particlesArr) {
p.tgtx = Math.cos(p.angle)*mag;
p.tgty = Math.sin(p.angle)*mag;
}

}


private function moveAll(e:Event):void{
var mainTgtX:Number;
var mainTgtY:Number;

if(!isGrid){
for each (var p in particlesArr) {
p.x += (p.tgtx - p.x) /20;
p.y += (p.tgty - p.y) /20;
}

}else {

   for each (p in particlesArr) {
p.x += (p.ox - p.x) /20;
p.y += (p.oy- p.y) /10;
}

}
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders