Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   Серверные технологии и Flash (http://www.flasher.ru/forum/forumdisplay.php?f=62)
-   -   Формула кривых Безье! (http://www.flasher.ru/forum/showthread.php?t=69066)

artcraft 13.09.2005 02:10

Формула кривых Безье!
 
это не вопрос - просто делюсь :~)

//R(t) = P0*(1-t)^3 + P1 * t * (1-t)^2 + P2 * t^2 * (1-t) + P3 * t^3 ,
//где 0<=t<=1
//P0,P2 - опорные точки
//P1,P3 - управляющие точки

Код:

function dot(path, x, y, w, h, c){
        depth=path.getNextHighestDepth();
        var mc=path.createEmptyMovieClip("dot"+depth, depth);
        mc._x=x;        mc._y=y;
        with(mc){       
                beginFill(c, 100);
                moveTo(0, 0);
                lineTo(w, 0);lineTo(w, h);lineTo(0, h);lineTo(0, 0);
                endFill();               
        }return(mc);
}

a=dot(_root,10,10,5,5,0xFF0000);
a1=dot(_root,10,110,5,5,0xFF0000);
b=dot(_root,200,200,5,5,0xFF0000);
b1=dot(_root,200,90,5,5,0xFF0000);

a.onPress=a1.onPress=b.onPress=b1.onPress=function() {this.startDrag();}
a.onRelease=a.onReleaseOutside=function() {        this.stopDrag();}
a1.onRelease=a1.onReleaseOutside=function() {        this.stopDrag();}
b.onRelease=b.onReleaseOutside=function() {        this.stopDrag();}
b1.onRelease=b1.onReleaseOutside=function() {        this.stopDrag();}


d=_root.createEmptyMovieClip("d", 11);
d.onEnterFrame=function() {
        x0=a._x;y0=a._y;
        xc0=a1._x;yc0=a1._y;
        x1=b._x;y1=b._y;
        xc1=b1._x;yc1=b1._y;
        _root.Redraw();
}

function Redraw () {// Hарисовать кривую Безье
s=_root.createEmptyMovieClip("s", 10);
//s._x=s._y=10;

for (t=0; t<1; t+=0.01) {
        q1 = t*t*t*-1 + t*t*3 + t*(-3) + 1;
        q2 = t*t*t*3 + t*t*(-6) + t*3;
        q3 = t*t*t*(-3) + t*t*3;
        q4 = t*t*t;

        // Здесь подставляются координаты опорных точек
        qx = q1*x0 + q2*xc0 + q3*xc1 + q4*x1; 
        qy = q1*y0 + q2*yc0 + q3*yc1 + q4*y1; 
       
        dot(s,qx,qy,1,1,0x000000);
}
}


nuran 13.09.2005 05:56

genius

artcraft 14.09.2005 18:05

О, оказывается я изобрёл велосипед :~)
http://www.robertpenner.com/tools/bezier_cubic.zip

TERRORist 14.09.2005 18:08

Изобретаешь велик.

тире и ударение по желанию!)


Часовой пояс GMT +4, время: 21:58.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.