Difference between revisions of "SWF e-book.as"

From Organic Design wiki
m
m
Line 41: Line 41:
 
clear();
 
clear();
 
lineStyle(3,0);
 
lineStyle(3,0);
beginFill(0xffffff,100);
+
beginFill(0xffff80,100);
 
moveTo(ox-w,oy);
 
moveTo(ox-w,oy);
 
lineTo(ox+Px,oy+Py);
 
lineTo(ox+Px,oy+Py);

Revision as of 03:25, 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) Qx = w-(Qy-h)/dx*dy;

// Draw page clear(); lineStyle(3,0); beginFill(0xffff80,100); moveTo(ox-w,oy); lineTo(ox+Px,oy+Py); lineTo(ox+Qx,oy+Qy); 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();

};