Skip to content

Commit 9445bf4

Browse files
author
thyttan
committed
Dial_Display: WIP generate a function drawing the dial
1 parent 0d7fb84 commit 9445bf4

File tree

1 file changed

+54
-10
lines changed

1 file changed

+54
-10
lines changed

modules/Dial_Display.js

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,67 @@
11
let dialDisplayGenerator = function(options) {
2-
3-
let dialDisplay = function(step, previousValue) {
4-
if (!previousValue) previousValue = 0;
5-
let currentValue = previousValue + step;
6-
g.clear().reset().setFont("Vector:30");
7-
g.drawString(currentValue);
8-
9-
return currentValue;
2+
"ram";
3+
const SCREEN_W = g.getWidth();
4+
const SCREEN_H = g.getHeight();
5+
6+
options = Object.assign(
7+
{ stepsPerWholeTurn : 7, // 7 chosen as it felt the best in use.
8+
dialRect : {
9+
x: 0,
10+
y: 0,
11+
w: SCREEN_W,
12+
h: SCREEN_H,
13+
},
14+
}, options);
15+
16+
const DIAL_RECT = options.dialRect;
17+
18+
const CENTER = {
19+
x: DIAL_RECT.x + DIAL_RECT.w / 2,
20+
y: DIAL_RECT.y + DIAL_RECT.h / 2,
21+
};
22+
23+
let dialDisplay = function(step, value) {
24+
let prevValue = this.value;
25+
if (value) this.value = value;
26+
if (!this.value) this.value = 0;
27+
if (this.isFirstDraw===undefined) this.isFirstDraw = true;
28+
this.value += step;
29+
//g.setFont("Vector:30");
30+
//g.drawString(this.value);
31+
32+
let drawCircle = (value, R, G, B, rad, isFill)=>{
33+
let x = CENTER.x+27*Math.sin(value*(2*Math.PI/options.stepsPerWholeTurn));
34+
let y = CENTER.y-27*Math.cos(value*(2*Math.PI/options.stepsPerWholeTurn));
35+
g.setColor(R,G,B)
36+
if (!isFill) g.drawCircle(x, y, rad);
37+
if (isFill) g.fillCircle(x, y, rad);
38+
}
39+
if (this.isFirstDraw) {
40+
g.clear();
41+
g.setColor(1,1,1).drawCircle(CENTER.x, CENTER.y, 25);
42+
for (let i=0; i<options.stepsPerWholeTurn; i++) {
43+
drawCircle(i, 1, 1, 1, 1, true);
44+
}
45+
this.isFirstDraw = false;
46+
}
47+
48+
//drawCircle(this.value, 1, 1, 1, 2, false);
49+
//drawCircle(prevValue, 0, 0, 0, 2, false);
50+
g.setColor(1,1,1).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(this.value*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(this.value*(2*Math.PI/options.stepsPerWholeTurn)));
51+
g.setColor(0,0,0).drawLine(CENTER.x, CENTER.y, CENTER.x+23*Math.sin(prevValue*(2*Math.PI/options.stepsPerWholeTurn)), CENTER.y-23*Math.cos(prevValue*(2*Math.PI/options.stepsPerWholeTurn)));
52+
g.setColor(0,0,0).fillCircle(CENTER.x, CENTER.y, 9);
53+
54+
return this.value;
1055
}
1156
return dialDisplay;
1257
}
1358

1459
let options = {};
1560
let dialDisplay = dialDisplayGenerator(options);
16-
let value = 0;
1761

1862
let cb = (step)=>{
1963
print(step);
20-
value = dialDisplay(step, value);
64+
dialDisplay(step);
2165
};
2266

2367
let dial = require("Dial")(cb);

0 commit comments

Comments
 (0)