My favorites
▼
|
Sign in
bezier
Bezier and Line classes: intersections and other basic methods
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
bezier
/
src
/
howtodo
/
Step08Bounce.as
‹r145
r181
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
package howtodo {
import flash.events.Event;
import flash.geom.Bezier;
import flash.geom.Intersection;
import flash.geom.Line;
import flash.geom.Point;
import flash.geom.Rectangle;
import howtodo.view.DragPoint;
public class Step08Bounce extends BezierUsage {
private static const DESCRIPTION:String = "<B>Bounce: detect intersection (not finished methods)</B><BR/><BR/>drag control points";
private const ball:DragPoint = new DragPoint();
private const stageRectangle:Rectangle = new Rectangle();
private const stepLine:Line = new Line();
private var speedX:Number=0;
private var speedY:Number=0;
/**
* Нахождение пересечения и отскока.<BR/>
* @example
* <table width="100%" border=1><td>
* <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
* id="Step1Building" width="100%" height="500"
* codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
* <param name="movie" value="../images/Step08Bounce.swf" />
* <param name="quality" value="high" />
* <param name="bgcolor" value="#FFFFFF" />
* <param name="allowScriptAccess" value="sameDomain" />
* <embed src="../images/Step08Bounce.swf" quality="high" bgcolor="#FFFFFF"
* width="100%" height="400" name="Step1Building"
* align="middle"
* play="true"
* loop="false"
* quality="high"
* allowScriptAccess="sameDomain"
* type="application/x-shockwave-flash"
* pluginspage="http://www.adobe.com/go/getflashplayer">
* </embed>
* </object>
* </td></table>
* <BR/>
**/
public function Step08Bounce () {
super();
}
override protected function init():void {
super.init();
initDescription(DESCRIPTION);
addChild(ball);
ball.x = -1;
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
addEventListener(Event.RESIZE, onResize);
start.x = 100;
start.y = 100;
control.x = 500;
control.y = 300;
end.x = 700;
end.y = 700;
bezier.isSegment = true;
stepLine.isSegment = true;
onResize();
redraw();
}
protected function onResize(event:Event=null):void {
stageRectangle.width = stage.stageWidth;
stageRectangle.height = stage.stageHeight;
}
protected function enterFrameHandler(event:Event):void {
if (stageRectangle.containsPoint(ball.point)) {
moveBall();
} else {
initBallMotion();
}
}
private function initBallMotion ():void {
ball.x = 1;
ball.y = stageRectangle.height-1;
speedX = 3; // Math.random()+10;
speedY =-3; //Math.random()-11;
}
private function moveBall():void {
stepLine.start = ball.position;
ball.x+=speedX;
ball.y+=speedY;
stepLine.end = ball.position;
var intersection:Intersection = bezier.intersectionLine(stepLine);
if ((intersection)&&(intersection.currentTimes.length > 0))
{
// trace(intersection.currentTimes, intersection.oppositeTimes);
var time:Number = intersection.currentTimes[0];
var fulcrum:Point = bezier.getPoint(time);
var tangentAngle:Number = bezier.getTangentAngle(time);
var angleDist:Number = (tangentAngle-stepLine.angle)%Math.PI;
graphics.lineStyle(0, 0x0000FF, 1);
drawLine(stepLine);
stepLine.angleOffset(angleDist*2, fulcrum);
graphics.lineStyle(0, 0x00FF00, 1) ;
drawLine(stepLine);
speedX=stepLine.end.x - stepLine.start.x;
speedY=stepLine.end.y - stepLine.start.y;
ball.x = stepLine.end.x;
ball.y = stepLine.end.y;
}
}
override protected function onPointMoved(event:Event=null):void {
redraw();
}
private function redraw ():void {
graphics.clear();
graphics.lineStyle(0, 0xFF0000, 1);
drawBezier(bezier);
graphics.lineStyle(0, 0xFF0000, .3);
drawRectangle(bezier.bounds);
drawRectangle(stepLine.bounds);
}
}
}
Show details
Hide details
Change log
r150
by a.sergeyev on Apr 7, 2010
Diff
[No log message]
Go to:
.../bezier/src/flash/geom/Bezier.as
...nk/bezier/src/flash/geom/Line.as
...c/howtodo/Step06PointOnBezier.as
...rc/howtodo/Step07PointOnCurve.as
...zier/src/howtodo/Step08Bounce.as
.../src/howtodo/Step09DashedLine.as
...todo/Step12GeometryProperties.as
Hide comments
Show comments
Sign in
to write a code review
Older revisions
r145
by a.sergeyev on Apr 4, 2010
Diff
[No log message]
r127
by ivan.dembicki on Jun 5, 2008
Diff
[No log message]
r123
by ivan.dembicki on Jun 5, 2008
Diff
[No log message]
All revisions of this file
File info
Size: 4087 bytes, 149 lines
View raw file
Powered by
Google Project Hosting