-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
99 lines (86 loc) · 2.01 KB
/
sketch.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
var pointA;
var pointB;
var pointC;
var d;
var dice;
var run = false;
var count = 0;
var fpsSlider;
var fpsLabel;
var fps = 30;
var fpsValue = fps;
function setup() {
var myCanvas = createCanvas(innerHeight-110,innerHeight-110);
myCanvas.parent('game');
myCanvas.position(innerWidth/2-width/2,50);
background(20);
stroke(255);
frameRate(fps);
//Create Triangle
pointA = createVector(width/2, 60);
pointB = createVector(60, height - 60);
pointC = createVector(width-60, height-60);
// Draw Triangle
strokeWeight(8);
point(pointA.x, pointA.y);
point(pointB.x, pointB.y);
point(pointC.x, pointC.y);
// Text around Triangle
noStroke();
fill(255);
textSize(24);
text("A", width/2-8, 40);
text("B", 30, height - 52);
text("C", width-40, height-52);
stroke(255);
// Slider
fpsLabel = createP(fpsValue);
fpsLabel.style("color", "white");
fpsLabel.position((innerWidth/2-120),innerHeight-40);
fpsSlider = createSlider(4,60,fps,2);
fpsSlider.position(innerWidth/2-300,innerHeight-40);
fpsSlider.style('width', '160px');
// Make new Dice
dice = new Dice;
d = new Dot;
// Status info
countLabel = select('#counter');
countLabel.html(nf(count,6,0));
diceLabel = select('#dice');
diceLabel.html("-");
startBtn = select('#start');
startBtn.position(innerWidth/2-60, 10)
startBtn.mousePressed(toggleRun);
restartBtn = select('#restart');
restartBtn.position(innerWidth/2, 10)
restartBtn.mousePressed(restartGame);
}
function draw() {
//Make new Dot;
var fps = fpsSlider.value();
frameRate(fps);
fpsLabel.html(fps + " fps");
if (run == true) {
d.display();
d.halfway(dice.choice());
count++;
countLabel.html(nf(count,6,0));
diceLabel.html(dice.selected);
}
}
function toggleRun() {
run = !run;
if (run) {
startBtn.class("btn btn-danger text-center");
startBtn.html("Stop");
diceLabel.html(dice.selected);
}
if (!run) {
startBtn.class("btn btn-success text-center");
startBtn.html("Start");
diceLabel.html("-");
}
}
function restartGame() {
location.reload();
}