Skip to content

Commit

Permalink
feat(perturbation-theory): add deep zoom control to settings
Browse files Browse the repository at this point in the history
  • Loading branch information
JMaio committed Feb 16, 2021
1 parent b1ddfce commit c970135
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
12 changes: 4 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Grid, Switch, ThemeProvider } from '@material-ui/core';
import { Grid, ThemeProvider } from '@material-ui/core';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { useSpring } from 'react-spring';
import './App.css';
Expand Down Expand Up @@ -142,8 +142,8 @@ function App(): JSX.Element {
// <AnimatedTypography></AnimatedTypography>
// const AnimatedGrid = animated(Grid);

const [showDeep, setDeep] = useState(false);
const toggleDeep = () => setDeep((p) => !p);
// const [showDeep, setDeep] = useState(false);
// const toggleDeep = () => setDeep((p) => !p);

return (
<ThemeProvider theme={theme}>
Expand All @@ -167,10 +167,6 @@ function App(): JSX.Element {
position: 'absolute',
}}
>
<div style={{ position: 'absolute', zIndex: 10 }}>
<Switch onChange={toggleDeep} />
</div>

<CoordinateInterface
show={settings.showCoordinates}
mandelbrot={mandelbrotControls}
Expand All @@ -184,7 +180,7 @@ function App(): JSX.Element {
flexGrow: showMandelbrot ? 1 : 0, // percentFlex.m.interpolate((x) => x),
}}
>
{showDeep ? (
{settings.deepZoom ? (
<MandelbrotRendererDeep
controls={mandelbrotControls}
DPR={currentDPR}
Expand Down
18 changes: 13 additions & 5 deletions src/common/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ export type settingsDefinitionsType = {
useDPR: boolean;
useAA: boolean;
colour: RgbColor;
deepZoom: boolean;
};

export const defaultSettings = {
export const defaultSettings: settingsDefinitionsType = {
showMinimap: true,
showCrosshair: true,
showCoordinates: false,
Expand All @@ -24,9 +25,10 @@ export const defaultSettings = {
useDPR: false,
useAA: false,
colour: defaultShadingColour,
deepZoom: false,
};

export const defaultIterationLevels = [10, 250, 500, 750, 1000].map((i) => ({
export const defaultIterationLevels = [16, 250, 500, 750, 1000].map((i) => ({
value: i,
label: i,
}));
Expand All @@ -39,6 +41,7 @@ export const defaultIterationLevels = [10, 250, 500, 750, 1000].map((i) => ({
// }
// squares: 6^2, 20^2, 32^2...
// bad iteration levels: 6, 7, 12, 13, 14, 15, 24, 26, 28, 30
// 19 iteration levels:
export const perturbationIterationLevels = [
4,
5,
Expand All @@ -59,9 +62,14 @@ export const perturbationIterationLevels = [
29,
31,
32,
].map((i) => ({
value: i * i,
}));
]
.map((l) => l * l)
.map((l, i) => ({
value: l,
// only show the labels of the higher levels
// i+n to ensure that 18 is mod n
label: (i + 2) % 4 ? null : l,
}));

// export const perturbationIterationLevels = _.range(2, 33, 2)
// .map((i) => i * i)
Expand Down
22 changes: 19 additions & 3 deletions src/components/settings/SettingsDefinitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PhotoIcon from '@material-ui/icons/Photo';
import React from 'react';
import { RgbColorPicker } from 'react-colorful';
import {
defaultIterationLevels,
perturbationIterationLevels,
settingsDefinitionsType,
settingsGroupType,
Expand Down Expand Up @@ -54,9 +55,10 @@ and allows warping to specific coordinates
min={16}
max={1024}
// step={16}
step={null}
// increment by 16 if not in "deep mode"
step={settings.deepZoom ? null : 16}
marks={settings.deepZoom ? perturbationIterationLevels : defaultIterationLevels}
valueLabelDisplay="auto"
marks={perturbationIterationLevels}
/>
),
helptext: `
Expand Down Expand Up @@ -85,7 +87,7 @@ but **may reduce performance**.
useAA: {
label: `Anti-aliasing (slow)`,
checked: settings.useAA,
control: <Switch />,
control: <Switch color="secondary" />,
helptext: `
Anti-aliasing provides a smoothing effect which increases the quality of the image,
but can **severely reduce performance and crash the application**.
Expand Down Expand Up @@ -131,6 +133,19 @@ The top picker changes *Saturation* (horizontally) and *Value* (vertically).
The bottom picker changes *Hue*.
`,
},
deepZoom: {
label: `⚠️ Deep zoom`,
checked: settings.deepZoom,
control: <Switch color="secondary" />,
helptext: `
(Mandelbrot viewer only)
**This feature is experimental and could severely reduce performance, especially at high zoom levels.**
Uses perturbation theory to provide deeper zoom capability.
To obtain a usable result, move the "Iterations" slider so that it stops at a predefined level; changing the iteration count will slightly affect colouring.
Zooming into some regions may give almost no improvement over the standard method.
Regions closer to the origin will usually allow for deeper zoom without loss of quality.
`,
},
});

export const getSettingsWidgetsGrouping = (
Expand All @@ -155,6 +170,7 @@ export const getSettingsWidgetsGrouping = (
useDPR: settingsWidgets.useDPR,
useAA: settingsWidgets.useAA,
showFPS: settingsWidgets.showFPS,
deepZoom: settingsWidgets.deepZoom,
},
},
];

0 comments on commit c970135

Please sign in to comment.