-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from christo-pr/develop
React legra v0.1.1
- Loading branch information
Showing
12 changed files
with
165 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import Board, { BezierCurve } from 'react-legra' | ||
|
||
export default function BezierCurveExample() { | ||
return ( | ||
<Board> | ||
<BezierCurve | ||
from={[3,3]} | ||
to={[22, 14]} | ||
controlPointX={[8, 30]} | ||
controlPointY={[18, 1]} | ||
bs={8} /> | ||
</Board> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react' | ||
import Board, { QuadraticCurve } from 'react-legra' | ||
|
||
export default function QuadraticCurveExample() { | ||
return ( | ||
<Board> | ||
<QuadraticCurve | ||
from={[3,3]} | ||
to={[22, 14]} | ||
controlPoint={[8, 30, 18, 1]} | ||
bs={8} /> | ||
</Board> | ||
) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { useEffect } from 'react' | ||
import Legra from 'legra' | ||
|
||
export function BezierCurve (props) { | ||
const { from, to, controlPointX, controlPointY, options = {}, bs = 24, c = null } = props | ||
|
||
useEffect(() => { | ||
if (!c) return | ||
|
||
const ctx = c.getContext('2d') | ||
const legra = new Legra(ctx, bs) | ||
|
||
// Draw the blizer curve | ||
legra.bezierCurve(...from, ...controlPointX, ...controlPointY, ...to, options) | ||
}, [from, controlPointX, controlPointY, to, options, bs, c]) | ||
|
||
return null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useEffect } from 'react' | ||
import Legra from 'legra' | ||
|
||
export function QuadraticCurve (props) { | ||
const { from, to, controlPoint, options = {}, bs = 24, c = null } = props | ||
|
||
useEffect(() => { | ||
if (!c) return | ||
|
||
const ctx = c.getContext('2d') | ||
const legra = new Legra(ctx, bs) | ||
|
||
// Draw the quadratic curve | ||
legra.quadraticCurve(...from, ...controlPoint, ...to, options) | ||
}, [from, controlPoint, to, options, bs, c]) | ||
|
||
return null | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict' | ||
|
||
/** | ||
* Clean the board | ||
*/ | ||
function cleanBoard(canvas) { | ||
const ctx = canvas.getContext('2d') | ||
ctx.clearRect(0, 0, canvas.width, canvas.height) | ||
} | ||
|
||
export default { | ||
cleanBoard | ||
} |