質問編集履歴

2

初心者マークつけました

2019/06/04 05:19

投稿

what
what

スコア15

test CHANGED
File without changes
test CHANGED
File without changes

1

指摘を入れていただきましたので修正しました

2019/06/04 05:19

投稿

what
what

スコア15

test CHANGED
File without changes
test CHANGED
@@ -2,14 +2,70 @@
2
2
 
3
3
 
4
4
 
5
+ ソースコードはこれです
5
6
 
6
7
 
7
8
 
9
+ var canvas = document.getElementById("myCanvas");
10
+
11
+ var ctx = canvas.getContext("2d");
12
+
13
+ var ballRadius = 10;
14
+
15
+ var x = canvas.width/2;
16
+
17
+ var y = canvas.height-30;
18
+
19
+ var dx = 2;
20
+
21
+ var dy = -2;
8
22
 
9
23
 
10
24
 
25
+ function drawBall() {
26
+
27
+ ctx.beginPath();
28
+
11
- ![イメージ説明](11bbe5ebe438d2d7b0d58b7c7371bb8e.png)
29
+ ctx.arc(x, y, ballRadius, 0, Math.PI*2);
30
+
31
+ ctx.fillStyle = "#0095DD";
32
+
33
+ ctx.fill();
34
+
35
+ ctx.closePath();
36
+
37
+ }
12
38
 
13
39
 
14
40
 
41
+ function draw() {
42
+
15
- ![イメージ説明](a159d8a3564316c939f34426ff9e1436.png)
43
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
44
+
45
+ drawBall();
46
+
47
+
48
+
49
+ if(x + dx > canvas.width-ballRadius || x + dx < ballRadius) {
50
+
51
+ dx = -dx;
52
+
53
+ }
54
+
55
+ if(y + dy > canvas.height-ballRadius || y + dy < ballRadius) {
56
+
57
+ dy = -dy;
58
+
59
+ }
60
+
61
+
62
+
63
+ x += dx;
64
+
65
+ y += dy;
66
+
67
+ }
68
+
69
+
70
+
71
+ setInterval(draw, 10);