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

(+ D entry)
Line 227:
....................
....................</pre>
 
=={{header|FBSL}}==
Windows' graphics origin is located at the bottom-left corner of device bitmap.
 
'''Translation of BBC BASIC using pure FBSL's built-in graphics functions:'''
<lang qbasic>#DEFINE WM_LBUTTONDOWN 513
#DEFINE WM_CLOSE 16
 
FBSLSETTEXT(ME, "Bezier Quadratic")
FBSLSETFORMCOLOR(ME, RGB(0, 255, 255)) ' Cyan: persistent background color
DRAWWIDTH(5) ' Adjust point size
FBSL.GETDC(ME) ' Use volatile FBSL.GETDC below to avoid extra assignments
 
RESIZE(ME, 0, 0, 235, 235)
CENTER(ME)
SHOW(ME)
 
DIM %Height
FBSL.GETCLIENTRECT(ME, 0, 0, 0, Height)
 
BEGIN EVENTS
SELECT CASE CBMSG
CASE WM_LBUTTONDOWN: BezierQuad(10, 100, 250, 270, 150, 20, 20) ' Draw
CASE WM_CLOSE: FBSL.RELEASEDC(ME, FBSL.GETDC) ' Clean up
END SELECT
END EVENTS
 
SUB BezierQuad(x1, y1, x2, y2, x3, y3, n)
TYPE POINTAPI
x AS INTEGER
y AS INTEGER
END TYPE
DIM t, t1, a, b, c, p[n] AS POINTAPI
FOR DIM i = 0 TO n
t = i / n: t1 = 1 - t
a = t1 ^ 2
b = 2 * t * t1
c = t ^ 2
p[i].x = a * x1 + b * x2 + c * x3 + 0.5
p[i].y = Height - (a * y1 + b * y2 + c * y3 + 0.5)
NEXT
FOR i = 0 TO n - 1
Bresenham(p[i].x, p[i].y, p[i + 1].x, p[i + 1].y)
NEXT
SUB Bresenham(x0, y0, x1, y1)
DIM dx = ABS(x0 - x1), sx = SGN(x0 - x1)
DIM dy = ABS(y0 - y1), sy = SGN(y0 - y1)
DIM tmp, er = IIF(dx > dy, dx, -dy) / 2
WHILE NOT (x0 = x1 ANDALSO y0 = y1)
PSET(FBSL.GETDC, x0, y0, &HFF) ' Red: Windows stores colors in BGR order
tmp = er
IF tmp > -dx THEN: er = er - dy: x0 = x0 + sx: END IF
IF tmp < +dy THEN: er = er + dx: y0 = y0 + sy: END IF
WEND
END SUB
END SUB</lang>
'''Output:''' [[File:FBSLBezierQuad.PNG]]
 
=={{header|Factor}}==