Skip to content

Commit 5a6cde4

Browse files
committed
Added Bézier curves.
1 parent d3b4b0e commit 5a6cde4

File tree

3 files changed

+89
-1
lines changed

3 files changed

+89
-1
lines changed

docs/Graphics/Canvas.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,4 +727,41 @@ setGradientFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :
727727

728728
Set the Context2D fillstyle to the CanvasGradient.
729729

730+
#### `QuadraticCurve`
731+
732+
``` purescript
733+
type QuadraticCurve = { cpx :: Number, cpy :: Number, x :: Number, y :: Number }
734+
```
735+
736+
A type representing a quadratic Bézier curve.
737+
- Bézier control point: (`cpx`, `cpy`)
738+
- Ending point coordinates: (`x`, `y`)
739+
740+
#### `quadraticCurveTo`
741+
742+
``` purescript
743+
quadraticCurveTo :: forall eff. QuadraticCurve -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
744+
```
745+
746+
Draw a quadratic Bézier curve.
747+
748+
#### `BezierCurve`
749+
750+
``` purescript
751+
type BezierCurve = { cp1x :: Number, cp1y :: Number, cp2x :: Number, cp2y :: Number, x :: Number, y :: Number }
752+
```
753+
754+
A type representing a cubic Bézier curve.
755+
- First Bézier control point: (`cp1x`, `cp1y`)
756+
- Second Bézier control point: (`cp2x`, `cp2y`)
757+
- Ending point: (`x`, `y`)
758+
759+
#### `bezierCurveTo`
760+
761+
``` purescript
762+
bezierCurveTo :: forall eff. BezierCurve -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
763+
```
764+
765+
Draw a cubic Bézier curve.
766+
730767

src/Graphics/Canvas.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,22 @@ exports.setGradientFillStyle = function(gradient) {
540540
};
541541
};
542542
};
543-
544543

544+
exports.quadraticCurveTo = function(qCurve) {
545+
return function(ctx) {
546+
return function() {
547+
ctx.quadraticCurveTo(qCurve.cpx, qCurve.cpy, qCurve.x, qCurve.y);
548+
return ctx;
549+
};
550+
};
551+
};
545552

553+
exports.bezierCurveTo = function(bCurve) {
554+
return function(ctx) {
555+
return function() {
556+
ctx.bezierCurveTo(bCurve.cp1x, bCurve.cp1y, bCurve.cp2x, bCurve.cp2y, bCurve.x, bCurve.y);
557+
return ctx;
558+
};
559+
};
560+
};
546561

src/Graphics/Canvas.purs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ module Graphics.Canvas
2121
, CanvasGradient()
2222
, LinearGradient()
2323
, RadialGradient()
24+
, QuadraticCurve()
25+
, BezierCurve()
2426

2527
, getCanvasElementById
2628
, getContext2D
@@ -96,6 +98,9 @@ module Graphics.Canvas
9698
, createRadialGradient
9799
, addColorStop
98100
, setGradientFillStyle
101+
102+
, quadraticCurveTo
103+
, bezierCurveTo
99104
) where
100105

101106
import Prelude
@@ -511,3 +516,34 @@ foreign import addColorStop :: forall eff. Number -> String -> CanvasGradient ->
511516

512517
-- | Set the Context2D fillstyle to the CanvasGradient.
513518
foreign import setGradientFillStyle :: forall eff. CanvasGradient -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
519+
520+
-- | A type representing a quadratic Bézier curve.
521+
-- | - Bézier control point: (`cpx`, `cpy`)
522+
-- | - Ending point coordinates: (`x`, `y`)
523+
524+
type QuadraticCurve =
525+
{ cpx :: Number
526+
, cpy :: Number
527+
, x :: Number
528+
, y :: Number
529+
}
530+
531+
-- | Draw a quadratic Bézier curve.
532+
foreign import quadraticCurveTo :: forall eff. QuadraticCurve -> Context2D -> Eff (canvas :: Canvas | eff) Context2D
533+
534+
-- | A type representing a cubic Bézier curve.
535+
-- | - First Bézier control point: (`cp1x`, `cp1y`)
536+
-- | - Second Bézier control point: (`cp2x`, `cp2y`)
537+
-- | - Ending point: (`x`, `y`)
538+
539+
type BezierCurve =
540+
{ cp1x :: Number
541+
, cp1y :: Number
542+
, cp2x :: Number
543+
, cp2y :: Number
544+
, x :: Number
545+
, y :: Number
546+
}
547+
548+
-- | Draw a cubic Bézier curve.
549+
foreign import bezierCurveTo :: forall eff. BezierCurve -> Context2D -> Eff (canvas :: Canvas | eff) Context2D

0 commit comments

Comments
 (0)