-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjavascript.js
More file actions
64 lines (50 loc) · 1.18 KB
/
javascript.js
File metadata and controls
64 lines (50 loc) · 1.18 KB
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
console.log("toimiiko?");
const canvas = document.getElementById("myCanvas");
const ctx = canvas.getContext("2d");
let x = canvas.width / 2;
let y = canvas.height - 30;
let dx = 2;
let dy = -2;
let ballColor = "#0095DD";
const ballRadius = 10
//esimerkkejä
const f0 = (a, b, c) => {
console.log(a + b + c);
};
const f1 = widht => height => depths => {};
function f11(a) {
return function(b) {
return function(c) {
console.log(a + b - c);
};
};
}
f0(1, 2, 3);
f1(1)(2)(3);
f11(1)(3)(2);
const draw = () => {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawBall();
bounceCollisionToEdges()
x += dx;
y += dy;
};
setInterval(draw, 10);
const drawBall = () => {
ctx.beginPath();
ctx.arc(x, y, ballRadius, 0, Math.PI * 2);
ctx.fillStyle = ballColor;
ctx.fill();
ctx.closePath();
};
const getRandomColor = () => '#'+(0x1000000+(Math.random())*0xffffff).toString(16).substr(1,6);
const bounceCollisionToEdges = () => {
if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
dx = -dx;
ballColor = getRandomColor();
}
if(y + dy > canvas.height-ballRadius || y + dy < ballRadius) {
dy = -dy;
ballColor = getRandomColor();
}
}