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

From Organic Design wiki
(right intersection)
(legacy)
 
(79 intermediate revisions by 2 users not shown)
Line 1: Line 1:
margin = 20;
+
{{legacy}}
 +
<as>
 +
// Code for [[[[SWF e-book]]]] is licensed under [[[[http://www.gnu.org/copyleft/lesser.html|LGPL]]]]
 +
#include "debug.as"
 +
margin = 50;
  
// bg defines the hitArea which raises mouse events
+
// This initialises the book page lines
// - this is used so that the book symbol doesn't need to have a filled background
+
createEmptyMovieClip("book",1);
createEmptyMovieClip("bg",1);
+
 
bg._visible = false;
+
createEmptyMovieClip("right_next",2);
bg.beginFill(0,100);
 
bg.moveTo(margin,margin);
 
bg.lineTo(width-margin,margin);
 
bg.lineTo(width-margin,height-margin);
 
bg.lineTo(margin,height-margin);
 
bg.lineTo(margin,margin);
 
bg.endFill();
 
  
// This initialises the book page lines
+
right_next.createTextField('content',100,0,0,50,50);
createEmptyMovieClip("book",2);
+
with (right_next.content) {
book.hitArea = bg;
+
autosize = 'left';
book.lineStyle(3,0);
+
selectable = false;
book.moveTo(margin,margin);
+
_quality = 'BEST';
book.lineTo(width-margin,margin);
+
border = false;
book.lineTo(width-margin,height-margin);
+
multiline = true;
book.lineTo(margin,height-margin);
+
wordWrap = false;
book.lineTo(margin,margin);
+
html = true;
book.moveTo(width/2,margin);
+
embedFonts = true;
book.lineTo(width/2,height-margin);
+
htmlText = '<font color="#ff0000">Hello world!</font>';
 +
}
  
 
// Draws page lines and folde line based on mouse position
 
// Draws page lines and folde line based on mouse position
book.onPress = function() {
+
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 = w;
 +
 
 +
if (dx<=0 && dy<1) { Qx = Rx = w; Qy = Ry = 0; }
 +
if (dy*dy<20) { a = 0; Qx = x>w ? w : x; Qy = Ry = h; Rx = (Qx+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();
 
clear();
 
lineStyle(3,0);
 
lineStyle(3,0);
moveTo(margin,margin);
+
moveTo(ox,oy);
lineTo(width-margin,margin);
+
lineTo(ox,oy+h);
lineTo(width-margin,height-margin);
+
moveTo(ox-w,oy);
lineTo(margin,height-margin);
+
lineTo(ox+Px,oy+Py);
lineTo(margin,margin);
+
lineTo(ox+Rx,oy+Ry);
moveTo(width/2,margin);
+
lineTo(ox+Rx,oy+h);
lineTo(width/2,height-margin);
+
lineTo(ox-w,oy+h);
 +
lineTo(ox-w,oy);
  
// Calculate point Z and dy,dx of line C
+
// Draw fold
dx = width-margin-_xmouse;
+
beginFill(0xdddddd,100);
dy = _ymouse-margin;
+
moveTo(ox+x,oy+y);
Zx = _xmouse+dx/2;
+
lineTo(ox+Px,oy+Py);
Zy = _ymouse-dy/2;
+
lineTo(ox+Rx,oy+Ry);
 +
lineTo(ox+Qx,oy+Qy);
 +
lineTo(ox+x,oy+y);
 +
endFill();
 +
 
 +
//echo("Px,Py:"+Px.toString()+","+Py.toString()+" Qx,Qy:"+Qx.toString()+","+Qy.toString()+" Rx,Ry:"+Rx.toString()+","+Ry.toString());
 +
//echo("x,y:"+x.toString()+","+y.toString()+" dx,dy:"+dx.toString()+","+dy.toString());
 +
 
 +
// orient right_next page
 +
_root.right_next._x = ox+x;
 +
_root.right_next._y = oy+y;
 +
_root.right_next._rotation = a*57.29578;
  
// Draw line D
 
moveTo(Zx-(Zy-margin)*dy/dx,margin);
 
lineTo(width-margin,Zy+(width-margin-Zx)*dy/dx);
 
 
};
 
};
 +
</as>
 +
[[Category:ActionScript]]

Latest revision as of 23:44, 24 September 2013

Legacy.svg Legacy: This article describes a concept that has been superseded in the course of ongoing development on the Organic Design wiki. Please do not develop this any further or base work on this concept, now this page is for historic record only.

<as> // Code for [[SWF e-book]] is licensed under [[[[1]]]]

  1. include "debug.as"

margin = 50;

// This initialises the book page lines createEmptyMovieClip("book",1);

createEmptyMovieClip("right_next",2);

right_next.createTextField('content',100,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 world!'; }

// 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 = w;

if (dx<=0 && dy<1) { Qx = Rx = w; Qy = Ry = 0; } if (dy*dy<20) { a = 0; Qx = x>w ? w : x; Qy = Ry = h; Rx = (Qx+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();

//echo("Px,Py:"+Px.toString()+","+Py.toString()+" Qx,Qy:"+Qx.toString()+","+Qy.toString()+" Rx,Ry:"+Rx.toString()+","+Ry.toString()); //echo("x,y:"+x.toString()+","+y.toString()+" dx,dy:"+dx.toString()+","+dy.toString());

// orient right_next page _root.right_next._x = ox+x; _root.right_next._y = oy+y; _root.right_next._rotation = a*57.29578;

}; </as>