Computer Science Canada Programming C, C++, Java, PHP, Ruby, Turing, VB   Username:   Password: Wiki   Blog   Search   Turing   Chat Room  Members
[source] Bezier Curve
Author Message
Catalyst

Posted: 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

zylum

Posted: 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

+20 bits

-zylum
Tony

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

sweet anyone wants to write up a vector design app (adobe illustrator) in turing?
Tony's programming blog. DWITE - a programming contest.
AsianSensation

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

that is really really nice
jonos

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

yeah, awesome.
recneps

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

Nice indeed. That has many many possibilities.
shorthair

Posted: 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

Posted: 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..

jonos

Posted: 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

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

i have the exact formula but its at school . . im on march break as as yesterday...
Tony

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

isn't it something like x*x + y*y = r*r ?
Tony's programming blog. DWITE - a programming contest.
Delos

Posted: 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

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

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

Posted: 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

Posted: 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: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
 Jump to:  Select a forum  CompSci.ca ------------ - Network News - General Discussion     General Forums   -----------------   - Hello World   - Featured Poll   - Contests     Contest Forums   -----------------   - DWITE   - [FP] Contest 2006/2008   - [FP] 2005/2006 Archive   - [FP] 2004/2005 Archive   - Off Topic     Lounges   ---------   - User Lounge   - VIP Lounge     Programming -------------- - General Programming     General Programming Forums   --------------------------------   - Functional Programming   - Logical Programming   - C     C   --   - C Help   - C Tutorials   - C Submissions   - C++     C++   ----   - C++ Help   - C++ Tutorials   - C++ Submissions   - Java     Java   -----   - Java Help   - Java Tutorials   - Java Submissions   - Ruby     Ruby   -----   - Ruby Help   - Ruby Tutorials   - Ruby Submissions   - Turing     Turing   --------   - Turing Help   - Turing Tutorials   - Turing Submissions   - PHP     PHP   ----   - PHP Help   - PHP Tutorials   - PHP Submissions   - Python     Python   --------   - Python Help   - Python Tutorials   - Python Submissions   - Visual Basic and Other Basics     VB   ---   - Visual Basic Help   - Visual Basic Tutorials   - Visual Basic Submissions     Education ----------- - Student Life   Graphics and Design ----------------------- - Web Design     Web Design Forums   ---------------------   - (X)HTML Help   - (X)HTML Tutorials   - Flash MX Help   - Flash MX Tutorials   - Graphics     Graphics Forums   ------------------   - Photoshop Tutorials   - The Showroom   - 2D Graphics   - 3D Graphics     Teams ------ - dTeam Public

 Style: Appalachia blueSilver eMJay subAppalachia subBlue subCanvas subEmjay subGrey subSilver subVereor Search: