-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCreateArrayOfImageCanvas.html
More file actions
98 lines (84 loc) · 2.31 KB
/
CreateArrayOfImageCanvas.html
File metadata and controls
98 lines (84 loc) · 2.31 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<style>
#myCanvas {touch-action: none;
-webkit-touch-callout:none;
-webkit-user-select:none;
-khtml-user-select:none;
-moz-user-select:none;
-ms-user-select:none;
user-select:none;
-webkit-tap-highlight-color:rgba(0,0,0,0);
}
</style>
</head>
<body bgcolor="black">
<canvas id="myCanvas" width="320" height="240" style="border:0px solid #d3d3d3;">
Use different browser.
</canvas>
<script>
//
// random poly rock asteroid shape(red)
//
var c=document.getElementById("myCanvas");
var ctx=c.getContext("2d");
var q=[];
for(var i=0;i<64;i++){
var s = (Math.random()*32)+16;
q.push(rock(s));
//ctx.drawImage(img,Math.random()*c.width,Math.random()*c.height);
//ctx.fillStyle="#ffffff";
//ctx.fillRect(Math.random()*c.width,Math.random()*c.height,10,10);
//ctx.drawImage(img,100,100);
}
gameloop=setInterval(doGameLoop,333);
function doGameLoop(){
myCanvas.width = window.innerWidth;
myCanvas.height = window.innerHeight-32;
myCanvas.width = window.innerWidth-32;
ctx.fillStyle="rgb(100,0,0)";
ctx.fillRect(0,0,c.width,c.height);
ctx.fillStyle="rgb(255,255,255)";
ctx.fillText("Drawing a tilemap example.",10,10);
for(var i=0;i<q.length;i++){
ctx.drawImage(q[i],Math.random()*c.width,Math.random()*c.height);
}
}
function rock(s){
var x = s;
var y = s;
const offscreenCanvas = document.getElementById("myCanvas");
offscreenCanvas.width = s*4;
offscreenCanvas.height = s*4;
const offscreenCtx = offscreenCanvas.getContext("2d");
canvasAsImage = new Image(s,s);
// offscreenCtx.fillStyle = '#000000';
// offscreenCtx.fillRect(0,0,s,s);
offscreenCtx.fillStyle = '#ffffff';
offscreenCtx.beginPath();
offscreenCtx.moveTo(x,y);
var stp=(Math.PI*2)/((Math.random()*5)+16);
var rad,x1,y1;
for(var a=0;a<(Math.PI*2);a+=stp){
rad = (Math.random()*8)+s;
x1=rad*Math.cos(a);
y1=rad*Math.sin(a);
offscreenCtx.lineTo(x+x1,y+y1);
}
rad = (Math.random()*8)+s;
x1=rad*Math.cos(0);
y1=rad*Math.sin(0);
offscreenCtx.lineTo(x+x1,y+y1);
offscreenCtx.closePath();
offscreenCtx.fill();
canvasAsImage.src = offscreenCanvas.toDataURL();
offscreenCanvas.width = 1;
offscreenCanvas.height = 1;
return canvasAsImage;
}
</script>
</body>
</html>