import math
① CircleArea(r):
area=math.pi*r*r
②
R=float(input("请输入圆的半径R:")))
print("半径为{0}的圆面积为{1:.2f}".format(R, ③ ))
1、def
2、return area
3、CircleArea(R)
- circle方法绘制圆形
- circle(Surface, color, pos, radius, width=0)
- Surface参数:绘制在surface对象上
- color参数:颜色
- pos参数:圆心位置
- radius参数:半径大小
- width=0:边框大小。0表示填充矩形,1以上表示 使用color指定的颜色绘制边框
# 跟随鼠标的圆形
import pygame
import sys
from pygame.locals import *
pygame.init()
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
pygame.display.set_caption("FishC Demo")
position = size[0] // 2, size[1] // 2
moving = False
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
if event.type == MOUSEBUTTONDOWN:
if event.button == 1:
moving = True
if event.type == MOUSEBUTTONUP:
if event.button == 1:
moving = False
if moving:
position = pygame.mouse.get_pos()
screen.fill(WHITE)
pygame.draw.circle(screen, RED, position, 25, 1)
pygame.draw.circle(screen, GREEN, position, 75, 1)
pygame.draw.circle(screen, BLUE, position, 125, 1)
pygame.display.flip()
clock.tick(120)