Skip to content

Commit 4c1624f

Browse files
author
Oskar Widmark
committed
fix: add gaps to spiral
1 parent fa2f500 commit 4c1624f

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

TODO.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Features:
44
- [x] Parallelization for algorithms
55
- [ ] Merge sort
66
- [x] 2D color matrix visualization
7-
- [ ] Spiral visualization
7+
- [x] Spiral visualization
88
- [x] Highlight color based on action type
99
- [x] Mobile browser support
1010

src/canvas-controller.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { MAX_ANGLE_GAP_FACTOR } from './constants';
12
import {
23
ColorPreset,
34
ColorSettings,
@@ -398,14 +399,20 @@ export class CanvasController {
398399
(maxRadius / (this.context.columnNbr + 1)) * (arr[i].value + 1);
399400
const startAngle = anglePerColumn * i;
400401
const endAngle = anglePerColumn * (i + 1);
402+
const gap =
403+
(anglePerColumn *
404+
this.context.gapSize *
405+
arr[i].value *
406+
MAX_ANGLE_GAP_FACTOR) /
407+
this.context.columnNbr;
401408

402409
this.canvas2dCtx.fillStyle = color || this.getColumnColor(arr[i].value);
403410
this.canvas2dCtx.beginPath();
404411
this.canvas2dCtx.arc(
405412
centerX,
406413
centerY,
407414
this.snap(radius),
408-
startAngle,
415+
startAngle + gap,
409416
endAngle,
410417
);
411418
this.canvas2dCtx.lineTo(centerX, centerY);

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
export const RAINBOW_BACKGROUND_COLOR = '#282c34';
1313
export const DEFAULT_SOUND_VOLUME = 50;
1414
export const DEFAULT_SOUND_TYPE = 'triangle';
15+
export const MAX_ANGLE_GAP_FACTOR = 0.05;
1516

1617
export const INIT_STATE: Omit<AppState, 'settings'> = {
1718
isSorting: false,

src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export const sleep = (ms: number, counter: number) => {
5050
return new Promise((resolve) => setTimeout(resolve, ms));
5151
};
5252

53-
// something that sounds good
5453
export const toHz = (
5554
value: number,
5655
columnNbr: number,

0 commit comments

Comments
 (0)