Implement color for quadratic bezier curves

This commit is contained in:
2021-03-12 19:10:14 +01:00
parent 4ed72e263b
commit 918f7d23b8
8 changed files with 38 additions and 14 deletions
+14 -2
View File
@@ -69,8 +69,20 @@ polygonCol :: [(Point2,RGBA)] -> Picture
{-# INLINE polygonCol #-}
polygonCol = PolygonCol 0
bezierQuad :: Point2 -> Point2 -> Point2 -> Picture
bezierQuad a b c = BezierQuad 0 [a,b,c]
-- note that much of work computing the width of the bezier curve is done here
-- not sure that moving the control point does much...
bezierQuad :: Color -> Color -> Float -> Float -> Point2 -> Point2 -> Point2 -> Picture
bezierQuad cola colc ra rc a b c = BezierQuad 0 [(aX,cola ,raX)
,(bx,mixColors 0.5 0.5 cola colc,1)
,(cX,colc ,rcX)]
where v = a -.- c
nv = normalizeV v
aX = a +.+ ra * 0.5 *.* nv
cX = c -.- rc * 0.5 *.* nv
raX = ra / magV (aX -.- cX)
rcX = rc / magV (aX -.- cX)
bx = b +.+ (0.5 * ra *.* normalizeV (b -.- a))
+.+ (0.5 * rc *.* normalizeV (b -.- c))
color :: RGBA -> Picture -> Picture
{-# INLINE color #-}