💡 Add default fractal settings
This commit is contained in:
parent
9fb99b63ff
commit
eb689f452f
|
@ -7,12 +7,12 @@ import { applyChaos } from './chaos';
|
||||||
* Render a canvas element that draws a fractal out of a
|
* Render a canvas element that draws a fractal out of a
|
||||||
* given iterated function system
|
* given iterated function system
|
||||||
*/
|
*/
|
||||||
export class Fractal extends React.Component {
|
class Fractal extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
zoom: 200,
|
zoom: 30,
|
||||||
dragging: false,
|
dragging: false,
|
||||||
center: null,
|
center: null,
|
||||||
points: null
|
points: null
|
||||||
|
@ -158,10 +158,13 @@ export class Fractal extends React.Component {
|
||||||
this.ctx.putImageData(image, 0, 0);
|
this.ctx.putImageData(image, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is dirty. TODO: make it less coupled
|
/**
|
||||||
|
* Get the container size
|
||||||
|
*
|
||||||
|
* @return {Array} Width and height of the container
|
||||||
|
*/
|
||||||
getSize() {
|
getSize() {
|
||||||
const wrapping = document.querySelector('#content');
|
return [this.container.clientWidth, this.container.clientHeight];
|
||||||
return [wrapping.clientWidth, wrapping.clientHeight];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -223,12 +226,21 @@ export class Fractal extends React.Component {
|
||||||
* Create a canvas with correct listeners
|
* Create a canvas with correct listeners
|
||||||
*/
|
*/
|
||||||
render() {
|
render() {
|
||||||
return <canvas
|
return <div id="content" ref={div => this.container = div}>
|
||||||
|
<canvas
|
||||||
ref={canvas => this.ctx = canvas.getContext('2d')}
|
ref={canvas => this.ctx = canvas.getContext('2d')}
|
||||||
onWheel={this.wheel.bind(this)}
|
onWheel={this.wheel.bind(this)}
|
||||||
onMouseDown={this.mouseDown.bind(this)}
|
onMouseDown={this.mouseDown.bind(this)}
|
||||||
onMouseUp={this.mouseUp.bind(this)}
|
onMouseUp={this.mouseUp.bind(this)}
|
||||||
onMouseMove={this.mouseMove.bind(this)}
|
onMouseMove={this.mouseMove.bind(this)}
|
||||||
></canvas>;
|
></canvas>
|
||||||
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Fractal.defaultProps = {
|
||||||
|
iterations: 200000,
|
||||||
|
system: [[], []]
|
||||||
|
};
|
||||||
|
|
||||||
|
export { Fractal };
|
||||||
|
|
Loading…
Reference in New Issue