Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bezier Path Generator
#4
(10-07-2024, 06:29 AM)vince Wrote: check out this mod

Code: (Select All)
defdbl a-z
sw = 800
sh = 600
screen _newimage(sw, sh, 32)

n = 8
dim x(n), y(n)
x(0)=sw/2:y(0)=sh/7
x(1)=sw/3:y(1)=2*sh/7
x(2)=2*sw/3:y(2)=3*sh/7
x(3)=sw/5:y(3)=4*sh/7
x(4)=sw/2:y(4)=5*sh/7
x(5)=sw/5:y(5)=5*sh/7
x(6)=sw/2:y(6)=6*sh/7
x(7)=4*sw/5:y(7)=6*sh/7

cls

preset (x(0), y(0))
for i=0 to n - 1
    line -(x(i), y(i)), _rgb(55,55,0)
    circle (x(i), y(i)), 3, _rgb(255,255,0)
next

preset (x(0), y(0))

dt = 0.0001
for t=0 to 1 step dt
    bx = 0
    by = 0   
   
    'dx = 0
    'dy = 0
   
    for i=0 to n - 1
        bin = 1
        for j=1 to i
            bin = bin*(n - j)/j
        next
   
        p = bin*((1 - t)^(n - 1 - i))*(t^i)
        bx = bx + p*x(i)
        by = by + p*y(i)
                     
        'q = bin*((1 - t)^(n - 2 - i))*(t^(i - 1))*(i - n*t + t)
        'dx = dx + q*x(i)
        'dy = dy + q*y(i)               
    next

    if abs(bx - ox)>1 and abs(by - oy)>1 then
        line -(bx, by), _rgb(255,0,0)

        ox = bx
        oy = by
    end if
   
    'm = sqr(dx*dx + dy*dy)
    'line -step(10*dx/m, 10*dy/m), _rgb(0,255,0)
next
line -(bx, by), _rgb(255,0,0)
Whoa, thank you. I was wondering how to incorporate more than 4 points into the mix. So simple.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply


Messages In This Thread
Bezier Path Generator - by TerryRitchie - 10-06-2024, 03:06 AM
RE: Bezier Path Generator - by TerryRitchie - 10-06-2024, 05:08 PM
RE: Bezier Path Generator - by vince - 10-07-2024, 06:29 AM
RE: Bezier Path Generator - by TerryRitchie - 10-07-2024, 03:36 PM
RE: Bezier Path Generator - by Petr - 10-07-2024, 04:59 PM



Users browsing this thread: 2 Guest(s)