Difference between revisions of "E-book comb.as"
m |
m |
||
| Line 1: | Line 1: | ||
| − | // Code for [[]] is licensed under [[[[1] (http://www.gnu.org/copyleft/lesser.html|LGPL)]]] margin = 50; | + | // Code for [[]] is licensed under [[[[1] (http://www.gnu.org/copyleft/lesser.html|LGPL)]]] |
| + | margin = 50; | ||
| − | // This initialises the book page lines createEmptyMovieClip("book",1); | + | // This initialises the book page lines |
| + | |||
| + | createEmptyMovieClip("book",1); | ||
createEmptyMovieClip("right_next",2); | createEmptyMovieClip("right_next",2); | ||
| − | right_next.createTextField('content',0,0,0,50,50); with (right_next.content) { autosize = 'left'; selectable = false; | + | right_next.createTextField('content',0,0,0,50,50); |
| + | with (right_next.content) { autosize = 'left'; | ||
| + | selectable = false; _ | ||
| + | quality = 'BEST'; border = false; | ||
| + | multiline = true; wordWrap = false; | ||
| + | html = true; | ||
| + | embedFonts = true; | ||
| + | htmlText = 'Hello right world!'; } | ||
createEmptyMovieClip("left_next",3); | createEmptyMovieClip("left_next",3); | ||
| − | left_next.createTextField('content',0,0,0,50,50); with (left_next.content) { autosize = 'left'; selectable = false; _quality = 'BEST'; border = false; multiline = true; wordWrap = false; html = true; embedFonts = true; htmlText = 'Hello left world!'; } | + | left_next.createTextField('content',0,0,0,50,50); |
| + | with (left_next.content) { | ||
| + | autosize = 'left'; | ||
| + | selectable = false; | ||
| + | _quality = 'BEST'; | ||
| + | border = false; | ||
| + | multiline = true; | ||
| + | wordWrap = false; | ||
| + | html = true; | ||
| + | embedFonts = true; | ||
| + | htmlText = 'Hello left world!'; } | ||
| + | |||
| + | // Draws page lines and fold line based on mouse position | ||
| − | + | function movepage() { | |
| − | + | w = (width-margin*2)/2; | |
| + | h = height-margin*2; | ||
| + | ox = margin+w; | ||
| + | oy = margin; | ||
| − | + | // Set mouse co-ords at top right edge | |
| + | |||
| + | x = width; | ||
| + | y = 0; | ||
| − | // | + | // One iteration per pixel width |
| + | for (i=0; i<600; i++) { | ||
| − | // 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; | + | // 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 line | + | // 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 = w; | ||
| − | + | if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; } | |
| + | else { | ||
| + | Qy = Zy+(w-Zx)*dx/dy; | ||
| + | if (Qy>h || Qy<0) { | ||
| + | a = Math.atan2(Qy-y,Qx-x); | ||
| + | if (Qy<0) a += Math.PI; | ||
| + | Qx = x+Math.cos(a)*h; | ||
| + | Qy = y+Math.sin(a)*h; | ||
| + | Rx = Qx+(Qy-h)/(y-Py)*(Px-x); | ||
| + | Ry = h; | ||
| + | } | ||
| + | else { Rx = Qx; Ry = Qy; } | ||
| + | if (Qy==0) Rx = w-Qx; | ||
| + | if (Rx<0) return; | ||
| + | } | ||
| − | // Draw | + | // Draw page |
| + | clear(); | ||
| + | lineStyle(3,0); | ||
| + | moveTo(ox,oy); | ||
| + | lineTo(ox,oy+h); | ||
| + | moveTo(ox-w,oy); | ||
| + | lineTo(ox+Px,oy+Py); | ||
| + | lineTo(ox+Rx,oy+Ry); | ||
| + | lineTo(ox+Rx,oy+h); | ||
| + | lineTo(ox-w,oy+h); | ||
| + | lineTo(ox-w,oy); | ||
| + | // Draw fold | ||
| + | beginFill(0xdddddd,100); | ||
| + | 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(); | ||
| + | } | ||
// orient right_next page _root.right_next._x = ox+x; _root.right_next._y = oy+y; _root.right_next._rotation = a*57.29578; | // orient right_next page _root.right_next._x = ox+x; _root.right_next._y = oy+y; _root.right_next._rotation = a*57.29578; | ||
Revision as of 00:09, 18 December 2006
// Code for [[]] is licensed under [[[[1] (http://www.gnu.org/copyleft/lesser.html%7CLGPL)]]] margin = 50;
// This initialises the book page lines
createEmptyMovieClip("book",1);
createEmptyMovieClip("right_next",2);
right_next.createTextField('content',0,0,0,50,50); with (right_next.content) { autosize = 'left'; selectable = false; _ quality = 'BEST'; border = false; multiline = true; wordWrap = false; html = true; embedFonts = true; htmlText = 'Hello right world!'; }
createEmptyMovieClip("left_next",3);
left_next.createTextField('content',0,0,0,50,50); with (left_next.content) { autosize = 'left'; selectable = false; _quality = 'BEST'; border = false; multiline = true; wordWrap = false; html = true; embedFonts = true; htmlText = 'Hello left world!'; }
// Draws page lines and fold line based on mouse position
function movepage() {
w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin;
// Set mouse co-ords at top right edge x = width; y = 0;
// One iteration per pixel width
for (i=0; i<600; i++) {
// 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 = w;
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; }
else {
Qy = Zy+(w-Zx)*dx/dy;
if (Qy>h || Qy<0) {
a = Math.atan2(Qy-y,Qx-x);
if (Qy<0) a += Math.PI;
Qx = x+Math.cos(a)*h;
Qy = y+Math.sin(a)*h;
Rx = Qx+(Qy-h)/(y-Py)*(Px-x);
Ry = h;
}
else { Rx = Qx; Ry = Qy; }
if (Qy==0) Rx = w-Qx;
if (Rx<0) return;
}
// Draw page clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy+h); moveTo(ox-w,oy); lineTo(ox+Px,oy+Py); lineTo(ox+Rx,oy+Ry); lineTo(ox+Rx,oy+h); lineTo(ox-w,oy+h); lineTo(ox-w,oy);
// Draw fold beginFill(0xdddddd,100); 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();
} // orient right_next page _root.right_next._x = ox+x; _root.right_next._y = oy+y; _root.right_next._rotation = a*57.29578;
}
function bottomRight() {
w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin+h; //reverses y
// Get mouse coords relative to book middle, reverses y co-ords x = _xmouse-ox; y = oy-_ymouse;
// 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 = w;
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; } else { Qy = Zy+(w-Zx)*dx/dy; if (Qy>h || Qy<0) { a = Math.atan2(Qy-y,Qx-x); if (Qy<0) a += Math.PI; Qx = x+Math.cos(a)*h; Qy = y+Math.sin(a)*h; Rx = Qx+(Qy-h)/(y-Py)*(Px-x); Ry = h; } else { Rx = Qx; Ry = Qy; } if (Qy==0) Rx = w-Qx; if (Rx<0) return; }
// Draw page, reverses draw clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy-h); moveTo(ox-w,oy); lineTo(ox+Px,oy-Py); lineTo(ox+Rx,oy-Ry); lineTo(ox+Rx,oy-h); lineTo(ox-w,oy-h); lineTo(ox-w,oy);
// Draw fold beginFill(0xdddddd,100); 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();
// orient right_next page _root.right_next._x = ox+x; _root.right_next._y = oy-y; _root.right_next._rotation = a*57.29578;
}
function topLeft() {
w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin;
// Get mouse coords relative to book middle, reverse ox x = ox-_xmouse; y = _ymouse-oy;
// 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 = w;
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; } else { Qy = Zy+(w-Zx)*dx/dy; if (Qy>h || Qy<0) { a = Math.atan2(Qy-y,Qx-x); if (Qy<0) a += Math.PI; Qx = x+Math.cos(a)*h; Qy = y+Math.sin(a)*h; Rx = Qx+(Qy-h)/(y-Py)*(Px-x); Ry = h; } else { Rx = Qx; Ry = Qy; } if (Qy==0) Rx = w-Qx; if (Rx<0) return; }
// Draw page clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy+h); moveTo(ox+w,oy); lineTo(ox-Px,oy+Py); lineTo(ox-Rx,oy+Ry); lineTo(ox-Rx,oy+h); lineTo(ox+w,oy+h); lineTo(ox+w,oy);
// Draw fold beginFill(0xdddddd,100); 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();
// orient right_next page _root.left_next._x = ox-x; _root.left_next._y = oy+y; _root.left_next._rotation = -a*57.29578;
}
function bottomLeft() {
w = (width-margin*2)/2; h = height-margin*2; ox = margin+w; oy = margin+h; //reverses y
// Get mouse coords relative to book middle, reverses y co-ords x = ox-_xmouse; y = oy-_ymouse;
// 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 = w;
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; } else { Qy = Zy+(w-Zx)*dx/dy; if (Qy>h || Qy<0) { a = Math.atan2(Qy-y,Qx-x); if (Qy<0) a += Math.PI; Qx = x+Math.cos(a)*h; Qy = y+Math.sin(a)*h; Rx = Qx+(Qy-h)/(y-Py)*(Px-x); Ry = h; } else { Rx = Qx; Ry = Qy; } if (Qy==0) Rx = w-Qx; if (Rx<0) return; }
// Draw page, reverses draw clear(); lineStyle(3,0); moveTo(ox,oy); lineTo(ox,oy-h); moveTo(ox+w,oy); lineTo(ox-Px,oy-Py); lineTo(ox-Rx,oy-Ry); lineTo(ox-Rx,oy-h); lineTo(ox+w,oy-h); lineTo(ox+w,oy);
// Draw fold beginFill(0xdddddd,100); 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();
// orient left_next page _root.left_next._x = ox-x; _root.left_next._y = oy-y; _root.left_next._rotation = -a*57.29578; }
var mouseListener = new Object();
mouseListener.onMouseMove = corner;
function corner() {
if (_xmouse <= 200 && _ymouse <= 100) book.onMouseMove= topLeft; else if (_xmouse <= 200 && _ymouse >= 300) book.onMouseMove= bottomLeft; else if (_xmouse >= 400 && _ymouse <= 100) book.onMouseMove= topRight; else if (_xmouse >= 400 && _ymouse >= 300) book.onMouseMove= bottomRight; }
Mouse.addListener(mouseListener);



