![]() |
|
||||||||||
|
|||||||
|
|
« Предыдущая тема | Следующая тема » |
| Опции темы | Опции просмотра |
|
![]() |
|
|||||
|
Регистрация: Apr 2003
Адрес: DC
Сообщений: 4,489
|
// Это вообще легко и просто
MovieClip.prototype.drawBezierCircle = function(shadow, x1, y1, x2, y2, x3, y3, x4, y4) { cx1 = x1+(x2-x1)/2; cy1 = y1+(y2-y1)/2; cx2 = x2+(x3-x2)/2; cy2 = y2+(y3-y2)/2; cx3 = x3+(x4-x3)/2; cy3 = y3+(y4-y3)/2; cx4 = x4+(x1-x4)/2; cy4 = y4+(y1-y4)/2; this.lineStyle(0, 0x000000, 100); this.beginFill(shadow << 16 | shadow << 8 | shadow << 0, 100); this.moveTo(cx1, cy1); this.curveTo(x2, y2, cx2, cy2); this.curveTo(x3, y3, cx3, cy3); this.curveTo(x4, y4, cx4, cy4); this.curveTo(x1, y1, cx1, cy1); this.endFill(); }; 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.zindex = function() { return (Math.round(v[this.v1].z+v[this.v2].z+v[this.v3].z+v[this.v4].z)); }; 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))/8; _root.drawBezierCircle(shadow,v[this.v1].rx, v[this.v1].ry, v[this.v2].rx, v[this.v2].ry, v[this.v3].rx, v[this.v3].ry, v[this.v4].rx, v[this.v4].ry); }; face.prototype.fill = function() { this.draw(); }; insertSort = function (a, lb, ub) { for (i=lb+1; i<=ub; i++) { t = a[i].z; temp = a[i].i; for (j=i-1; j>=lb && (a[j].z>t); j--) { a[j+1].z = a[j].z; a[j+1].i = a[j].i; } a[j+1].z = t; a[j+1].i = temp; } return (a); }; _root.onLoad = function() { cnx = 200; cny = 200; dist = 270; var sx = 75; var sy = 75; var sz = 75; rad = Math.PI/180; faces = 5; 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 // -- 3D CUBE + BezierCircle + Z Sort // #################################################### insertSorting = function () { count = new Array(); for (var i = 0; i<=faces; i++) { count[i] = new Object(); count[i].z = f[i].zindex(); count[i].i = i; } count = insertSort(count, 0, faces); for (var i = 0; i<=faces; i++) { f[count[faces-i].i].fill(); } }; _root.onEnterFrame = function() { _root.clear(); for (var i = 0; i<=amount; i++) { 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); v[i].rotateXY(sinY, cosY, sinX, cosX); v[i].perspective(); } insertSorting(); }; stop();
__________________
flash/flex/unity |
|
|||||
|
Регистрация: Apr 2003
Адрес: DC
Сообщений: 4,489
|
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();
__________________
flash/flex/unity |
|
|||||
|
Регистрация: Apr 2003
Адрес: DC
Сообщений: 4,489
|
// ################################################################
// -- (c) 2002-2003 Grigory RYABOV. // -- http://www.flash.plux.ru // -- CLOTH MX // ################################################################ 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); } }; radius = 70; this.createEmptyMovieClip("layer2_", 2); this.createEmptyMovieClip("layer1_", 1); this["layer2_"].beginFill(0xFFFFFF, 100); this["layer2_"].drawCircle(16, radius, radius); this["layer2_"].endFill(); this["layer1_"].beginFill(0x333333, 100); this["layer1_"].drawCircle(16, radius, radius); this["layer1_"].endFill(); max = 20; for (i=0; i<=max; i++) { duplicateMovieClip("layer1_", "layer1_" add i, 100-i); duplicateMovieClip("layer2_", "layer2_" add i, 50-i); } layer1_._visible = layer1_0._visible=layer2_._visible=layer2_0._visible=0; function mouse() { px += (_xmouse-this.layer1_0._x)/3, py += (_ymouse-this.layer1_0._y)/3; layer1_0._x=layer2_0._x=px, layer1_0._y=layer2_0._y=py; xs=Math.sin(count += 0.3)*6, ys=Math.cos(count)*6; for (i=max; i>0; i--) { this["layer1_"+i]._x = this["layer2_"+i]._x=this["layer1_"+(i-1)]._x; this["layer1_"+i]._y = this["layer2_"+i]._y=this["layer1_"+(i-1)]._y; this["layer1_"+i]._xscale = this["layer1_"+(i-1)]._xscale-xs; this["layer1_"+i]._yscale = this["layer1_"+(i-1)]._yscale-ys; this["layer2_"+i]._xscale = this["layer1_"+(i-1)]._xscale-xs+1; this["layer2_"+i]._yscale = this["layer1_"+(i-1)]._yscale-ys+1; } } _root.onEnterFrame = function() { mouse(); };
__________________
flash/flex/unity |
![]() |
Часовой пояс GMT +4, время: 08:33. |
|
|
« Предыдущая тема | Следующая тема » |
|
|