-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathpart2m.html
61 lines (44 loc) · 1.41 KB
/
part2m.html
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
<!DOCTYPE html>
<html>
<title>Creative Coding Yea!</title>
<head>
<meta charset="utf-8">
<script language="javascript" src="js/creative_coding.js"></script>
<script language="javascript" src="js/canvas.js"></script>
<link rel="stylesheet" href="css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" />
</head>
<body>
<script>
// this is a function (from canvas.js) that sets you the canvas
// so you don't need to do any of the heavy lifting and can
// start playing straight away
// the function also lets you access the screen width as "width" or "w"
// and the screen height as "height" or "h"
var ctx = createCanvas("canvas1");
var ball_size = 20;
var ball_x = width/2;
var ball_y = height/2;
var speed_x = randomInt(-15, 15);
var speed_y = randomInt(-15, 15);
ctx.fillStyle = rgb(randomInt(255),randomInt(255),0);
function draw(){
//ctx.background(255, 0.2);
//ctx.fillStyle = rgb(255,0,0);
ball_x = ball_x + speed_x;
ball_y = ball_y + speed_y;
if (bounce(ball_x, 0, w, ball_size)) {
speed_x *=-1;
ball_size = random(10, 50);
ctx.fillStyle = rgb(randomInt(255),randomInt(255),0);
}
if (bounce(ball_y, 0 ,h, ball_size)) {
speed_y *=-1;
ball_size = random(10, 50);
ctx.fillStyle = rgb(0, randomInt(255),randomInt(255));
}
ctx.fillEllipse(ball_x, ball_y, ball_size, ball_size);
}
</script>
</body>
</html>