-
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
Showing
7 changed files
with
156 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,54 @@ | ||
import React from 'react' | ||
import React, { | ||
useCallback, | ||
useState, | ||
} from 'react' | ||
|
||
import PropTypes from 'prop-types' | ||
|
||
import Controls from './Controls' | ||
import Fractal from './Fractal' | ||
|
||
import Styles from './styles.module.sass' | ||
|
||
const PARAMS = new URLSearchParams(window.location.search) | ||
|
||
const DIRECTION = 0 | ||
const LENGTH = 500 | ||
const LIMIT = Math.pow(2, 5) + 7 | ||
const RATIO = 0.5 | ||
const SHIFT_ANGLE = 60 | ||
|
||
|
||
|
||
export default function App() { | ||
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), | ||
}) | ||
|
||
const handleChange = useCallback(({ name, value }) => { | ||
setState((oldState) => ({ | ||
...oldState, | ||
[name]: Number(value), | ||
})) | ||
}, [setState]) | ||
|
||
return ( | ||
<div className={ Styles.root }> | ||
<Fractal /> | ||
<Fractal | ||
direction={ state.direction } | ||
length={ state.length } | ||
limit={ state.limit } | ||
ratio={ state.ratio } | ||
shiftAngle={ state.shiftAngle } | ||
/> | ||
<Controls | ||
handleChange={ handleChange } | ||
state={ state } | ||
/> | ||
</div> | ||
) | ||
} |
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,71 @@ | ||
import React, { | ||
useCallback, | ||
} from 'react' | ||
|
||
import PropTypes from 'prop-types' | ||
|
||
import Styles from './styles.module.sass' | ||
|
||
|
||
export default function Controls({ handleChange, state }) { | ||
const onChange = useCallback((e) => { | ||
e.stopPropagation() | ||
e.preventDefault() | ||
|
||
handleChange({ | ||
name: e.target.name, | ||
value: e.target.value, | ||
}) | ||
}, [handleChange]) | ||
|
||
return ( | ||
<div className={ Styles.root }> | ||
Angle: | ||
<input | ||
onChange={ onChange } | ||
type="number" | ||
name="shiftAngle" | ||
defaultValue={ state.shiftAngle } | ||
/> | ||
<br /> | ||
Direction: | ||
<input | ||
onChange={ onChange } | ||
type="number" | ||
name="direction" | ||
defaultValue={ state.direction } | ||
/> | ||
<br /> | ||
Limit: | ||
<input | ||
onChange={ onChange } | ||
type="number" | ||
name="limit" | ||
defaultValue={ state.limit } | ||
/> | ||
<br /> | ||
Length: | ||
<input | ||
onChange={ onChange } | ||
type="number" | ||
name="length" | ||
defaultValue={ state.length } | ||
step={ 10 } | ||
/> | ||
<br/> | ||
Ratio: | ||
<input | ||
onChange={ onChange } | ||
type="number" | ||
name="ratio" | ||
defaultValue={ state.ratio } | ||
step={ 0.01 } | ||
max={ 0.99 } | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
Controls.propTypes = { | ||
handleChange: PropTypes.func.isRequired, | ||
} |
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 @@ | ||
import Controls from './Controls' | ||
|
||
export default Controls |
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,11 @@ | ||
.root | ||
position: absolute | ||
padding: 1rem | ||
border: 1px solid black | ||
background: #ccc | ||
top: 0 | ||
right: 0 | ||
width: 20rem | ||
height: 10rem | ||
|
||
|
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 |
---|---|---|
@@ -1,7 +1,6 @@ | ||
.root | ||
height: 100% | ||
width: 100% | ||
border: 1px solid pink | ||
bottom: 0 | ||
top: 0 | ||
left: 0 | ||
|