Difference between revisions of "SWF e-book.as"
m |
m |
||
| Line 36: | Line 36: | ||
Qy = Ry = Zy+(w-Zx)*dx/dy; | Qy = Ry = Zy+(w-Zx)*dx/dy; | ||
| − | if (Qy>h) | + | if (Qy>h) { |
| + | a = Math.atan2(Qy-y,Qx-x); | ||
| + | Qx = x+Math.cos(a)*h; | ||
| + | Qy = y+Math.sin(a)*h; | ||
| + | } | ||
// Draw page | // Draw page | ||
clear(); | clear(); | ||
lineStyle(3,0); | lineStyle(3,0); | ||
| − | + | beginFill(0xff,100); | |
moveTo(ox-w,oy); | moveTo(ox-w,oy); | ||
lineTo(ox+w,oy); | lineTo(ox+w,oy); | ||
| Line 47: | Line 51: | ||
lineTo(ox-w,oy+h); | lineTo(ox-w,oy+h); | ||
lineTo(ox-w,oy); | lineTo(ox-w,oy); | ||
| − | + | endFill(); | |
moveTo(ox,oy); | moveTo(ox,oy); | ||
lineTo(ox,oy+h); | lineTo(ox,oy+h); | ||
Revision as of 03:36, 22 November 2006
// Code for [[SWF e-book]] margin = 50;
// This initialises the book page lines createEmptyMovieClip("book",1);
// Draws page lines and folde line based on mouse position book.onMouseMove = function() {
w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin;
// Get mouse coords relative to book middle x = _xmouse-margin-w; y = _ymouse-margin;
// constrain mouse to radius W a = Math.atan2(y,x); r = Math.sqrt(x*x+y*y); if (r>w) r=w; x = Math.cos(a)*r; y = Math.sin(a)*r;
// Calculate point Z and dy,dx of line C dx = w-x; dy = y; Zx = x+dx/2; Zy = y-dy/2;
// Calculate line D Px = Zx-Zy*dy/dx; Py = 0; Qx = Rx = w; Qy = Ry = Zy+(w-Zx)*dx/dy;
if (Qy>h) { a = Math.atan2(Qy-y,Qx-x); Qx = x+Math.cos(a)*h; Qy = y+Math.sin(a)*h; }
// Draw page clear(); lineStyle(3,0); beginFill(0xff,100); moveTo(ox-w,oy); lineTo(ox+w,oy); lineTo(ox+w,oy+h); lineTo(ox-w,oy+h); lineTo(ox-w,oy); endFill(); moveTo(ox,oy); lineTo(ox,oy+h);
// Draw fold beginFill(0xdddddd,100); moveTo(ox+x,oy+y); lineTo(ox+Px,oy+Py); lineTo(ox+Qx,oy+Qy); lineTo(ox+x,oy+y); endFill();
};



