Python 使用 Turtle 库
```python
import turtle
def draw_star(size):
angle = 144
for _ in range(5):
turtle.forward(size)
turtle.right(angle)
def main():
turtle.speed(1) 设置绘制速度
turtle.penup() 抬起画笔
turtle.goto(-50, 0) 移动画笔的起始位置
turtle.pendown() 放下画笔
draw_star(100) 绘制大小为100的五角星
turtle.done() 绘图完成后保持窗口不关闭
if __name__ == "__main__":
main()
```
Python 使用数学运算
```python
import turtle
import math
def draw_star(size):
angle = 144
for _ in range(5):
turtle.forward(size)
turtle.right(angle)
def main():
turtle.speed(1) 设置绘制速度
turtle.penup() 抬起画笔
turtle.goto(-50, 0) 移动画笔的起始位置
turtle.pendown() 放下画笔
draw_star(100) 绘制大小为100的五角星
turtle.done() 绘图完成后保持窗口不关闭
if __name__ == "__main__":
main()
```
C 语言
```c
include
int main() {
int size = 5; // 五角星的大小
int i, j;
for (i = 1; i <= size; i++) {
for (j = 1; j <= 2 * size - i; j++) {
if (i == 1 || i == size || j == i || j == 2 * size - i) {
printf("* ");
} else {
printf(" ");
}
}
printf("\n");
}
return 0;
}
```
Java
```java
import javax.swing.*;
import java.awt.*;
public class Star {
public static void main(String[] args) {
JFrame frame = new JFrame("Star");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(300, 300);
frame.setLayout(new BorderLayout());
JPanel panel = new JPanel() {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
int size = 50;
int x = size;
int y = size;
for (int i = 0; i < 5; i++) {
g.drawLine(x, y, x + size * Math.cos(Math.toRadians(360 / 5 * i)), y - size * Math.sin(Math.toRadians(360 / 5 * i)));
x += size * Math.cos(Math.toRadians(360 / 5 * i));
y -= size * Math.sin(Math.toRadians(360 / 5 * i));
}
}
};
frame.add(panel);
frame.setVisible(true);
}
}
```
这些代码示例展示了如何使用不同的编程语言和库来绘制五角星。你可以根据自己的需求和熟悉程度选择合适的编程语言和工具来实现五角星的绘制。