Показать сообщение отдельно
Старый 14.06.2003, 08:25
nuran вне форума Посмотреть профиль Отправить личное сообщение для nuran Найти все сообщения от nuran
  № 1  
nuran

Регистрация: Apr 2003
Адрес: DC
Сообщений: 4,489
Thumbs up ActionScripts.TXT Смотрите <-- здесь мои Flash MX исходники

// 3D CUBE
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;
};
face = function (c, v1, v2, v3, v4) {
this.c = c;
this.v1 = v1;
this.v2 = v2;
this.v3 = v3;
this.v4 = v4;
};
face.prototype.draw = function() {
var shadow = 140+((v[this.v1].rx+v[this.v2].rx+v[this.v3].rx+v[this.v4].rx)-(v[this.v1].ry+v[this.v2].ry+v[this.v3].ry+v[this.v4].ry))/4;
_root.lineStyle(0, 0x000000, 100);
_root.beginFill(shadow << 16 | shadow << 8 | shadow << 0, 100);
_root.moveTo(v[this.v1].rx, v[this.v1].ry);
_root.lineTo(v[this.v2].rx, v[this.v2].ry, v[this.v3].rx, v[this.v3].ry);
_root.lineTo(v[this.v3].rx, v[this.v3].ry, v[this.v4].rx, v[this.v4].ry);
_root.lineTo(v[this.v4].rx, v[this.v4].ry, v[this.v1].rx, v[this.v1].ry);
_root.endFill();
};
face.prototype.fill = function() {
var vis = ((v[this.v2].rx-v[this.v1].rx)*(v[this.v3].ry-v[this.v1].ry)-(v[this.v2].ry-v[this.v1].ry)*(v[this.v3].rx-v[this.v1].rx));
if ((this.c+2)%2) {
vis *= -1;
}
if (vis>=0) {
this.draw();
}
};
_root.onLoad = function() {
cnx = 250;
cny = 250;
dist = 200;
var sx = 75;
var sy = 75;
var sz = 75;
rad = Math.PI/180;
amount = 7;
// initialization of the vertex
v = new Array();
v[0] = new vertex(sx, -sy, sz);
v[1] = new vertex(sx, sy, sz);
v[2] = new vertex(sx, sy, -sz);
v[3] = new vertex(sx, -sy, -sz);
v[4] = new vertex(-sx, -sy, -sz);
v[5] = new vertex(-sx, sy, -sz);
v[6] = new vertex(-sx, sy, sz);
v[7] = new vertex(-sx, -sy, sz);
// initialization of the faces
f = new Array();
f[0] = new face(0, 0, 1, 2, 3);
f[1] = new face(1, 2, 3, 4, 5);
f[2] = new face(2, 4, 5, 6, 7);
f[3] = new face(3, 0, 1, 6, 7);
f[4] = new face(4, 0, 3, 4, 7);
f[5] = new face(5, 1, 2, 5, 6);
};
// ####################################################
// -- © 2002-2003 Grigory Ryabov.
// -- http://www.flash.plux.ru
// ####################################################
this.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();
}
_root.clear();
// fill the right side face
f[0].fill();
// fill the front face
f[1].fill();
// fill the left side face
f[2].fill();
// fill the back face
f[3].fill();
// fill the bottoms face
f[4].fill();
// fill the top face
f[5].fill();
};
stop();

------------------------------------------------------------------------------------

// 3D Splines Like

initialization = function () {
cnx = 250;
cny = 250;
mas = new Array(0, 0.5, 0, -0.5, 1, 1.23, 1, 1, 1.23, 1);
radius = 120;
spline = 10;
amount = spline*3;
rad = Math.PI/180;
i = 0;
v = new Array();
for (var next = 0; next<=3; next++) {
var am = amount*next/3;
do {
var angle = (i*Math.PI*6)/amount;
v[i] = new ver(Math.cos(angle)*radius*mas[next+3], Math.sin(angle)*radius*mas[next+6], radius*mas[next]);
} while (i++<am);
}
dist = radius*((mas[5]+mas[8])*0.5)*2.5;
};
ver = function (x, y, z) {
this.x = x;
this.y = y;
this.z = z;
};
ver.prototype.rotate3d = function(ya, xa) {
var zp = (this.z*Math.cos(ya*rad))-(this.x*Math.sin(ya*rad));
var xp = (this.z*Math.sin(ya*rad))+(this.x*Math.cos(ya*rad));
var yp = (this.y*Math.cos(xa*rad))-(zp*Math.sin(xa*rad));
var zp = (this.y*Math.sin(xa*rad))+(zp*Math.cos(xa*rad));
this.x = xp;
this.y = yp;
this.z = zp;
};
ver.prototype.perspective = function() {
var perRatio = 1/(this.z/dist+1);
this.rx = cnx+this.x*perRatio;
this.ry = cny+this.y*perRatio;
};
curveThree = function (x1, y1, x2, y2, x3, y3) {
var nx = 2*x2-0.5*(x1+x3);
var ny = 2*y2-0.5*(y1+y3);
this.moveTo(x1, y1);
this.curveTo(nx, ny, x3, y3);
};
splines = function () {
var df = amount/3;
clear();
lineStyle(16, 0xFFFFFF, 100);
for (var i = 1; i<=df; i++) {
curveThree(v[i].rx, v[i].ry, v[i+df].rx, v[i+df].ry, v[i+df*2].rx, v[i+df*2].ry);
}
lineStyle(14, 0x000000, 100);
for (var i = 1; i<=df; i++) {
curveThree(v[i].rx, v[i].ry, v[i+df].rx, v[i+df].ry, v[i+df*2].rx, v[i+df*2].ry);
}
};
// ##################################################################
// -- 3D SPLINES LIKE v2.0
// -- © 2002-2003 Grigory Ryabov.
// -- http://www.flash.plux.ru
// -- original idea - Den Ivanov | CleoAG.com
// ##################################################################
initialization();
this.onEnterFrame = function () {
for (var i = 0; i<=amount; i++) {
v[i].rotate3d(-(cnx-_xmouse)*0.05, (cny-_ymouse)*0.05);
v[i].perspective();
}
splines();
};
stop();
__________________
flash/flex/unity