-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from tsaxking/chore-update-scripts-to-27051fcd…
…9f8cd70f3942b348534e33f8ec2a315f Chore update scripts to 27051fc
- Loading branch information
Showing
21 changed files
with
411 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import '../../utilities/imports'; | ||
import SignIn from '../../views/components/SignIn.svelte'; | ||
|
||
new SignIn({ | ||
target: document.body, | ||
props: { | ||
title: document.title, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import '../../utilities/imports'; | ||
import SignUp from '../../views/components/SignUp.svelte'; | ||
new SignUp({ | ||
target: document.body, | ||
props: { | ||
title: document.title, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
import './../../utilities/imports'; | ||
import { Canvas } from '../../models/canvas/canvas'; | ||
import { Path } from '../../models/canvas/path'; | ||
import { Circle } from '../../models/canvas/circle'; | ||
import { Point } from '../../../shared/submodules/calculations/src/linear-algebra/point'; | ||
import { Color } from '../../submodules/colors/color'; | ||
import { Spline as S } from '../../../shared/submodules/calculations/src/linear-algebra/spline'; | ||
import { DrawableEvent } from '../../models/canvas/drawable'; | ||
import { Spline } from '../../models/canvas/spline'; | ||
import { downloadText } from '../../utilities/downloads'; | ||
|
||
const canvas = document.createElement('canvas'); | ||
document.body.appendChild(canvas); | ||
document.body.classList.add('bg-dark', 'p-0', 'no-scroll', 'position-relative'); | ||
|
||
const resetBtn = document.createElement('button'); | ||
resetBtn.classList.add( | ||
'btn', | ||
'btn-secondary', | ||
'position-absolute', | ||
'top-0', | ||
'start-0', | ||
'm-2', | ||
); | ||
resetBtn.innerText = 'Reset'; | ||
document.body.appendChild(resetBtn); | ||
|
||
const downloadBtn = document.createElement('button'); | ||
downloadBtn.classList.add( | ||
'btn', | ||
'btn-secondary', | ||
'position-absolute', | ||
'top-0', | ||
'end-0', | ||
'm-2', | ||
); | ||
downloadBtn.innerText = 'Download JSON'; | ||
document.body.appendChild(downloadBtn); | ||
|
||
const ctx = canvas.getContext('2d'); | ||
if (!ctx) throw new Error('Canvas context is null'); | ||
|
||
const c = new Canvas(ctx, { | ||
events: [ | ||
'click', | ||
'mousedown', | ||
'mouseup', | ||
'mousemove', | ||
'mouseleave', | ||
'touchstart', | ||
'touchend', | ||
'touchmove', | ||
'touchcancel', | ||
], | ||
}); | ||
|
||
const stop = () => (c.$animating = false); | ||
|
||
const spline = new S(); | ||
|
||
const start = () => { | ||
c.destroy(); | ||
|
||
const paths = { | ||
y1: new Path([ | ||
[0, 0], | ||
[0, 1], | ||
]), | ||
'y0.25': new Path([ | ||
[0.25, 0], | ||
[0.25, 1], | ||
]), | ||
'y0.5': new Path([ | ||
[0.5, 0], | ||
[0.5, 1], | ||
]), | ||
'y0.75': new Path([ | ||
[0.75, 0], | ||
[0.75, 1], | ||
]), | ||
y0: new Path([ | ||
[1, 0], | ||
[1, 1], | ||
]), | ||
x1: new Path([ | ||
[0, 0], | ||
[1, 0], | ||
]), | ||
'x0.25': new Path([ | ||
[0, 0.25], | ||
[1, 0.25], | ||
]), | ||
'x0.5': new Path([ | ||
[0, 0.5], | ||
[1, 0.5], | ||
]), | ||
'x0.75': new Path([ | ||
[0, 0.75], | ||
[1, 0.75], | ||
]), | ||
x0: new Path([ | ||
[0, 1], | ||
[1, 1], | ||
]), | ||
}; | ||
|
||
c.add( | ||
...Object.values(paths).map((p) => { | ||
p.$properties.line = { | ||
color: Color.fromBootstrap('gray').toString('rgba'), | ||
width: 1, | ||
}; | ||
return p; | ||
}), | ||
); | ||
|
||
spline.points = new Array(10).fill(0).map((_, i, a) => { | ||
return new Point(i / a.length, 1 - i / a.length); | ||
}); | ||
|
||
const circles = spline.points.map((_, i, a) => { | ||
const cir = new Circle([i / a.length, 1 - i / a.length], 0.02); | ||
cir.$properties.fill = { | ||
color: Color.fromBootstrap('primary').toString('rgba'), | ||
}; | ||
|
||
let dragging = false; | ||
const start = () => (dragging = true); | ||
const end = () => (dragging = false); | ||
|
||
const move = (e: DrawableEvent) => { | ||
if (!dragging) return; | ||
cir.center = e.points[0]; | ||
spline.points[i].x = e.points[0][0]; | ||
spline.points[i].y = e.points[0][1]; | ||
}; | ||
|
||
cir.on('mousedown', start); | ||
cir.on('touchstart', start); | ||
cir.on('mouseup', end); | ||
cir.on('touchend', end); | ||
cir.on('mousemove', move); | ||
cir.on('touchmove', move); | ||
|
||
return cir; | ||
}); | ||
|
||
const s = new Spline(spline, { | ||
frames: 1000, | ||
}); | ||
|
||
spline.magnitude = 5; | ||
|
||
s.$properties.line = { | ||
color: Color.fromBootstrap('primary').toString('rgba'), | ||
width: 2, | ||
}; | ||
|
||
c.add(...circles, s); | ||
|
||
return c.animate(); | ||
}; | ||
|
||
const reset = () => { | ||
stop(); | ||
start(); | ||
}; | ||
|
||
resetBtn.onclick = reset; | ||
downloadBtn.onclick = () => { | ||
downloadText( | ||
JSON.stringify( | ||
new Array(1000).fill(0).map((_, i) => spline.ft(i / 1000)), | ||
), | ||
'spline.json', | ||
); | ||
}; | ||
|
||
start(); | ||
|
||
const setView = () => { | ||
c.width = window.innerWidth; | ||
c.height = window.innerHeight; | ||
}; | ||
|
||
setView(); | ||
|
||
window.onresize = setView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { copy } from '../../../shared/copy'; | ||
import { Color } from '../../submodules/colors/color'; | ||
import { Drawable } from './drawable'; | ||
|
||
export class Background extends Drawable<Background> { | ||
get color() { | ||
return Color.parse(this.$properties.fill?.color || 'white'); | ||
} | ||
|
||
set color(value: Color) { | ||
this.$properties.fill = { | ||
color: value.toString('rgba'), | ||
}; | ||
} | ||
|
||
draw(ctx: CanvasRenderingContext2D) { | ||
const { width, height } = ctx.canvas; | ||
ctx.fillStyle = this.color.toString('rgba'); | ||
ctx.fillRect(0, 0, width, height); | ||
} | ||
|
||
isIn(_point: [number, number]): boolean { | ||
return true; | ||
} | ||
|
||
clone(): Background { | ||
const b = new Background(); | ||
b.color = this.color; | ||
copy(this, b); | ||
return b; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Point } from '../../../shared/submodules/calculations/src/linear-algebra/point'; | ||
import { Drawable } from './drawable'; | ||
|
||
export class Sphere extends Drawable<Sphere> { | ||
constructor( | ||
public readonly center: Point, | ||
public readonly radius: number, | ||
) { | ||
super(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { Drawable } from './drawable'; | ||
import { Spline as S } from '../../../shared/submodules/calculations/src/linear-algebra/spline'; | ||
|
||
type SplineOptions = { | ||
frames: number; | ||
}; | ||
|
||
export class Spline extends Drawable<Spline> { | ||
constructor( | ||
public readonly spline: S, | ||
public readonly options: Partial<SplineOptions> = {}, | ||
) { | ||
super(); | ||
} | ||
|
||
isIn(_point: [number, number]): boolean { | ||
return false; | ||
} | ||
|
||
draw(ctx: CanvasRenderingContext2D) { | ||
const { width, height } = ctx.canvas; | ||
ctx.fillStyle = this.$properties.fill?.color || 'black'; | ||
ctx.strokeStyle = this.$properties.line?.color || 'black'; | ||
|
||
ctx.beginPath(); | ||
const { x, y } = this.spline.ft(0); | ||
ctx.moveTo(x * width, y * height); | ||
|
||
const frames = this.options.frames || 100; | ||
for (let i = 1; i <= frames; i++) { | ||
const { x, y } = this.spline.ft(i / frames); | ||
ctx.lineTo(x * width, y * height); | ||
} | ||
ctx.stroke(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.