website

source code for the ttmaths.uk website
Log | Files | Refs | README

commit d9bad3246a1fa419b25ba4e50d8a5bbd47705d30
parent 9a8482f64e0abf7fdf3c1fb03647973c9cd46fb1
Author: fen123456 <fenwthompson@gmail.com>
Date:   Sat, 15 Aug 2026 15:17:08 +0100

Merge branch 'main' of https://github.com/hrryt/website

Diffstat:
Asrc/components/plotting/Sinusoid.jsx | 25+++++++++++++++++++++++++
Msrc/pages/Home.jsx | 4+++-
Msrc/scripts/utils.js | 5++---
3 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/src/components/plotting/Sinusoid.jsx b/src/components/plotting/Sinusoid.jsx @@ -0,0 +1,25 @@ +import Point from './Point.jsx'; +import { getColourClass, trueMod } from '../../scripts/utils.js'; + +export default function Sinusoid({ period=1, amp=1, dx=0, dy=0, colour="auto", viewBox }) { + const [minX, minY, width, height] = viewBox; + + const offset = trueMod(minX - dx, period); + const x0 = minX - offset; + const periods = Math.ceil((width + offset) / period); + + const magicNumber = 0.3642124232; + const halfPeriod = period / 2; + + const dx1 = halfPeriod * magicNumber; + const dx2 = halfPeriod * (1 - magicNumber); + + const h = 2*amp; + + const wave = ` + c ${dx1},0 ${dx2},${-h} ${halfPeriod},${-h} + c ${dx1},0 ${dx2},${+h} ${halfPeriod},${+h} + `; + + return <path d={`M ${x0},${amp+dy}${wave.repeat(periods)}`} class={getColourClass(colour)} />; +} diff --git a/src/pages/Home.jsx b/src/pages/Home.jsx @@ -8,6 +8,7 @@ import Segment from '../components/plotting/Segment.jsx'; import Line from '../components/plotting/Line.jsx'; import Point from '../components/plotting/Point.jsx'; import Label from '../components/plotting/Label.jsx'; +import Sinusoid from '../components/plotting/Sinusoid.jsx'; export default function Home() { const viewBox = [-5, -4, 8, 8]; @@ -21,8 +22,9 @@ export default function Home() { <Quadratic a={2} b={1} c={-3} colour="1" viewBox={viewBox} /> <Polygon points={[[1,2], [-1,1], [-4,3]]} label="P" colour="2" /> <Cubic a={1} b={-3} c={3} d={-1} colour="3" viewBox={viewBox} /> + <Point point={[1,0]} label="Q" colour="3" /> <Line line={{a: -10, b: -9, c: -1}} colour="4" viewBox={viewBox} /> - <Point point={[0,1]} label="Q" colour="5" /> + <Sinusoid period={5} amp={0.5} dx={-11} dy={-2} colour="5" viewBox={viewBox} /> </Plot> <Plot mode="blank" viewBox={[0, 0, 5, 5]}> <Label point={A} position="top">A</Label> diff --git a/src/scripts/utils.js b/src/scripts/utils.js @@ -109,5 +109,5 @@ export function getMidpoint(points) { export function trueMod(a, b) { // a mod b, but with expected behaviour for negatives. - return a >= 0 ? a % b : b - (-a % b) -} -\ No newline at end of file + return a >= 0 ? a % b : b - ((-a % b) || b); +}