import React, { useState } from "react"; import { Checkbox } from "../checkbox"; import { mixColor } from "../color-util"; import { ColorWidget } from "../color-widget"; import { NumericSlider } from "../numeric-slider"; import { Page } from "../page"; import { Random } from "../random"; import { lerp, range } from "../util"; const WAVE_STROKE = "#79beda"; const WAVE_FILL = "#2b7c9e"; const Wave: React.FC<{ stroke: string; fill: string; }> = ({ stroke, fill }) => ( <> {/* Generator: Moho 13.0.3 build 635 */} ); const BG_COLOR = "#FFFFFF"; const BG_MAX_BLEND = 0.33; const NUM_WAVES = 10; const WAVE_DURATION = 1; const WAVE_PARALLAX_SCALE_START = 1.2; const WAVE_PARALLAX_TRANSLATE_START = 10; const WAVE_PARALLAX_SCALE_VELOCITY = 1.25; const WAVE_PARALLAX_TRANSLATE_VELOCITY = 30; const WAVE_PARALLAX_TRANSLATE_ACCEL = 10; type HillProps = { idPrefix: string; xScale: number; yScale: number; cx: number; cy: number; r: number; highlight: string; shadow: string; }; const DEFAULT_HILL_PROPS: HillProps = { idPrefix: "", xScale: 1, yScale: 1, cx: 50, cy: 50, r: 50, highlight: "#aeb762", shadow: "#616934", }; const Hill: React.FC> = (props) => { const { idPrefix, xScale, yScale, cx, cy, r, highlight, shadow } = { ...DEFAULT_HILL_PROPS, ...props, }; const gradientId = `${idPrefix}HillGradient`; const gradientUrl = `url(#${gradientId})`; return ( ); }; const Waves: React.FC<{}> = () => { const [randomSeed, setRandomSeed] = useState(Date.now()); const newRandomSeed = () => setRandomSeed(Date.now()); const rng = new Random(randomSeed); const [stroke, setStroke] = useState(WAVE_STROKE); const [fill, setFill] = useState(WAVE_FILL); const [numWaves, setNumWaves] = useState(NUM_WAVES); const [duration, setDuration] = useState(WAVE_DURATION); const [initialYVel, setInitialYVel] = useState( WAVE_PARALLAX_TRANSLATE_VELOCITY ); const [showHills, setShowHills] = useState(false); const [yAccel, setYAccel] = useState(WAVE_PARALLAX_TRANSLATE_ACCEL); const [scaleVel, setScaleVel] = useState(WAVE_PARALLAX_SCALE_VELOCITY); const [useMask, setUseMask] = useState(false); let scale = WAVE_PARALLAX_SCALE_START; let y = WAVE_PARALLAX_TRANSLATE_START; let yVel = initialYVel; let waves: JSX.Element[] = []; for (let i = 0; i < numWaves; i++) { const numHills = Math.floor(rng.inInterval({ min: 0, max: numWaves - i })); const hazeAmt = lerp( 0, BG_MAX_BLEND, // The furthest-away waves (the first ones we draw) should be the // most hazy. Scale the amount quadratically so that the waves in // front tend to be less hazy. Math.pow(1 - i / Math.max(numWaves - 1, 1), 2) ); const blendedFill = mixColor(fill, BG_COLOR, hazeAmt); const blendedStroke = mixColor(stroke, BG_COLOR, hazeAmt); waves.push( {showHills && range(numHills).map((j) => { return ( ); })} ); y += yVel; scale *= scaleVel; yVel += yAccel; } return ( <>
{useMask ? ( <> {waves} ) : ( waves )}
{" "}
{showHills && ( )}
); }; export const WavesPage: React.FC<{}> = () => ( );