Bitmap/Bézier curves/Quadratic: Difference between revisions
Content deleted Content added
added FreeBASIC |
|||
Line 349: | Line 349: | ||
end subroutine quad_bezier</lang> |
end subroutine quad_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/Quadratic BBC BASIC entry |
|||
Sub bezierquad(x1 As Double, y1 As Double, x2 As Double, y2 As Double, _ |
|||
x3 As Double, y3 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 ^ 2 |
|||
b = t * t1 * 2 |
|||
c = t ^ 2 |
|||
p(i).x = Int(a * x1 + b * x2 + c * x3 + .5) |
|||
p(i).y = Int(a * y1 + b * y2 + c * y3 + .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 |
|||
bezierquad(10, 100, 250, 270, 150, 20, 20) |
|||
' empty keyboard buffer |
|||
While InKey <> "" : Wend |
|||
Print : Print "hit any key to end program" |
|||
Sleep |
|||
End</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |