1 ! Copyright (c) 2012 Anonymous
2 ! See http://factorcode.org/license.txt for BSD license.
3 USING: arrays assocs kernel locals math math.functions
4 math.vectors rosetta-code.bitmap rosetta-code.bitmap-line
6 IN: rosetta-code.bitmap-bezier
8 ! http://rosettacode.org/wiki/Bitmap/Bézier_curves/Cubic
10 ! Using the data storage type defined on this page for raster
11 ! images, and the draw_line function defined in this other one,
12 ! draw a cubic bezier curves (definition on Wikipedia).
14 :: (cubic-bezier) ( P0 P1 P2 P3 -- bezier )
17 1 x - sq 3 * x * P1 n*v
18 1 x - 3 * x sq * P2 n*v
22 ! gives an interval of x from 0 to 1 to map the bezier function
23 : t-interval ( x -- interval )
24 [ <iota> ] keep 1 - [ / ] curry map ;
26 ! turns a list of points into the list of lines between them
27 : points-to-lines ( seq -- seq )
30 : draw-lines ( {R,G,B} points image -- )
31 [ [ first2 ] dip draw-line ] curry with each ;
33 :: bezier-lines ( {R,G,B} P0 P1 P2 P3 image -- )
34 ! 100 is an arbitrary value.. could be given as a parameter..
35 100 t-interval P0 P1 P2 P3 (cubic-bezier) map
37 {R,G,B} swap image draw-lines ;