Ooops
January 26, 2021, 06:17:30 AM

### Author Topic: [bb] Bezier Function by wedoe [ 1+ years ago ]  (Read 413 times)

#### BlitzBot

• Jr. Member
• Posts: 1
##### [bb] Bezier Function by wedoe [ 1+ years ago ]
« on: June 29, 2017, 12:28:39 AM »
Title : Bezier Function
Author : wedoe
Posted : 1+ years ago

Description : This function is drawing a line between two
points with ability to curve it any way using
the reference-points.

Updated: I have now included a test-program, bezier-function at the bottom of the source.

Code :
Code: BlitzBasic
1. AppTitle "Bezier"
2.
3. Graphics 640,480,16,2
4.
5. Global x1=100     ; X start
6. Global y1=100     ; Y start
7. Global vx1=100    ; X vector start
8. Global vy1=100     ; Y vector start
9. Global x2=540     ; X end
10. Global y2=380     ; Y end
11. Global vx2=540     ; X vector-end
12. Global vy2=380     ; Y vector-end
13.
14. Global point=0 ; Counter for what position to drag
15.
16. SetBuffer BackBuffer()
17. Repeat
18. Cls
19.
20. drawbezier (x1,y1,vx1,vy1,x2,y2,vx2,vy2)
21.
22. Color 255,0,0
23. Select point
24. Case 0
25. Oval x1-2,y1-2,5,5
26. If MouseDown(2) Then
27.         x1=MouseX()
28.         y1=MouseY()
29. EndIf
30. Case 1
31. Oval vx1-2,vy1-2,5,5
32. If MouseDown(2) Then
33.         vx1=MouseX()
34.         vy1=MouseY()
35. EndIf
36. Case 2
37. Oval x2-2,y2-2,5,5
38. If MouseDown(2) Then
39.         x2=MouseX()
40.         y2=MouseY()
41. EndIf
42. Case 3
43. Oval vx2-2,vy2-2,5,5
44. If MouseDown(2) Then
45.         vx2=MouseX()
46.         vy2=MouseY()
47. EndIf
48. End Select
49.
50. Color 255,255,255
51. Text 10,10,"x1= "+x1
52. Text 10,25,"y1= "+y1
53. Text 10,40,"vx1="+vx1
54. Text 10,55,"vy1="+vy1
55. Text 10,70,"x2= "+x2
56. Text 10,85,"y2= "+y2
57. Text 10,100,"vx2="+vx2
58. Text 10,115,"vy2="+vy2
59.
60. If MouseDown(1) Then changepoint
61.
62. Flip
63. Until KeyDown(1)
64.
65. WaitKey()
66. End
67.
68. Function changepoint()
69. point=(point+1) Mod 4
70. While MouseDown(1)
71. Wend
72. End Function
73.
74.
75. ; Bezierline by Wedoe
76. ; x1=startpoint x
77. ; y1=startpoint y
78. ; vx1=referencepoint x1
79. ; vy1=referencepoint y1
80. ; x2=endpoint x
81. ; y2=endpoint y
82. ; vx2=referencepoint x2
83. ; vy2=referencepoint y2
84.
85. Function drawbezier (x1,y1,vx1,vy1,x2,y2,vx2,vy2)
86. For t#=0 To 1 Step.01
87. pointx# = x1*(1-t)^3 + 3*vx1*(1-t)^2*t + 3*vx2*(1-t)*t^2 + x2*t^3
88. pointy# = y1*(1-t)^3 + 3*vy1*(1-t)^2*t + 3*vy2*(1-t)*t^2 + y2*t^3
89. WritePixel pointx,pointy,\$ffffff
90. Next
91. End Function