diff options
author | lonkaars <loek@pipeframe.xyz> | 2021-07-01 12:09:08 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2021-07-01 12:09:08 +0200 |
commit | 57178786647aa290f797871000ad6bbe5b83fb83 (patch) | |
tree | 5b92651966db52d2596380360f344a7a8706f32a /pages | |
parent | 48e6be19588b7145fb5472c8b7b468e9dbfd7c77 (diff) |
fix #5
Diffstat (limited to 'pages')
-rw-r--r-- | pages/editor.tsx | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/pages/editor.tsx b/pages/editor.tsx index 6a283d5..c162e25 100644 --- a/pages/editor.tsx +++ b/pages/editor.tsx @@ -665,6 +665,35 @@ function getGhostParams(x: number, y: number, ox?: number, oy?: number) { return springValues; } +function divs(int: number) { + var divvable: number[] = []; + for (let i = 0; i < int; i++) { + if (int % i == 0) { + divvable.push(i); + } + } + return divvable; +} + +function getMarkerSpacing() { + var zoom = global.timeline.zoom.value; + var frameWidth = zoomToPx(zoom); + var divvable = divs(Math.round(project.timeline.framerate.value)); + if (divvable.length == 0) return 30; + var minSpacing = 120; + var multiply = 1; + var spacing: number; + + while (!spacing) { + var spacings = divvable.filter(i => (i * frameWidth * multiply) >= minSpacing); + spacing = spacings[spacings.length - 1]; + if (spacing) break; + multiply++; + } + console.log(spacing); + return spacing * multiply; +} + function TimelineEditor() { var timelineZoom = useHookstate(global).timeline.zoom; var workingTimeline = useHookstate(global).timeline.workingTimeline; @@ -734,8 +763,7 @@ function TimelineEditor() { var d = false; var a = 0; - var ns = [300, 150, 120, 90, 60, 30, 30, 30, 15, 15, 10, 10, 10]; - var everyN = ns[Math.floor(frameWidth)]; + var everyN = getMarkerSpacing(); for (var x = -offset; x < canvas.width + offset; x += frameWidth) { ctx.fillStyle = baseColor; |