Difference between revisions of "Bookclick.as"
m |
(mousedown added, calculate function reintegrated) |
||
Line 6: | Line 6: | ||
createEmptyMovieClip("book",1); | createEmptyMovieClip("book",1); | ||
− | createEmptyMovieClip("right_next",2); | + | /*createEmptyMovieClip("right_next",2); |
//backing page | //backing page | ||
right_next.createTextField('content',0,0,0,50,50); | right_next.createTextField('content',0,0,0,50,50); | ||
Line 19: | Line 19: | ||
embedFonts = true; | embedFonts = true; | ||
htmlText = '<font color="#ff0000">Hello right world!</font>'; | htmlText = '<font color="#ff0000">Hello right world!</font>'; | ||
− | } | + | }*/ |
− | |||
// constrain mouse to radius W | // constrain mouse to radius W | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
Line 70: | Line 40: | ||
x= _xmouse-ox; | x= _xmouse-ox; | ||
y= _ymouse-oy; | y= _ymouse-oy; | ||
− | x=x* | + | x=x*Tx; |
if (Ty == 1) { | if (Ty == 1) { | ||
oy = margin + h; | oy = margin + h; | ||
Line 81: | Line 51: | ||
if (i < -98) return; | if (i < -98) return; | ||
x = (i-ox); | x = (i-ox); | ||
− | x = x* | + | x = x*Tx; |
− | |||
− | |||
− | |||
− | |||
if (Ty == -1) { | if (Ty == -1) { | ||
y= _ymouse; | y= _ymouse; | ||
Line 97: | Line 63: | ||
} | } | ||
//calculate fold | //calculate fold | ||
− | + | 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; | ||
+ | } | ||
//adjust draw for mouse position | //adjust draw for mouse position | ||
− | w = w* | + | w = w*Tx; |
− | x=x* | + | x=x*Tx; |
− | Px=Px* | + | Px=Px*Tx; |
− | Rx=Rx* | + | Rx=Rx*Tx; |
− | Qx=Qx* | + | Qx=Qx*Tx; |
− | h= h* | + | h= h*Ty; |
− | y = y* | + | y = y*Ty; |
− | Py = Py* | + | Py = Py*Ty; |
− | Ry = Ry* | + | Ry = Ry*Ty; |
− | Qy = Qy* | + | Qy = Qy*Ty; |
//draw lines | //draw lines | ||
clear(); | clear(); | ||
Line 136: | Line 131: | ||
// for multiple parameters in main function | // for multiple parameters in main function | ||
var coords = new Object(); | var coords = new Object(); | ||
− | Tx = coords. | + | Tx = coords.j = 0; |
− | Ty = coords. | + | Ty = coords.k = 0; |
var mouseListener = new Object(); | var mouseListener = new Object(); | ||
mouseListener.onMouseMove = function(){ | mouseListener.onMouseMove = function(){ | ||
if (_xmouse >=305) { | if (_xmouse >=305) { | ||
− | coords. | + | coords.j = 1; |
} | } | ||
if (_xmouse < 305) { | if (_xmouse < 305) { | ||
− | coords. | + | coords.j = -1; |
} | } | ||
− | if (_ymouse <= 200) coords. | + | if (_ymouse <= 200) coords.k = -1; |
− | if (_ymouse > 200) coords. | + | if (_ymouse > 200) coords.k = 1; |
− | Tx = coords. | + | Tx = coords.j; |
− | Ty = coords. | + | Ty = coords.k; |
pageTurn(0,Tx,Ty); | pageTurn(0,Tx,Ty); | ||
+ | }; | ||
+ | |||
+ | mouseListener.onMouseDown = function(){ | ||
+ | if (_xmouse >=305) { | ||
+ | coords.j = 1; | ||
+ | } | ||
+ | if (_xmouse < 305) { | ||
+ | coords.j = -1; | ||
+ | } | ||
+ | //if (_ymouse <= 150) coords.bar = -1; | ||
+ | //if (_ymouse > 150 && _ymouse <= 250) coords.bar = 0; | ||
+ | //if (_ymouse > 250) coords.bar = 1; | ||
+ | if (_ymouse <= 200) coords.k = -1; | ||
+ | if (_ymouse > 200) coords.k = 1; | ||
+ | Tx = coords.j; | ||
+ | Ty = coords.k; | ||
}; | }; | ||
mouseListener.onMouseUp = function(){ | mouseListener.onMouseUp = function(){ | ||
if (_xmouse >=305) { | if (_xmouse >=305) { | ||
− | |||
i=559; | i=559; | ||
} | } | ||
if (_xmouse < 305) { | if (_xmouse < 305) { | ||
− | |||
i=50; | i=50; | ||
speed = -speed; | speed = -speed; | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}; | }; | ||
Mouse.addListener(mouseListener); | Mouse.addListener(mouseListener); |
Revision as of 20:46, 24 December 2006
// Compile and run in [[Bookclick]] margin = 50; i = 0; speed = 8; //main clip createEmptyMovieClip("book",1);
/*createEmptyMovieClip("right_next",2); //backing page 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!'; }*/
// constrain mouse to radius W
// main function takes three parameters (an iterator and x and y mouse)
function pageTurn(i,Tx,Ty) {
w = (Stage.width-margin*2)/2; h = Stage.height-margin*2; ox = margin+w; oy = margin; //these need to change sign later j = Tx; k = Ty; //mousemove if (!i) { x= _xmouse-ox; y= _ymouse-oy; x=x*Tx; if (Ty == 1) { oy = margin + h; y= oy-_ymouse; } } //onclick if (i) { if (i > 706) return; if (i < -98) return; x = (i-ox); x = x*Tx; if (Ty == -1) { y= _ymouse; if (x <= -400) y = 0; } if (Ty == 1) { oy = margin + h; y= oy-_ymouse; if (x <= -400) y = 0; } } //calculate fold 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; } //adjust draw for mouse position w = w*Tx; x=x*Tx; Px=Px*Tx; Rx=Rx*Tx; Qx=Qx*Tx; h= h*Ty; y = y*Ty; Py = Py*Ty; Ry = Ry*Ty; Qy = Qy*Ty; //draw lines 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();
} //iterates over frames function reduce() {
if (i) pageTurn(i-=speed,Tx,Ty);
} // for multiple parameters in main function var coords = new Object(); Tx = coords.j = 0; Ty = coords.k = 0; var mouseListener = new Object();
mouseListener.onMouseMove = function(){ if (_xmouse >=305) { coords.j = 1; } if (_xmouse < 305) { coords.j = -1; } if (_ymouse <= 200) coords.k = -1; if (_ymouse > 200) coords.k = 1;
Tx = coords.j; Ty = coords.k; pageTurn(0,Tx,Ty); };
mouseListener.onMouseDown = function(){
if (_xmouse >=305) {
coords.j = 1; }
if (_xmouse < 305) {
coords.j = -1; } //if (_ymouse <= 150) coords.bar = -1; //if (_ymouse > 150 && _ymouse <= 250) coords.bar = 0; //if (_ymouse > 250) coords.bar = 1; if (_ymouse <= 200) coords.k = -1; if (_ymouse > 200) coords.k = 1; Tx = coords.j; Ty = coords.k; };
mouseListener.onMouseUp = function(){
if (_xmouse >=305) {
i=559; }
if (_xmouse < 305) {
i=50; speed = -speed; } };
Mouse.addListener(mouseListener);