Difference between revisions of "SWF e-book.as"
m |
m |
||
| Line 40: | Line 40: | ||
Qx = x+Math.cos(a)*h; | Qx = x+Math.cos(a)*h; | ||
Qy = y+Math.sin(a)*h; | Qy = y+Math.sin(a)*h; | ||
| − | Rx = Qx+(Qy-h)/dy | + | Rx = Qx+(Qy-h)/dx*dy; |
Ry = h; | Ry = h; | ||
} | } | ||
Revision as of 03:49, 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; Rx = Qx+(Qy-h)/dx*dy; Ry = 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();
// Draw fold beginFill(0xdddddd,100); moveTo(ox,oy); lineTo(ox,oy+h); moveTo(ox+x,oy+y); lineTo(ox+Px,oy+Py); lineTo(ox+Rx,oy+Ry); lineTo(ox+Qx,oy+Qy); lineTo(ox+x,oy+y); endFill();
};



