MovieClip.prototype.newCurve = function(x1, y1, x2, y2, x3, y3) {
var nx = 2*x2-0.5*(x1+x3);
var ny = 2*y2-0.5*(y1+y3);
this.curveTo(nx, ny, x3, y3);
};
MovieClip.prototype.drawCircle = function(c, wd, hg) {
var mas = new Array();
var angle = 360/c;
for (var i = 0; i<=c; i++) {
mas[i] = new Object();
mas[i].x = Math.cos(angle*(Math.PI/180)*i)*wd;
mas[i].y = Math.sin(angle*(Math.PI/180)*i)*hg;
}
this.moveTo(mas[0].x, mas[0].y);
for (var i = 0; i<c; i += 2) {
this.newCurve(mas[i].x, mas[i].y, mas[i+1].x, mas[i+1].y, mas[i+2].x, mas[i+2].y);
}
};
vertex = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
vertex.prototype.rotateXY = function(sinX, cosX, sinY, cosY) {
//rotation around of axes X and Y
var yp = this.y*cosY-this.z*sinY;
var zp = this.y*sinY+this.z*cosY;
var xp = this.x*cosX+zp*sinX;
var zp = -this.x*sinX+zp*cosX;
this.x = xp;
this.y = yp;
this.z = zp;
};
vertex.prototype.perspective = function() {
//calculation 3d to 2d
var perRatio = 1/(this.z/dist+1);
this.rx = cnx+this.x*perRatio;
this.ry = cny+this.y*perRatio;
};
_root.onLoad = function() {
cnx = 250;
cny = 250;
dist = 200;
rad = Math.PI/180;
amount = 33;
v = new Array();
radius = 100;
step = 4;
next = 0;
c = 0;
createEmptyMovieClip("dot", 100);
dot.lineStyle(0, 0xFFFFFF, 100);
dot.beginFill(0x000000, 100);
dot.drawCircle(16, 15, 15);
dot.endFill();
// build sphere
while (next<=step) {
next++;
angstp = 180/(step+1);
while (c<=((amount-2)*next)/step) {
if (c>amount) {
break;
}
ang += 360/(((amount-2)+1)/step);
angle = ang*rad;
newrad = radius*Math.sin(next*angstp*rad);
v[c] = new vertex(Math.cos(angle)*newrad, Math.sin(angle)*newrad, radius*Math.cos(next*angstp*rad));
duplicateMovieClip("dot", "dot"+c, c);
c++;
}
ang = 0;
}
dot.removeMovieClip();
// ------------------------------------
v[amount-1] = new vertex(0, 0, radius);
v[amount] = new vertex(0, 0, -radius);
};
// ####################################################
// -- © 2002-2003 Grigory Ryabov.
// --
http://www.flash.plux.ru
// -- 3d sphere 2
// ####################################################
_root.onEnterFrame = function() {
var xa = -(cnx-_ymouse)*rad/25;
var ya = (cny-_xmouse)*rad/25;
var sinY = Math.sin(ya);
var cosY = Math.cos(ya);
var sinX = Math.sin(xa);
var cosX = Math.cos(xa);
for (var i = 0; i<=amount; i++) {
v[i].rotateXY(sinY, cosY, sinX, cosX);
v[i].perspective();
perRatio = 1/(v[i].z/dist+1);
this["dot"+i]._x = v[i].rx;
this["dot"+i]._y = v[i].ry;
this["dot"+i]._xscale = this["dot"+i]._yscale=perRatio*50;
this["dot"+i].swapDepths(perRatio*500);
}
_root.clear();
_root.lineStyle(0, 0xCCCCCC, 100);
for (var c = 0; c<step; c++) {
_root.moveTo(v[c*8].rx, v[c*8].ry);
for (var i = c*8; i<=(c*8+7); i++) {
_root.lineTo(v[i].rx, v[i].ry);
}
_root.lineTo(v[c*8].rx, v[c*8].ry);
}
for (var i = 0; i<=23; i++) {
_root.moveTo(v[i].rx, v[i].ry);
_root.lineTo(v[i+8].rx, v[i+8].ry);
}
// -------------------------
for (var i = 0; i<=7; i++) {
_root.moveTo(v[amount-1].rx, v[amount-1].ry);
_root.lineTo(v[i].rx, v[i].ry);
}
for (var i = 24; i<=31; i++) {
_root.moveTo(v[amount].rx, v[amount].ry);
_root.lineTo(v[i].rx, v[i].ry);
}
};
stop();