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

Added PicoLisp
(Added PicoLisp)
Line 418:
}
</lang>
 
=={{header|PicoLisp}}==
This uses the 'brez' line drawing function from
[[Bitmap/Bresenham's line algorithm#PicoLisp]].
<lang PicoLisp>(scl 6)
 
(de cubicBezier (Img N X1 Y1 X2 Y2 X3 Y3 X4 Y4)
(let (R (* N N N) X X1 Y Y1 DX 0 DY 0)
(for I N
(let
(J (- N I)
A (*/ 1.0 J J J R)
B (*/ 3.0 I J J R)
C (*/ 3.0 I I J R)
D (*/ 1.0 I I I R) )
(brez Img
X
Y
(setq DX
(-
(+ (*/ A X1 1.0) (*/ B X2 1.0) (*/ C X3 1.0) (*/ D X4 1.0))
X ) )
(setq DY
(-
(+ (*/ A Y1 1.0) (*/ B Y2 1.0) (*/ C Y3 1.0) (*/ D Y4 1.0))
Y ) ) )
(inc 'X DX)
(inc 'Y DY) ) ) ) )</lang>
Test:
<lang PicoLisp>(let Img (make (do 200 (link (need 300 0)))) # Create image 300 x 200
(cubicBezier Img 24 20 120 540 33 -225 33 285 100)
(out "img.pbm" # Write to bitmap file
(prinl "P1")
(prinl 300 " " 200)
(mapc prinl Img) ) )
 
(call 'display "img.pbm")</lang>
 
=={{header|PureBasic}}==
<lang PureBasic>Procedure cubic_bezier(img, p1x, p1y, p2x, p2y, p3x, p3y, p4x, p4y, Color, n_seg)
Anonymous user