Advertisement
PolyCreativity

Bezier Curve: QBasic

Jun 8th, 2024 (edited)
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QBasic 2.23 KB | Source Code | 0 0
  1. 'Draw a bezier curve
  2. SUB Curve (pointAX AS DOUBLE, pointAY AS DOUBLE, controlAX AS DOUBLE, controlAY AS DOUBLE, pointBX AS DOUBLE, pointBY AS DOUBLE, controlBX AS DOUBLE, controlBY AS DOUBLE, detail AS INTEGER, colour AS INTEGER, pattern AS INTEGER)
  3.  
  4.  
  5.     'Half-way point
  6.     DIM pointNX AS DOUBLE
  7.     DIM pointNY AS DOUBLE
  8.     'Center of triangle: pointA -> controlA -> pointN
  9.     DIM pointCX AS DOUBLE
  10.     DIM pointCY AS DOUBLE
  11.     'Center of triangle: pointN -> controlB -> pointB
  12.     DIM pointDX AS DOUBLE
  13.     DIM pointDY AS DOUBLE
  14.  
  15.     'Halfway between the two new controls
  16.     DIM pointEX AS DOUBLE
  17.     DIM pointEY AS DOUBLE
  18.  
  19.  
  20.     IF detail = 0 THEN
  21.         'If this is the last line of detail just draw a line betwen the two points
  22.         LINE (INT(pointAX), INT(pointAY))-(INT(pointBX), INT(pointBY)), colour,,pattern
  23.     ELSE
  24.         'Find half way between controlA and controlB
  25.         pointNX = (controlAX + controlBX) / 2
  26.         pointNY = (controlAY + controlBY) / 2
  27.  
  28.         'Find the center of the triangle pointA -> controlA -> and pointN
  29.         pointCX = (pointAX + controlAX + pointNX) / 3
  30.         pointCY = (pointAY + controlAY + pointNY) / 3
  31.        
  32.         'Find the center of the triangle pointN -> controlB -> and pointB
  33.         pointDX = (pointNX + controlBX + pointBX) / 3
  34.         pointDY = (pointNY + controlBY + pointBY) / 3
  35.  
  36.         'The control point is halfway between controlA and pointC (center of triangle)
  37.         controlCX = (controlAX + pointCX) / 2
  38.         controlCY = (controlAY + pointCY) / 2
  39.  
  40.         'The second control point is halfway between controlB and pointD (center of triangle)
  41.         controlDX = (controlBX + pointDX) / 2
  42.         controlDY = (controlBY + pointDY) / 2
  43.  
  44.         'The new destination point is halfway between pointC and pointD
  45.         pointEX = (pointCX + pointDX) / 2
  46.         pointEY = (pointCY + pointDY) / 2
  47.        
  48.         'Draw a curve from pointA to pointE
  49.         Curve pointAX, pointAY, pointCX, pointCY, pointEX, pointEY, pointCX, pointCY, detail - 1, colour,pattern
  50.         'Draw a curve from pointE to pointB
  51.         Curve pointEX, pointEY, pointDX, pointDY, pointBX, pointBY, pointDX, pointDY, detail - 1, colour,pattern
  52.        
  53.     END IF
  54. END SUB
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement