2021-03-27 11:39:21 +00:00
|
|
|
import React, { useRef, useState } from "react";
|
2021-03-26 22:07:01 +00:00
|
|
|
import { AutoSizingSvg } from "../auto-sizing-svg";
|
|
|
|
import { getBoundingBoxCenter } from "../bounding-box";
|
2021-03-27 11:39:21 +00:00
|
|
|
import { ColorWidget } from "../color-widget";
|
|
|
|
import { DEFAULT_BG_COLOR } from "../colors";
|
|
|
|
import { ExportSvgButton } from "../export-svg";
|
2021-03-26 22:07:01 +00:00
|
|
|
import { HoverDebugHelper } from "../hover-debug-helper";
|
2021-03-27 11:39:21 +00:00
|
|
|
import { NumericSlider } from "../numeric-slider";
|
2021-03-26 22:07:01 +00:00
|
|
|
import { reversePoint } from "../point";
|
|
|
|
import {
|
|
|
|
createSvgSymbolContext,
|
|
|
|
SvgSymbolContent,
|
|
|
|
SvgSymbolContext,
|
|
|
|
SvgSymbolData,
|
|
|
|
} from "../svg-symbol";
|
2021-03-27 12:04:40 +00:00
|
|
|
import { SvgSymbolWidget } from "../svg-symbol-widget";
|
2021-03-26 22:07:01 +00:00
|
|
|
import {
|
|
|
|
svgRotate,
|
|
|
|
svgScale,
|
|
|
|
SvgTransforms,
|
|
|
|
svgTranslate,
|
|
|
|
} from "../svg-transform";
|
2021-03-27 12:04:40 +00:00
|
|
|
import { getSvgSymbol, SvgVocabulary } from "../svg-vocabulary";
|
2021-03-26 22:07:01 +00:00
|
|
|
import { SymbolContextWidget } from "../symbol-context-widget";
|
|
|
|
import { range } from "../util";
|
|
|
|
|
|
|
|
const EYE = getSvgSymbol("eye");
|
|
|
|
|
|
|
|
const MandalaCircle: React.FC<
|
|
|
|
{
|
|
|
|
data: SvgSymbolData;
|
|
|
|
radius: number;
|
|
|
|
numSymbols: number;
|
|
|
|
} & SvgSymbolContext
|
|
|
|
> = (props) => {
|
|
|
|
const center = getBoundingBoxCenter(props.data.bbox);
|
|
|
|
const degreesPerItem = 360 / props.numSymbols;
|
|
|
|
const symbol = (
|
|
|
|
<SvgTransforms
|
|
|
|
transforms={[
|
|
|
|
svgTranslate({ x: props.radius, y: 0 }),
|
|
|
|
svgTranslate(reversePoint(center)),
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
<SvgSymbolContent {...props} />
|
|
|
|
</SvgTransforms>
|
|
|
|
);
|
|
|
|
|
|
|
|
const symbols = range(props.numSymbols).map((i) => (
|
|
|
|
<SvgTransforms
|
|
|
|
key={i}
|
|
|
|
transforms={[svgRotate(degreesPerItem * i)]}
|
|
|
|
children={symbol}
|
|
|
|
/>
|
|
|
|
));
|
|
|
|
|
|
|
|
return <>{symbols}</>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const MandalaPage: React.FC<{}> = () => {
|
2021-03-27 11:39:21 +00:00
|
|
|
const svgRef = useRef<SVGSVGElement>(null);
|
|
|
|
const [bgColor, setBgColor] = useState(DEFAULT_BG_COLOR);
|
2021-03-27 12:04:40 +00:00
|
|
|
const [symbol, setSymbol] = useState(EYE);
|
2021-03-26 22:07:01 +00:00
|
|
|
const [symbolCtx, setSymbolCtx] = useState(createSvgSymbolContext());
|
2021-03-27 11:39:21 +00:00
|
|
|
const [radius, setRadius] = useState(400);
|
|
|
|
const [numSymbols, setNumSymbols] = useState(6);
|
2021-03-26 22:07:01 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<h1>Mandala!</h1>
|
2021-03-27 11:39:21 +00:00
|
|
|
<SymbolContextWidget ctx={symbolCtx} onChange={setSymbolCtx}>
|
|
|
|
<ColorWidget
|
|
|
|
label="Background"
|
|
|
|
id="bgColor"
|
|
|
|
value={bgColor}
|
|
|
|
onChange={setBgColor}
|
|
|
|
/>{" "}
|
|
|
|
</SymbolContextWidget>
|
|
|
|
<p>
|
2021-03-27 12:04:40 +00:00
|
|
|
<SvgSymbolWidget
|
|
|
|
label="Symbol"
|
|
|
|
value={symbol}
|
|
|
|
onChange={setSymbol}
|
|
|
|
choices={SvgVocabulary}
|
|
|
|
/>
|
2021-03-27 11:39:21 +00:00
|
|
|
<NumericSlider
|
|
|
|
id="radius"
|
|
|
|
label="Radius"
|
|
|
|
value={radius}
|
|
|
|
onChange={setRadius}
|
|
|
|
min={0}
|
|
|
|
max={1000}
|
|
|
|
step={1}
|
|
|
|
/>
|
|
|
|
<NumericSlider
|
|
|
|
id="symbols"
|
|
|
|
label="Numer of symbols"
|
|
|
|
value={numSymbols}
|
|
|
|
onChange={setNumSymbols}
|
|
|
|
min={1}
|
|
|
|
max={30}
|
|
|
|
step={1}
|
|
|
|
/>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<ExportSvgButton filename="mandala.svg" svgRef={svgRef} />
|
|
|
|
</p>
|
2021-03-26 22:07:01 +00:00
|
|
|
<HoverDebugHelper>
|
2021-03-27 11:39:21 +00:00
|
|
|
<AutoSizingSvg padding={20} ref={svgRef} bgColor={bgColor}>
|
2021-03-26 22:07:01 +00:00
|
|
|
<SvgTransforms transforms={[svgScale(0.5)]}>
|
|
|
|
<MandalaCircle
|
2021-03-27 12:04:40 +00:00
|
|
|
data={symbol}
|
2021-03-27 11:39:21 +00:00
|
|
|
radius={radius}
|
|
|
|
numSymbols={numSymbols}
|
2021-03-26 22:07:01 +00:00
|
|
|
{...symbolCtx}
|
|
|
|
/>
|
|
|
|
</SvgTransforms>
|
|
|
|
</AutoSizingSvg>
|
|
|
|
</HoverDebugHelper>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|