Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 [source] Bezier Curve
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Catalyst




PostPosted: Tue Mar 02, 2004 9:17 pm   Post subject: [source] Bezier Curve

Implementation of a 4-point Bezier Curve
Translated (and simplified) from my c++ implementation

code:

View.Set ("offscreenonly,nobuttonbar,graphics:512;512")

type Point2D :
    record
        x, y : real
    end record

var controlPoints : array 1 .. 4 of Point2D
var hold1, hold2, hold3 : real

controlPoints (1).x := 100
controlPoints (1).y := maxy div 2

controlPoints (2).x := 200
controlPoints (2).y := maxy div 2 + 150


controlPoints (3).x := 300
controlPoints (3).y := maxy div 2 - 150

controlPoints (4).x := 400
controlPoints (4).y := maxy div 2

var holdPoint : Point2D

fcn PointOnCurve (t : real) : Point2D%% Percentage along Curve : 0 to 1

    hold1 := 1 - t
    hold2 := hold1 * hold1 * hold1
    hold3 := t * t * t

    holdPoint.x := controlPoints (1).x * hold2
    holdPoint.y := controlPoints (1).y * hold2

    holdPoint.x += controlPoints (2).x * (3 * t * hold1 * hold1)
    holdPoint.y += controlPoints (2).y * (3 * t * hold1 * hold1)

    holdPoint.x += controlPoints (3).x * (3 * t * t * hold1)
    holdPoint.y += controlPoints (3).y * (3 * t * t * hold1)

    holdPoint.x += controlPoints (4).x * hold3
    holdPoint.y += controlPoints (4).y * hold3

    result holdPoint

end PointOnCurve

var hold, holdNext : Point2D := PointOnCurve (0)
proc DrawCurve
    holdNext := PointOnCurve (0)

    for i : 1 .. 3
        drawline (round (controlPoints (i).x), round (controlPoints (i).y), round (controlPoints (i + 1).x), round (controlPoints (i + 1).y), 22)
    end for

    for i : 1 .. 100
        hold := holdNext
        holdNext := PointOnCurve ((i + 1) / 100)
        drawline (round (hold.x), round (hold.y), round (holdNext.x), round (holdNext.y), 42)
    end for

    for i : 1 .. 4
        drawoval (round (controlPoints (i).x), round (controlPoints (i).y), 5, 5, 103)

    end for
end DrawCurve

var x, y, z : int

loop
    mousewhere (x, y, z)
    DrawCurve
    for i : 1 .. 4
        if sqrt ((controlPoints (i).x - x) * (controlPoints (i).x - x) + (controlPoints (i).y - y) * (controlPoints (i).y - y)) <= 5 and z = 1 then

            loop
                mousewhere (x, y, z)
                DrawCurve
                controlPoints (i).x := x
                controlPoints (i).y := y
                exit when z = 0
                View.Update
                drawfillbox (0, 0, maxx, maxy, 7)
            end loop
        end if
    end for


    View.Update
    drawfillbox (0, 0, maxx, maxy, 7)
end loop
Sponsor
Sponsor
Sponsor
sponsor
zylum




PostPosted: Tue Mar 02, 2004 9:23 pm   Post subject: (No subject)

wow that is really nice... im going to try and recreate that without looking at the code Very Happy

+20 bits

-zylum
Tony




PostPosted: Tue Mar 02, 2004 10:38 pm   Post subject: (No subject)

sweet Very Happy anyone wants to write up a vector design app (adobe illustrator) in turing? Laughing
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
AsianSensation




PostPosted: Tue Mar 02, 2004 11:12 pm   Post subject: (No subject)

that is really really nice
jonos




PostPosted: Wed Mar 03, 2004 8:15 am   Post subject: (No subject)

yeah, awesome.
recneps




PostPosted: Wed Mar 03, 2004 3:53 pm   Post subject: (No subject)

Nice indeed. That has many many possibilities. Very Happy
shorthair




PostPosted: Wed Mar 03, 2004 5:09 pm   Post subject: (No subject)

Once again , 2 thumbs up , just a quality app catalyst , i really like it , your code is just crazy you have areally really unique style
the_short1




PostPosted: Fri Mar 12, 2004 2:16 pm   Post subject: (No subject)

crzy,,,, taht lookz realy nice... and black backround.. YAY someone makes it look good...

does anyone know the proper slope to get a circle...
like for drawing a line at a central point and rotating it do a nice circle.. whenever i try i only get it to / and \ not round

x += ?
y +=?
y := ?x + ? blah blah blah...

i should know this cuz we did sometihgn similiar to it in math.. but i forget the slope now but i dont got my bookz with me... thx..
Sponsor
Sponsor
Sponsor
sponsor
jonos




PostPosted: Fri Mar 12, 2004 3:22 pm   Post subject: (No subject)

you have to square the y or x coordinates to get a parabola (i think, we haven't done that in math yet).
the_short1




PostPosted: Fri Mar 12, 2004 3:31 pm   Post subject: (No subject)

i have the exact formula but its at school Evil or Very Mad . . im on march break as as yesterday... Laughing Laughing Laughing Laughing Laughing Laughing
Tony




PostPosted: Fri Mar 12, 2004 4:03 pm   Post subject: (No subject)

isn't it something like x*x + y*y = r*r ?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Delos




PostPosted: Fri Mar 12, 2004 6:21 pm   Post subject: (No subject)

That only applies to a circle from the origin.

I believe the general eqn for a cirle on a Cartesian place is:

(y-p)^2 + (x-q)^2 = r^2

Or something to that effect...urgh..Gr11 maths haunting again.
the_short1




PostPosted: Fri Mar 12, 2004 10:36 pm   Post subject: (No subject)

thanxTony... thats it ..or at least thats was the formula i remember....
SuperGenius




PostPosted: Fri Mar 19, 2004 2:38 pm   Post subject: (No subject)

the formula for the radius of a circle that my tracher told us is:

r=sqrt ((x2-x1)** + (y2-y1)**)
jonos




PostPosted: Fri Mar 19, 2004 3:07 pm   Post subject: (No subject)

i think they are the same, because one of your x,y is the center of the circle and the other is a point on the circle, so the radius is the the length of that (i think)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: