Difference between revisions of "Bookclick.as"

From Organic Design wiki
(Constrained the asymptote, but what became of the html text?)
m
Line 1: Line 1:
// Code for [[[[SWF e-book]]]] is liscenced under [[[[http://www.gnu.org/copyleft/lesser.html|LGPL]]]]
+
// Code for SWF e-book is liscenced under LGPL
 
margin = Stage.height/8;
 
margin = Stage.height/8;
 
w = (Stage.width-margin*2)/2;
 
w = (Stage.width-margin*2)/2;
Line 15: Line 15:
 
right_next.createTextField('content',0,0,0,50,50);
 
right_next.createTextField('content',0,0,0,50,50);
 
with (right_next.content) {
 
with (right_next.content) {
autosize = 'left';
+
    autosize = 'left';
selectable = false;
+
    selectable = false;
_quality = 'BEST';
+
    _quality = 'BEST';
border = false;
+
    border = false;
multiline = true;
+
    multiline = true;
wordWrap = false;
+
    wordWrap = false;
html = true;
+
    html = true;
embedFonts = true;
+
    embedFonts = true;
htmlText = '<font color="#ff0000">Hello right world!</font>';
+
    htmlText = '<font color="#ff0000">Hello right world!</font>';
}
+
    }
  
 
// Draws page lines and fold line based on mouse position
 
// Draws page lines and fold line based on mouse position
  
 
function topRight(i) {
 
function topRight(i) {
x= _xmouse-ox;
+
    x= _xmouse-ox;
y= _ymouse-oy;
+
    y= _ymouse-oy;
if (i) {
+
    if (i) {
x = i-ox;
+
        x = i-ox;
if (y >margin/2) y = margin/2;
+
        if (y <0) y = 0;
if (x <= -Stage.width){
+
        if (x <= -w*2) y = 0;
y=0;
+
if (y >margin) y = margin;
}
+
    }
}
+
 
+
    // constrain mouse to radius W
// constrain mouse to radius W
+
    a = Math.atan2(y,x);
a = Math.atan2(y,x);
+
    r = Math.sqrt(x*x+y*y);
r = Math.sqrt(x*x+y*y);
+
    if (r>w) r=w;
if (r>w) r=w;
+
    x = Math.cos(a)*r;
x = Math.cos(a)*r;
+
    y = Math.sin(a)*r;
y = Math.sin(a)*r;
 
  
// Calculate point Z and dy,dx of line C
+
    // Calculate point Z and dy,dx of line C
dx = w-x;
+
    dx = w-x;
dy = y;
+
    dy = y;
Zx = x+dx/2;
+
    Zx = x+dx/2;
Zy = y-dy/2;
+
    Zy = y-dy/2;
  
// Calculate line D
+
    // Calculate line D
Px = Zx-Zy*dy/dx;
+
    Px = Zx-Zy*dy/dx;
Py = 0;
+
    Py = 0;
Qx = w;
+
    Qx = w;
  
if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; }
+
    if (dy*dy<1) { a = 0; Qx = x; Qy = Ry = h; Rx = (x+w)/2; }
else {
+
    else {
Qy = Zy+(w-Zx)*dx/dy;
+
        Qy = Zy+(w-Zx)*dx/dy;
if (Qy>h || Qy<0) {
+
        if (Qy>h || Qy<0) {
a = Math.atan2(Qy-y,Qx-x);
+
            a = Math.atan2(Qy-y,Qx-x);
if (Qy<0) a += Math.PI;
+
            if (Qy<0) a += Math.PI;
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)/(y-Py)*(Px-x);
+
            Rx = Qx+(Qy-h)/(y-Py)*(Px-x);
Ry = h;
+
            Ry = h;
}
+
            }
else { Rx = Qx; Ry = Qy; }
+
        else { Rx = Qx; Ry = Qy; }
if (Qy==0) Rx = w-Qx;
+
        if (Qy==0) Rx = w-Qx;
if (Rx<0) return;
+
        if (Rx<0) return;
}
+
        }
  
// Draw page
+
    // Draw page
clear();
+
    clear();
lineStyle(1,0);
+
    lineStyle(1,0);
moveTo(ox,oy);
+
    moveTo(ox,oy);
lineTo(ox,oy+h);
+
    lineTo(ox,oy+h);
moveTo(ox-w,oy);
+
    moveTo(ox-w,oy);
lineTo(ox+Px,oy+Py);
+
    lineTo(ox+Px,oy+Py);
lineTo(ox+Rx,oy+Ry);
+
    lineTo(ox+Rx,oy+Ry);
lineTo(ox+Rx,oy+h);
+
    lineTo(ox+Rx,oy+h);
lineTo(ox-w,oy+h);
+
    lineTo(ox-w,oy+h);
lineTo(ox-w,oy);
+
    lineTo(ox-w,oy);
  
// Draw fold
+
    // Draw fold
beginFill(0xeeeeee,100);
+
    beginFill(0xeeeeee,100);
moveTo(ox+x,oy+y);
+
    moveTo(ox+x,oy+y);
lineTo(ox+Px,oy);
+
    lineTo(ox+Px,oy);
lineTo(ox+Rx,oy+Ry);
+
    lineTo(ox+Rx,oy+Ry);
lineTo(ox+Qx,oy+Qy);
+
    lineTo(ox+Qx,oy+Qy);
lineTo(ox+x,oy+y);
+
    lineTo(ox+x,oy+y);
endFill();
+
    endFill();
  
// orient right_next page
+
    // orient right_next page
_root.right_next._x = x;
+
    _root.right_next._x = x;
_root.right_next._y = y;
+
    _root.right_next._y = y;
_root.right_next._rotation = a*57.29578;
+
    _root.right_next._rotation = a*57.29578;
 
}
 
}
+
 
 
function reduce() {
 
function reduce() {
if (i) topRight (i-=speed);
+
    if (i) topRight (i-=speed);
}
+
    }
  
 
var mouseListener = new Object();
 
var mouseListener = new Object();
  
 
mouseListener.onMouseMove = function(){
 
mouseListener.onMouseMove = function(){
book.onMouseMove = topRight();
+
    book.onMouseMove = topRight();
 
};
 
};
 
mouseListener.onMouseUp = function(){
 
mouseListener.onMouseUp = function(){
i=Stage.width-margin;
+
    i=Stage.width-margin;
 +
 
 
};
 
};
  
 
Mouse.addListener(mouseListener);
 
Mouse.addListener(mouseListener);

Revision as of 05:56, 20 December 2006

// Code for SWF e-book is liscenced under LGPL margin = Stage.height/8; w = (Stage.width-margin*2)/2; h = Stage.height-margin*2; ox = margin+w; oy = margin; i = 0; speed = 4;

// 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!';
   }

// Draws page lines and fold line based on mouse position

function topRight(i) {

   x= _xmouse-ox;
   y= _ymouse-oy;
   if (i) {
       x = i-ox;
       if (y <0) y = 0;
       if (x <= -w*2) 	y = 0;

if (y >margin) y = 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 = 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(1,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(0xeeeeee,100);
   moveTo(ox+x,oy+y);
   lineTo(ox+Px,oy);
   lineTo(ox+Rx,oy+Ry);
   lineTo(ox+Qx,oy+Qy);
   lineTo(ox+x,oy+y);
   endFill();
   // orient right_next page
   _root.right_next._x = x;
   _root.right_next._y = y;
   _root.right_next._rotation = a*57.29578;

}

function reduce() {

   if (i) topRight (i-=speed);
   }

var mouseListener = new Object();

mouseListener.onMouseMove = function(){

   book.onMouseMove = topRight();

}; mouseListener.onMouseUp = function(){

   i=Stage.width-margin;

};

Mouse.addListener(mouseListener);