Bitmap/Bézier curves/Cubic: Difference between revisions

Content added Content deleted
No edit summary
(added FreeBASIC)
Line 456: Line 456:


end subroutine cubic_bezier</lang>
end subroutine cubic_bezier</lang>
=={{header|FreeBASIC}}==
{{trans|BBC BASIC}}
<lang freebasic>' version 01-11-2016
' compile with: fbc -s console

' translation from Bitmap/Bresenham's line algorithm C entry
Sub Br_line(x0 As Integer, y0 As Integer, x1 As Integer, y1 As Integer, _
Col As UInteger = &HFFFFFF)

Dim As Integer dx = Abs(x1 - x0), dy = Abs(y1 - y0)
Dim As Integer sx = IIf(x0 < x1, 1, -1)
Dim As Integer sy = IIf(y0 < y1, 1, -1)
Dim As Integer er = IIf(dx > dy, dx, -dy) \ 2, e2

Do
PSet(x0, y0), col
If (x0 = x1) And (y0 = y1) Then Exit Do
e2 = er
If e2 > -dx Then Er -= dy : x0 += sx
If e2 < dy Then Er += dx : y0 += sy
Loop

End Sub

' Bitmap/Bézier curves/Cubic BBC BASIC entry
Sub beziercubic(x1 As Double, y1 As Double, x2 As Double, y2 As Double, _
x3 As Double, y3 As Double, x4 As Double, y4 As Double, _
n As ULong, col As UInteger = &HFFFFFF)

Type point_
x As Integer
y As Integer
End Type

Dim As ULong i
Dim As Double t, t1, a, b, c, d
Dim As point_ p(n)

For i = 0 To n
t = i / n
t1 = 1 - t
a = t1 ^ 3
b = t * t1 * t1 * 3
c = t * t * t1 * 3
d = t ^ 3
p(i).x = Int(a * x1 + b * x2 + c * x3 + d * x4 + .5)
p(i).y = Int(a * y1 + b * y2 + c * y3 + d * y4 + .5)
Next

For i = 0 To n -1
Br_line(p(i).x, p(i).y, p(i +1).x, p(i +1).y, col)
Next

End Sub

' ------=< MAIN >=------

ScreenRes 250,250,32 ' 0,0 in top left corner

beziercubic(160, 150, 10, 120, 30, 0, 150, 50, 20)


' empty keyboard buffer
While Inkey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</lang>


=={{header|Go}}==
=={{header|Go}}==