Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
curves and ovals
#11
So why don't you enlighten us, Calculus Master? :lol: Wink
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#12
Calculus? You don't need that, i've never taken one. Just calculate the difference between the previous and next point, where k is steps.
oship me and i will give you lots of guurrls and beeea
Reply
#13
You wouldn't perchance be referring to a bresenham circle, would you blitz? I've taken two calculus's, but I'm about as smart as a retarded cow when it comes to actually applying that knowledge towards something useful Tongue
Code:
'by Kurt Kuzba
WIDE% = 320
HIGH% = 200

SUB BCircle (xc%, yc%, r%, c%)
'_|_|_|   Bresenham Circle Drawing Algorithm
'_|_|_|   Adapted from BRESNHAM.C in Bob Stout's SNIPPETS.
   SHARED WIDE%, HIGH%
   x% = 0: d% = 2 * (1 - r%): W% = 2 * WIDE% \ HIGH%
   WHILE r% >= 0
      PSET (xc% + x%, yc% + r%), c%
      PSET (xc% + x%, yc% - r%), c%
      PSET (xc% - x%, yc% + r%), c%
      PSET (xc% - x%, yc% - r%), c%
      IF (d% + r%) > 0 THEN r% = r% - 1: d% = d% - W% * r% - 1
      IF x% > d% THEN x% = x% + 1: d% = d% + 2 * x% + 1
   WEND
END SUB
Reply
#14
no, i'm talking about forward differencing, where you calculate each coordinate of the curve with 2 or 3 additions.
oship me and i will give you lots of guurrls and beeea
Reply
#15
Example

Code:
''
''
'' bezier.bas - Bezier drawing example
''
''
defint a-z

type pnt2i
    x   as integer
    y   as integer
end type

declare sub doTest        ( )
declare sub drwQuadBez    ( pnt() as pnt2i, steps as integer, col as integer )
declare sub drwQuadBezDDA ( pnt() as pnt2i, steps as integer, col as integer )

    
    ''
    '' Start point
    ''
    doTest
    




'' ::::::::::::
'' name: doTest
'' desc: Test draw quadratic beziers
''
'' ::::::::::::
defint a-z
sub doTest
    dim i as integer
    dim pnt( 2 ) as pnt2i
    
    ''
    '' Qb stuff
    ''
    screen 13
    randomize timer
    
    
    ''
    '' Generate random points
    ''
    for  i = 0 to 2
        pnt(i).x = rnd * 319
        pnt(i).y = rnd * 199
    next i
    
    ''
    '' Draw
    ''
    drwQuadBez pnt(), 25, 1
    sleep
    drwQuadBezDDA pnt(), 25, 4
    sleep
    
    ''
    '' More qb stuff
    ''
    screen 0
    width 80, 25
    cls    
    
end sub



'' ::::::::::::
'' name: drwQuadBez
'' desc: Draws a quadratic bezier using the formula
''       p(t)  =  (1 - t)^2*p0  +  2t*(1 - t)*p1  +  t^2*p2
''
'' ::::::::::::
defint a-z
sub drwQuadBez ( pnt() as pnt2i, _
                 steps as integer, _
                 col as integer ) static
                
    dim t as single
    dim dt as single    
    dim i as integer
    dim x as integer
    dim y as integer
    
    t = 0
    
    ''
    '' Calculate the difference in t
    ''
    dt = 1.0 / steps
        
    ''
    '' Draw the bezier as a series of points
    ''
    for  i = 0 to steps-1
        ''
        '' Calculate the point
        ''
        x = ((1.0 - t)^2)*pnt(0).x + (2*t*(1.0 - t))*pnt(1).x + (t^2)*pnt(2).x
        y = ((1.0 - t)^2)*pnt(0).y + (2*t*(1.0 - t))*pnt(1).y + (t^2)*pnt(2).y
        
        ''
        '' Draw the point
        ''
        pset ( x, y ), col
        
        ''
        '' Advance to next
        ''
        t = t + dt
    next i
    
end sub



'' ::::::::::::
'' name: drwQuadBezDDA
'' desc: Draws a quadratic bezier using the formula as drwQuadBez, except
''       it uses the difference between each point. Here's some math
''
'' p(t)    =  (1 - t)^2p0  +  2t(1 - t)p1  +  t^2p2
''         =  (t^2 - 2t + 1)p0  +  (-2t^2 + 2t)p1  +  t^2p2
''
'' Dp(t)   =  p(t + k)  -  p(t)
''         =  ((t + k)^2 - 2(t + k) + 1)p0  + (-2(t + k)^2 + 2(t + k))p1  +
''            (t + k)^2p2  -  [(t2 - 2t + 1)p0  +  (-2t^2 + 2t)p1  +  t^2p2]
''         =  (2tk + k^2 - 2k)p0  +  (-4tk - 2k^2 + 2k)p1  +  (2t^2 + k^2)p2
''
'' DDp(t)  =  Dp(t + k)  -  Dp(t)
''         =  (2(t + k)k + k^2 - 2k)p0  +  (-4(t + k)k - 2k^2 + 2k)p1  +
''            (2(t + k)k + k^2)p2 - [(2tk + k^2 - 2k)p0 + (-4tk - 2k^2 + 2k)p1 +
''            (2tk + k^2)p2]
''         =  2k^2p0  -  4k^2p1  +  2k^2p2
''
''
'' At initial condition t is zero, so we replace the with zero
''
'' p(0)    =  p0
'' Dp(0)   =  (k^2 - 2k)p0  +  (-2k^2 + 2k)p1  +  k^2p2
'' DDp(0)  =  2k^2p0  -  4k^2p1  +  2k^2p2
''
'' ::::::::::::
defint a-z
sub drwQuadBezDDA ( pnt() as pnt2i, _
                    steps as integer, _
                    col as integer ) static
    dim i as integer
    dim x as single
    dim y as single  
      
    dim dx as single
    dim dy as single
    dim ddx as single
    dim ddy as single
    
    dim k as single
    dim k2 as single
    
    ''
    '' Setup the variables
    ''
    k  = 1.0 / steps
    k2 = k*k
    
    x = pnt(0).x
    y = pnt(0).y
    
    dx = (k2 - 2*k)*pnt(0).x + (-2*k2 + 2*k)*pnt(1).x + k2*pnt(2).x
    dy = (k2 - 2*k)*pnt(0).y + (-2*k2 + 2*k)*pnt(1).y + k2*pnt(2).y
    
    ddx = 2*k2*pnt(0).x - 4*k2*pnt(1).x + 2*k2*pnt(2).x
    ddy = 2*k2*pnt(0).y - 4*k2*pnt(1).y + 2*k2*pnt(2).y
    
    
    ''
    '' Draw the bezier as a series of points
    ''
    for  i = 0 to steps-1
        ''
        '' Draw the point
        ''
        pset ( x, y ), col        
        
        ''
        '' Advance to next
        ''
        x = x + dx
        y = y + dy
        dx = dx + ddx
        dy = dy + ddy
    next i
    
end sub
oship me and i will give you lots of guurrls and beeea
Reply
#16
Quote:Calculus? You don't need that, i've never taken one. Just calculate the difference between the previous and next point, where k is steps.

LOL. :*)

Blitz axiom #1.

Yo Blitz, any news on the "compiler" ?.

I hope Vic and CGI helps. :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#17
Thanks for all the help. I can draw them now.
Not yet Snake! It's not over yet!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)