用web知识写一个太极图代码
时间: 2023-03-15 14:55:25 浏览: 102
我可以为你提供以下代码。确保使用canvas元素:// 画布
var canvas = document.getElementById('canvas');// 画笔
var ctx = canvas.getContext('2d');// 太极中心坐标
var x = canvas.width / 2;
var y = canvas.height / 2;// 太极半径
var radius = 150;// 画太极
ctx.beginPath();
ctx.arc(x, y, radius, 0, 2 * Math.PI);
ctx.strokeStyle = '#000';
ctx.stroke();// 内圆颜色
ctx.fillStyle = '#fff';
ctx.fill();// 太极阴阳
var startAngle = 0;
var endAngle = Math.PI;
ctx.beginPath();
ctx.arc(x, y, radius, startAngle, endAngle);
ctx.fillStyle = '#000';
ctx.fill();// 画内圆
ctx.beginPath();
ctx.arc(x, y, radius / 2, 0, 2 * Math.PI);
ctx.strokeStyle = '#000';
ctx.stroke();// 内圆颜色
ctx.fillStyle = '#fff';
ctx.fill();
相关问题
用python写一个太极图
以下是一个简单的 Python 代码实现太极图:
```python
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 绘制白色半圆
pen.color("white")
pen.begin_fill()
pen.circle(100, 180)
pen.end_fill()
# 绘制黑色半圆
pen.color("black")
pen.begin_fill()
pen.circle(-100, 180)
pen.end_fill()
# 绘制两个小圆
pen.penup()
pen.goto(0, 50)
pen.pendown()
pen.color("white")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
pen.penup()
pen.goto(0, -50)
pen.pendown()
pen.color("black")
pen.begin_fill()
pen.circle(20)
pen.end_fill()
# 隐藏画笔
pen.hideturtle()
# 关闭画布
canvas.exitonclick()
```
运行上述代码,即可绘制一个简单的太极图。注意需要安装 Turtle 库。
用HTML写一个太极八卦图
好的,以下是一个简单的HTML代码,用来绘制太极八卦图:
```html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>太极八卦图</title>
</head>
<body>
<div style="width: 200px; height: 200px; border-radius: 50%; background-color: black; position: relative;">
<div style="width: 100px; height: 100px; border-radius: 50%; background-color: white; position: absolute; top: 0; left: 50%; margin-left: -50px;"></div>
<div style="width: 100px; height: 100px; border-radius: 50%; background-color: black; position: absolute; bottom: 0; left: 50%; margin-left: -50px;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: white; position: absolute; top: 25px; left: 50%; margin-left: -25px;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: black; position: absolute; bottom: 25px; left: 50%; margin-left: -25px;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: black; position: absolute; top: 75px; left: 0;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: white; position: absolute; top: 75px; right: 0;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: white; position: absolute; bottom: 75px; left: 0;"></div>
<div style="width: 50px; height: 50px; border-radius: 50%; background-color: black; position: absolute; bottom: 75px; right: 0;"></div>
</div>
</body>
</html>
```
这段代码会生成一个200*200大小的黑色圆形,内部有一个白色圆和一个黑色圆,分别占据圆的上下两个半部分。同时,圆内四个角落处分别有一个黑色/白色的半圆,构成了八卦图的形状。