Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
dkreft committed Dec 27, 2022
1 parent e78804b commit 414263c
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 18 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
</head>
Expand Down
1 change: 0 additions & 1 deletion public/vite.svg

This file was deleted.

1 change: 0 additions & 1 deletion src/assets/react.svg

This file was deleted.

32 changes: 26 additions & 6 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ import Styles from './styles.module.sass'

const PARAMS = new URLSearchParams(window.location.search)

const DIRECTION = 0
const DEFAULTS = {
length: 500,
limit: 5,
ratio: 0.5,
shiftAngle: 60,
}
const LENGTH = 500
const LIMIT = Math.pow(2, 5) + 7
const RATIO = 0.5
Expand All @@ -21,12 +26,14 @@ const SHIFT_ANGLE = 60


export default function App() {
// console.log(getDefaultState())
const count = React.useRef(0)

const [state, setState] = useState({
direction: Number(PARAMS.get('direction') || DIRECTION),
length: Number(PARAMS.get('length') || LENGTH),
limit: Number(PARAMS.get('limit') || LIMIT),
ratio: Number(PARAMS.get('ratio') || RATIO),
shiftAngle: Number(PARAMS.get('shiftAngle') || SHIFT_ANGLE),
length: getNumParam('length', LENGTH),
limit: getNumParam('limit', LIMIT),
ratio: getNumParam('ratio', RATIO),
shiftAngle: getNumParam('shiftAngle', SHIFT_ANGLE),
})

const handleChange = useCallback(({ name, value }) => {
Expand All @@ -52,3 +59,16 @@ export default function App() {
</div>
)
}

function getDefaultState() {
return Object
.entries(DEFAULTS)
.reduce((defaults, [key, value]) => ({
...defaults,
[key]: getNumParam(key, value),
}), {})
}

function getNumParam(name, defaultValue) {
return Number(PARAMS.get(name)) || defaultValue
}
8 changes: 0 additions & 8 deletions src/components/App/Fractal/Fractal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,6 @@ import Styles from './styles.module.sass'


export default function Fractal(props) {
const {
direction,
length,
limit,
ratio,
shiftAngle,
} = props

const ref = useRef()

const canvasSize = useSize(ref)
Expand Down
5 changes: 5 additions & 0 deletions src/components/App/Fractal/lib/fractal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ export default function drawFractal(canvas, opts = {}) {
})
]

let count = 0
while ( shapesToDraw.length ) {
const shape = shapesToDraw.shift()

lengths.add(shape.length)

drawPolygon(ctx, shape, STROKE_COLOR)
++count

if ( lengths.size >= opts.limit ) {
continue
Expand Down Expand Up @@ -65,6 +67,9 @@ export default function drawFractal(canvas, opts = {}) {
shapesToDraw.push(child)
}
}

console.log('Shapes drawn: %o', count)
return count
}

function makeContext(canvas) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ a:hover {

body {
margin: 0;
lace-items: center;
place-items: center;
height: 100%;
width: 100%;
}
Expand Down
1 change: 1 addition & 0 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
base: '',
plugins: [react()]
})

0 comments on commit 414263c

Please sign in to comment.