-
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.
- Loading branch information
1 parent
b910ead
commit ee6fd32
Showing
14 changed files
with
186 additions
and
31 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
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
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,34 @@ | ||
import { useEffect, useRef } from 'react'; | ||
|
||
interface CanvasProps { | ||
width: number; | ||
height: number; | ||
draw: Function; | ||
className?: string; | ||
} | ||
|
||
const Canvas = ({ width, height, draw, className }: CanvasProps) => { | ||
const canvasRef = useRef<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
if (canvasRef.current) { | ||
const canvas = canvasRef.current; | ||
const context = canvas.getContext('2d'); | ||
if (context && draw) { | ||
draw(context); | ||
} | ||
} | ||
// eslint-disable-next-line | ||
}, [canvasRef]); | ||
|
||
return <canvas ref={canvasRef} height={height} width={width} className={className} />; | ||
}; | ||
|
||
Canvas.defaultProps = { | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
draw: () => {}, | ||
className: '', | ||
}; | ||
|
||
export default Canvas; |
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,2 @@ | ||
.modalContainer { | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
src/pages/Projects/pages/FixedGearCalculator/components/BikeCanvas/index.tsx
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,45 @@ | ||
import React from 'react'; | ||
|
||
import Canvas from 'components/Canvas'; | ||
|
||
import styles from './styles.module.scss'; | ||
|
||
const BikeCanvas: React.FC = () => { | ||
const draw = (ctx: CanvasRenderingContext2D) => { | ||
const wheelPosX = 150; | ||
const wheelPosY = 150; | ||
|
||
// Tire | ||
ctx.beginPath(); | ||
ctx.strokeStyle = '#111111'; | ||
ctx.lineWidth = 7; | ||
ctx.arc(wheelPosX, wheelPosY, 120, 0, Math.PI * 2, true); | ||
ctx.stroke(); | ||
// Rim | ||
ctx.beginPath(); | ||
ctx.strokeStyle = '#888888'; | ||
ctx.lineWidth = 6; | ||
ctx.arc(wheelPosX, wheelPosY, 113, 0, Math.PI * 2, true); | ||
ctx.stroke(); | ||
// Radius | ||
ctx.strokeStyle = '#BBBBBB'; | ||
ctx.lineWidth = 1; | ||
for (var i = 0; i < 24; i++) { | ||
ctx.beginPath(); | ||
ctx.arc( | ||
wheelPosX, | ||
wheelPosX, | ||
110, | ||
i * ((Math.PI * 2) / 24), | ||
((i + 0.1) * Math.PI * 2) / 24, | ||
false | ||
); | ||
ctx.lineTo(wheelPosX, wheelPosX); | ||
ctx.stroke(); | ||
} | ||
}; | ||
|
||
return <Canvas width={500} height={300} draw={draw} className={styles.bikeCanvas} />; | ||
}; | ||
|
||
export default BikeCanvas; |
3 changes: 3 additions & 0 deletions
3
src/pages/Projects/pages/FixedGearCalculator/components/BikeCanvas/styles.module.scss
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,3 @@ | ||
.bikeCanvas { | ||
background-color: #9d9d9da3; | ||
} |
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,30 @@ | ||
import React from 'react'; | ||
|
||
import { Helmet } from 'react-helmet-async'; | ||
import { useTranslation } from 'react-i18next'; | ||
|
||
import { AppLayout } from 'layouts/AppLayout'; | ||
|
||
import BikeCanvas from './components/BikeCanvas'; | ||
import styles from './styles.module.scss'; | ||
|
||
const FixedGearCalculator: React.FC = () => { | ||
const { t } = useTranslation(); | ||
return ( | ||
<> | ||
<Helmet> | ||
<title> | ||
{t('projects.fgc.title')} | {process.env.REACT_APP_SITE_TITLE} | ||
</title> | ||
∆ </Helmet> | ||
<AppLayout className={`${styles.FGC} container`}> | ||
<div className={styles.container}> | ||
<h1>{t('projects.fgc.title')}</h1> | ||
</div> | ||
<BikeCanvas /> | ||
</AppLayout> | ||
</> | ||
); | ||
}; | ||
|
||
export default FixedGearCalculator; |
4 changes: 4 additions & 0 deletions
4
src/pages/Projects/pages/FixedGearCalculator/styles.module.scss
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,4 @@ | ||
.FGC { | ||
.container { | ||
} | ||
} |