欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

第一篇博客

程序员文章站 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{

}

运行截图

第一篇博客

第一篇博客
长按扫码关注

上一篇:

下一篇: