From e98b645ac4f317787c4aceb50fb700ea86db52c5 Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Thu, 22 Jul 2021 15:55:42 +0200 Subject: finished basis for physics tweaks --- pages/index.tsx | 384 +++++++++++++++++++++----------------------------------- 1 file changed, 140 insertions(+), 244 deletions(-) (limited to 'pages/index.tsx') diff --git a/pages/index.tsx b/pages/index.tsx index dcdb225..d39a153 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -189,94 +189,104 @@ export function GraphPage() { ) } -export interface TweakProps { - physics: typeof initialPhysics - setPhysics: any - threeDim: boolean - local: boolean +export interface InfoTooltipProps { + infoText?: string | boolean } - -export const Tweaks = function (props: TweakProps) { - const { physics, setPhysics, threeDim, local } = props - - interface InfoTooltipProps { - infoText: string - } - const InfoTooltip = (props: InfoTooltipProps) => { - const { infoText } = props - return ( - - - - +export const InfoTooltip = (props: InfoTooltipProps) => { + const { infoText } = props + return ( + + + + + + ) +} +export interface SliderWithInfoProps { + min?: number + max?: number + step?: number + value: number + onChange: (arg0: number) => void + label: string + infoText?: string +} +export const SliderWithInfo = ({ + min = 0, + max = 10, + step = 0.1, + value = 1, + ...rest +}: SliderWithInfoProps) => { + const { onChange, label, infoText } = rest + return ( + + + {label} + {infoText && } - ) - } + + + + + + + + + + ) +} - interface SliderWithInfo { - min: number - max: number - step: number - value: number - onChange: (arg0: number) => void - label: string - infoText: string - } +export interface EnableSliderProps extends SliderWithInfoProps { + enableValue: boolean + onEnableValueChange: () => void + enableLabel: string + enableInfoText?: string | boolean +} - const SliderWithInfo = (props: SliderWithLabel) => { - const { min, max, step, value, onChange, label, infoText } = props - return ( - +export const EnableSlider = ({ min = 0, max = 10, step = 0.1, ...rest }: EnableSliderProps) => { + const { + value, + onChange, + label, + infoText, + enableValue, + onEnableValueChange, + enableInfoText, + enableLabel, + } = rest + return ( + + - {label} - + {enableLabel} + {enableInfoText && } - - - - - - - - + - ) - } - - interface SliderWithoutInfo { - min: number - max: number - step: number - val: number - change: (arg0: number) => void - label: string - physics: typeof initialPhysics - setPhysics: any - } - - const SliderWithoutInfo = (props: SliderWithoutInfo) => { - const { min, max, step, physics, setPhysics, label } = props - return ( - - - {label} - - setPhysics({ ...physics, gravity: value })} + {enableValue && ( + - - - - - - - ) - } + label={label} + infoText={infoText} + /> + )} + + ) +} + +export interface TweakProps { + physics: typeof initialPhysics + setPhysics: any + threeDim: boolean + local: boolean +} +export const Tweaks = function (props: TweakProps) { + const { physics, setPhysics, threeDim, local } = props return ( @@ -310,59 +320,21 @@ export const Tweaks = function (props: TweakProps) { divider={} align="stretch" > - - - Gravity - setPhysics({ ...physics, gravityOn: !physics.gravityOn })} - isChecked={physics.gravityOn} - /> - - {physics.gravityOn && ( - - Strength - setPhysics({ ...physics, gravity: value })} - min={0} - max={1} - step={0.01} - > - - - - - - - - - )} - - + setPhysics({ ...physics, gravityOn: !physics.gravityOn }) + } + label="Strength" + value={physics.gravity * 10} + onChange={(v) => setPhysics({ ...physics, gravity: v / 10 })} + /> + setPhysics({ ...physics, charge: -100 * value })} + label="Repulsive Force" /> - - Repulsive Force - setPhysics({ ...physics, charge: -value })} - min={0} - max={1000} - > - - - - - - - - @@ -376,79 +348,32 @@ export const Tweaks = function (props: TweakProps) { /> {physics.collision && ( - - Strength - setPhysics({ ...physics, collisionStrength: value })} - min={0} - max={2} - > - - - - - - - - + setPhysics({ ...physics, collisionStrength: value / 10 })} + label="Strength" + /> )} - - Link Strength - setPhysics({ ...physics, linkStrength: value })} - min={0} - max={2} - step={0.01} - > - - - - - - - - - - - - Link Iterations - - - setPhysics({ ...physics, linkIts: value })} - min={0} - max={6} - step={1} - > - - - - - - - - - - Viscosity - setPhysics({ ...physics, velocityDecay: value })} - min={0} - max={1} - step={0.01} - > - - - - - - - - + setPhysics({ ...physics, linkStrength: value / 5 })} + label="Link Force" + /> + setPhysics({ ...physics, linkIts: value })} + min={0} + max={6} + step={1} + infoText="How many links down the line the physics of a single node affects (Slow)" + /> + setPhysics({ ...physics, velocityDecay: value / 10 })} + /> @@ -464,49 +389,20 @@ export const Tweaks = function (props: TweakProps) { divider={} align="stretch" > - - Simulation Ticks - - - - - - - - - - - Alpha Decay - setPhysics({ ...physics, alphaDecay: value })} - min={0} - max={1} - step={0.01} - > - - - - - - - - - Alpha Minimum - setPhysics({ ...physics, alphaMin: value })} - min={0.01} - max={1} - step={0.01} - > - - - - - - - + setPhysics({ ...physics, iterations: v })} + infoText="Number of times the physics simulation iterates per simulation step" + /> + setPhysics({ ...physics, alphaDecay: value / 50 })} + /> -- cgit v1.2.3