Re: [Flashcoders] Help Registration point and origion point

2011-08-03 Thread nasim hhhhh

Hi
I'm Really appreciate u 
I want to simulate Osiloscope . Part of My program give me x,y and I shoudl 
draw wave base on that point in osiloscope  ,my osiloscope should have scalex 
and y i should can move to right and left up and down 
I cant make it dynamically so i make 2 empty MovieClip nested in firt mc I draw 
my wave and move it left and Right and in parent I use scale but it has a bit 
bug  and my wave will be thiker after  scale
what do u do it and how to program it 

this is my  problem can u help me 
omethin like this not actually 
http://d.violet.vn/uploads/resources/171/scope.swf
--- On Tue, 8/2/11, Ktu ktu_fl...@cataclysmicrewind.com wrote:

From: Ktu ktu_fl...@cataclysmicrewind.com
Subject: Re: [Flashcoders] Help Registration point and origion point
To: Flash Coders List flashcoders@chattyfig.figleaf.com
Date: Tuesday, August 2, 2011, 10:33 AM

Hopefully below will help you:

I'm going to just explain how the origin stuff works, and how you can learn
to compensate for it, and maybe you can apply this to your work. Starting
off with an example where the visual elements of a sprite are not originated
at 0,0

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill();
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);

*the stage thinks this:*
mySprite.x = 10;
mySprite.y = 10;
mySprite.width = 50;
mySprite.height = 50;

*mySprite thinks this:*
this.x = 10;
this.y = 10;
this.width = 50;
this.height = 50;

But what happened to the fact that the rectangle I drew lives at x:10, y:10
!!!


*So how do you find out where the origin is from inside mySprite?*
 - mySprite.getBounds(mySprite);

this will return the boundaries of mySprite, in relation to mySprite. The
visual reality of mySprite is that its boundaries are this:

x: 10
y: 10
width:50
height:50


your origin offset is x:10, y:10. This still doesn't account for the x and y
placement of mySprite on the stage, but that is simple to calculate.


*The next part, is compensating for the scale:
**
*If you take our mySprite from above, and scale it to 2, there are some
notable changes:
 - mySprite.scaleX = mySprite.scaleY = 2;

mySprite thinks:
x:10
y:10
width:100
height:100

mySprite.getBounds(mySprite) returns this:
x:10
y:10
width:50
height:50

The visual elements inside of mySprite did not grow, but mySprite is telling
it to grow (because of the scaleX | scaleY changes)

But what is probably messing you up is that when you scale an object that
has an origin offset, the distance between the origin offset is multiplied
by the same scale.

*Here's the example:* (same mySprite as above, and already scaleX and scaleY
= 2)

mySprite is located at x:10, y:10
mySprite is scaled to 2, with an origin offset of x:10,. y:10.
multiply the origin offsets by the scale of the object and you get x:20,
y:20

the visual position of mySprite is at x:30, y:30

We can verify this by using getBounds again, but in relation to the stage.
mySprite.getBounds(stage);

returns:
x:30
y:30
width:100
height:100



So, an example to compensate for the offset and scale would go like this:
(if you want mySprite to *look* like its at 0,0 on the stage)

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;


Now, mySprite will appear to be at 0,0 on the stage, even though the origin
is offset and the scale has been changed.


*Solutions*

You can try compensation for both the origin and scale, or you can change
the way you scale, say by scaling the actual sin wave and not the containing
parent. You could also just redraw the wave instead of changing the scale.


Hope that helps.


the end code I used:

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill(0);
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);
mySprite.scaleX = mySprite.scaleY = 2;

var props:Rectangle = new Rectangle(mySprite.x, mySprite.y, mySprite.width,
mySprite.height);
trace(mySprite x,y,width,height:  + props);
trace(mySprite.getBounds(mySprite) =  + mySprite.getBounds(mySprite));
trace(mySprite.getBounds(stage) =  + mySprite.getBounds(stage));

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;



On Tue, Aug 2, 2011 at 1:03 AM, nasim h iranebah...@yahoo.com wrote:

 Hi

 Could u help me .  i draw wave( by code) inside empy movieClip that se
 regpoint (manualy)  at middle of that when i scale it t it’s good but
 when i move align x or y It scaled by pevios position  . I want to change
 reg point and refrence point
 too , like when i do

Re: [Flashcoders] Help Registration point and origion point

2011-08-03 Thread Glen Pike

Hello,

I did some stuff a long time ago with moving particles along a sine 
wave type path where you can control the frequency and amplitude.


Not sure if it will help much - the code is in (probably old bad) 
AS2, but you are welcome to look at it and borrow if it's any help.  You 
would need to update the position of a single particle as it moves 
along the waveform and draw a line from this to your previous point.


If you click and drag on the SWF vertical changes amplitude, 
horizontal changes frequency.  It's a good visual example of aliasing in 
action too - if you increase the frequency, the shape appears to cycle.


By the way, your frequency control on your scope appears to be 
backwards - turning anti-clockwise increases the frequency.


Hope this helps.

http://glenpike.co.uk/play/sinewave.html

Source: http://glenpike.co.uk/play/flash/sinewave.fla

Glen

On 03/08/2011 09:40, nasim h wrote:

Hi
I'm Really appreciate u
I want to simulate Osiloscope . Part of My program give me x,y and I shoudl 
draw wave base on that point in osiloscope  ,my osiloscope should have scalex 
and y i should can move to right and left up and down
I cant make it dynamically so i make 2 empty MovieClip nested in firt mc I draw 
my wave and move it left and Right and in parent I use scale but it has a bit 
bug  and my wave will be thiker after  scale
what do u do it and how to program it

this is my  problem can u help me
omethin like this not actually
http://d.violet.vn/uploads/resources/171/scope.swf
--- On Tue, 8/2/11, Ktuktu_fl...@cataclysmicrewind.com  wrote:

From: Ktuktu_fl...@cataclysmicrewind.com
Subject: Re: [Flashcoders] Help Registration point and origion point
To: Flash Coders Listflashcoders@chattyfig.figleaf.com
Date: Tuesday, August 2, 2011, 10:33 AM

Hopefully below will help you:

I'm going to just explain how the origin stuff works, and how you can learn
to compensate for it, and maybe you can apply this to your work. Starting
off with an example where the visual elements of a sprite are not originated
at 0,0

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill();
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);

*the stage thinks this:*
mySprite.x = 10;
mySprite.y = 10;
mySprite.width = 50;
mySprite.height = 50;

*mySprite thinks this:*
this.x = 10;
this.y = 10;
this.width = 50;
this.height = 50;

But what happened to the fact that the rectangle I drew lives at x:10, y:10
!!!


*So how do you find out where the origin is from inside mySprite?*
  - mySprite.getBounds(mySprite);

this will return the boundaries of mySprite, in relation to mySprite. The
visual reality of mySprite is that its boundaries are this:

x: 10
y: 10
width:50
height:50


your origin offset is x:10, y:10. This still doesn't account for the x and y
placement of mySprite on the stage, but that is simple to calculate.


*The next part, is compensating for the scale:
**
*If you take our mySprite from above, and scale it to 2, there are some
notable changes:
  - mySprite.scaleX = mySprite.scaleY = 2;

mySprite thinks:
x:10
y:10
width:100
height:100

mySprite.getBounds(mySprite) returns this:
x:10
y:10
width:50
height:50

The visual elements inside of mySprite did not grow, but mySprite is telling
it to grow (because of the scaleX| scaleY changes)

But what is probably messing you up is that when you scale an object that
has an origin offset, the distance between the origin offset is multiplied
by the same scale.

*Here's the example:* (same mySprite as above, and already scaleX and scaleY
= 2)

mySprite is located at x:10, y:10
mySprite is scaled to 2, with an origin offset of x:10,. y:10.
multiply the origin offsets by the scale of the object and you get x:20,
y:20

the visual position of mySprite is at x:30, y:30

We can verify this by using getBounds again, but in relation to the stage.
mySprite.getBounds(stage);

returns:
x:30
y:30
width:100
height:100



So, an example to compensate for the offset and scale would go like this:
(if you want mySprite to *look* like its at 0,0 on the stage)

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;


Now, mySprite will appear to be at 0,0 on the stage, even though the origin
is offset and the scale has been changed.


*Solutions*

You can try compensation for both the origin and scale, or you can change
the way you scale, say by scaling the actual sin wave and not the containing
parent. You could also just redraw the wave instead of changing the scale.


Hope that helps.


the end code I used:

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill(0);
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y

Re: [Flashcoders] Help Registration point and origion point

2011-08-02 Thread Ktu
Hopefully below will help you:

I'm going to just explain how the origin stuff works, and how you can learn
to compensate for it, and maybe you can apply this to your work. Starting
off with an example where the visual elements of a sprite are not originated
at 0,0

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill();
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);

*the stage thinks this:*
mySprite.x = 10;
mySprite.y = 10;
mySprite.width = 50;
mySprite.height = 50;

*mySprite thinks this:*
this.x = 10;
this.y = 10;
this.width = 50;
this.height = 50;

But what happened to the fact that the rectangle I drew lives at x:10, y:10
!!!


*So how do you find out where the origin is from inside mySprite?*
 - mySprite.getBounds(mySprite);

this will return the boundaries of mySprite, in relation to mySprite. The
visual reality of mySprite is that its boundaries are this:

x: 10
y: 10
width:50
height:50


your origin offset is x:10, y:10. This still doesn't account for the x and y
placement of mySprite on the stage, but that is simple to calculate.


*The next part, is compensating for the scale:
**
*If you take our mySprite from above, and scale it to 2, there are some
notable changes:
 - mySprite.scaleX = mySprite.scaleY = 2;

mySprite thinks:
x:10
y:10
width:100
height:100

mySprite.getBounds(mySprite) returns this:
x:10
y:10
width:50
height:50

The visual elements inside of mySprite did not grow, but mySprite is telling
it to grow (because of the scaleX | scaleY changes)

But what is probably messing you up is that when you scale an object that
has an origin offset, the distance between the origin offset is multiplied
by the same scale.

*Here's the example:* (same mySprite as above, and already scaleX and scaleY
= 2)

mySprite is located at x:10, y:10
mySprite is scaled to 2, with an origin offset of x:10,. y:10.
multiply the origin offsets by the scale of the object and you get x:20,
y:20

the visual position of mySprite is at x:30, y:30

We can verify this by using getBounds again, but in relation to the stage.
mySprite.getBounds(stage);

returns:
x:30
y:30
width:100
height:100



So, an example to compensate for the offset and scale would go like this:
(if you want mySprite to *look* like its at 0,0 on the stage)

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;


Now, mySprite will appear to be at 0,0 on the stage, even though the origin
is offset and the scale has been changed.


*Solutions*

You can try compensation for both the origin and scale, or you can change
the way you scale, say by scaling the actual sin wave and not the containing
parent. You could also just redraw the wave instead of changing the scale.


Hope that helps.


the end code I used:

var mySprite:Sprite = new Sprite ();
mySprite.graphics.beginFill(0);
mySprite.graphics.drawRect (10, 10, 50, 50);
mySprite.graphics.endFill();
mySprite.x = 10;
mySprite.y = 10;
stage.addChild(mySprite);
mySprite.scaleX = mySprite.scaleY = 2;

var props:Rectangle = new Rectangle(mySprite.x, mySprite.y, mySprite.width,
mySprite.height);
trace(mySprite x,y,width,height:  + props);
trace(mySprite.getBounds(mySprite) =  + mySprite.getBounds(mySprite));
trace(mySprite.getBounds(stage) =  + mySprite.getBounds(stage));

var myBounds:Rectangle = mySprite.getBounds(mySprite);
var originOffset:Point = new Point()
originOffset.x = -myBounds.x * mySprite.scaleX
originOffset.y = -myBounds.y * mySprite.scaleY;
mySprite.x = originOffset.x;
mySprite.y = originOffset.y;



On Tue, Aug 2, 2011 at 1:03 AM, nasim h iranebah...@yahoo.com wrote:

 Hi

 Could u help me .  i draw wave( by code) inside empy movieClip that se
 regpoint (manualy)  at middle of that when i scale it t it’s good but
 when i move align x or y It scaled by pevios position  . I want to change
 reg point and refrence point
 too , like when i do it manualy , the refrence point means (0,0) point ,
  how do i change that point plese help me
 what is diferent between reg point and origion point (cordinate system
 (0,0)) And how to change them ?
 ___
 Flashcoders mailing list
 Flashcoders@chattyfig.figleaf.com
 http://chattyfig.figleaf.com/mailman/listinfo/flashcoders




-- 
Ktu;

The information contained in this message may or may not be privileged
and/or confidential. If you are NOT the intended recipient, congratulations,
you got mail!
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders


[Flashcoders] Help Registration point and origion point

2011-08-01 Thread nasim hhhhh
Hi

Could u help me .  i draw wave( by code) inside empy movieClip that se 
regpoint (manualy)  at middle of that when i scale it t it’s good but 
when i move align x or y It scaled by pevios position  . I want to change reg 
point and refrence point 
too , like when i do it manualy , the refrence point means (0,0) point ,
 how do i change that point plese help me
what is diferent between reg point and origion point (cordinate system (0,0)) 
And how to change them ?
___
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders