From 57178786647aa290f797871000ad6bbe5b83fb83 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Thu, 1 Jul 2021 12:09:08 +0200 Subject: fix #5 --- pages/editor.tsx | 32 ++++++++++++++++++++++++++++++-- 1 file 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; -- cgit v1.2.3