第一篇博客
程序员文章站
2023-12-24 10:19:21
...
第一篇博客
Random Circles Generation
代码
HTML
<DOCTYPE! html>
<html>
<head>
<title>Random Circles Generator</title>
<style>
#myCanvas
{
background-color: black;
}
</style>
</head>
<body>
<input id="clickMe" type="button" value="Generate" onclick="generateCircles();" />
<canvas id="myCanvas"></canvas>
<script type="text/javascript">
var c = document.getElementById("myCanvas");
c.width = window.innerWidth;
c.height = window.innerHeight;
generateCircles();
function generateCircles()
{
for(var i=0; i<10; i++)
{
drawCircle(Math.random()*window.innerWidth, Math.random()*window.innerHeight, Math.random()*50, "blue");
}
}
function drawCircle(x, y, size, col)
{
var circle = c.getContext("2d");
circle.beginPath();
circle.arc(x, y, size, 0, 2 * Math.PI);
circle.fillStyle = col;
circle.fill();
}
</script>
</body>
</html>
CSS
body{
}
运行截图
长按扫码关注