-
Notifications
You must be signed in to change notification settings - Fork 0
/
colorAnim.js
74 lines (41 loc) · 1.36 KB
/
colorAnim.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
var intervalId;
var opacity = 0.0;
function setup() {
var increment = 0.01;
var increasing = true;
//var startTime = new Date();
var interval = 100; // ms
////////////////////////////////////////
intervalId = setInterval(function draw() {
//var timePassed = new Date() - start;
// Change opacity a little
if (increasing) {
opacity += increment; // opacity = opacity + increment
} else {
opacity -= increment; // opacity = opacity - increment
}
// Check if we need to change direction
if (opacity >= 1.0) {
increasing = false;
} else if (opacity <= 0) {
increasing = true;
}
// Print value
console.log('Opacity', opacity);
console.log('increasing', increasing);
//rect();
}, interval);
////////////////////////////////////////
}
// Setup
setup();
function stopIt() {
clearInterval(intervalId);
}
/*function rect() {
var ctx = document.getElementById('myCanvas').getContext('2d');
ctx.globalAlpha = opacity;
ctx.clearRect(0, 0, 500, 500);
ctx.fillStyle="blue";
ctx.fillRect (0, 0, 500, 500);
}*/