|
1 | 1 | 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; |
10 | 55 | } |
11 | 56 | return dialDisplay; |
12 | 57 | } |
13 | 58 |
|
14 | 59 | let options = {}; |
15 | 60 | let dialDisplay = dialDisplayGenerator(options); |
16 | | -let value = 0; |
17 | 61 |
|
18 | 62 | let cb = (step)=>{ |
19 | 63 | print(step); |
20 | | - value = dialDisplay(step, value); |
| 64 | + dialDisplay(step); |
21 | 65 | }; |
22 | 66 |
|
23 | 67 | let dial = require("Dial")(cb); |
|
0 commit comments