-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample.html
75 lines (65 loc) · 1.82 KB
/
sample.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="500" height="500"></canvas>
<script>
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
var colors = ["#0400b3" , "#FF0000", "#FFF", "#FFD821"];
var by = 0;
for(n=0; n<2; n++){//make two rectangles
ctx.fillStyle = colors[n];
ctx.fillRect (0, by, 500, 150);
by = 150;
}
function drawBase(x,y,color){
for(n=0; n<2; n++){//make two rectangles
ctx.fillStyle = color;
ctx.fillRect (x, y, 500, 150);
//by = 150;
}
}
var haha = 30;
var count = 60;
var height = 300;
var wy = 0;
var wx = 0;
for(b=0; b < haha; b++){
for(i=0; i < count; i++){
ctx.fillStyle = colors[2];
ctx.fillRect (wx, wy, 5, height);
}
wy=wy+5;//to increment top position
wx=wx+5;//to increment left position
height-=10; //to decrement height of the vertical rectangle ot thick line
}
function drawStar(cx,cy,spikes,outerRadius,innerRadius){
var rot=Math.PI/2*3;
var x=cx;
var y=cy;
var step=Math.PI/spikes;
ctx.beginPath();
ctx.moveTo(cx,cy-outerRadius)
for(i=0;i<spikes;i++){
x=cx+Math.cos(rot)*outerRadius;
y=cy+Math.sin(rot)*outerRadius;
ctx.lineTo(x,y)
rot+=step
x=cx+Math.cos(rot)*innerRadius;
y=cy+Math.sin(rot)*innerRadius;
ctx.lineTo(x,y)
rot+=step
}
ctx.lineTo(cx,cy-outerRadius);
ctx.closePath();
ctx.lineWidth=5;
ctx.fillStyle= colors[3];
ctx.fill();
}
document.write(drawStar(10,25,5,5,10));//top star
document.write(drawStar(10,275,5,5,10));//bottom star
document.write(drawStar(130,150,5,5,10));//right center star
document.write(drawStar(50,150,8,30,20));//sun
</script>
</body>
</html>