python 画风车

from turtle import *
for i in range(4):
    fd(100)
    rt(90)
    circle(-100,45)
    goto(0,0)
    lt(45)    
done()

# -*- coding: utf-8 -*-
"""
Created on Fri Nov  5 09:39:06 2021

@author: SBM
"""
from turtle import *
from random import random
rt(22.5)
for i in range(4):
    fillcolor(random(),random(),random())  #填充颜色
    begin_fill()    #填充开始
    fd(100)
    rt(90)    
    circle(-100,45)
    goto(0,0)
    end_fill()      #填充结束
    lt(45)
width(5)
goto(0,-200)
done()

from turtle import *
import time
setup(1024,768)
rt(90)
for i in range(8):
    fd(100)
    lt(90)
    circle(-100,45)
    goto(0,0)
    rt(90)   
done()

 

Python中,我们可以使用pygame库来创建简单的图形,如旋转风车。首先,你需要安装pygame库,可以使用pip来安装: ```bash pip install pygame ``` 以下是一个基本的示例,展示如何使用pygame以及一些基本的形状和动画来绘制旋转风车: ```python import pygame import math # 初始化pygame pygame.init() # 设置窗口大小 windmill_width = 400 windmill_height = 400 screen = pygame.display.set_mode((windmill_width, windmill_height)) pygame.display.set_caption("Pygame旋转风车") # 定义风车的形状和颜色 chord_length = 50 radius = windmill_width / 2 - chord_length / 2 colors = [(255, 255, 255), (0, 0, 255)] # 白色扇片,蓝色轴 def draw_windmill(angle): for i in range(2): # 两个扇片 x = radius + math.cos(math.radians(angle)) * chord_length y = radius + math.sin(math.radians(angle)) * chord_length pygame.draw.polygon(screen, colors[i], [(x, y), (x - chord_length, y), (x - chord_length, y - chord_length)]) # 游戏主循环 clock = pygame.time.Clock() angle = 0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() screen.fill((0, 0, 0)) # 清除屏幕背景 angle += 5 # 风车每帧旋转的角度 draw_windmill(angle) pygame.display.flip() # 更新显示 clock.tick(60) # 控制帧率 # 结束游戏 pygame.quit() ``` 在这个例子中,风车由两个扇形组成,它们围绕着中心点旋转。你可以调整`chord_length`、`radius`和`colors`来改变风车的外观。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值