绘制各种图形
2017-08-27 09:13
155 查看
#_*_coding:utf-8_*_ import pygame from pygame.locals import * from sys import exit from random import * from math import pi pygame.init() screen=pygame.display.set_mode((640,480),0,32) points=[] while True: for event in pygame.event.get(): if event.type==QUIT: exit() if event.type==KEYDOWN: points=[] screen.fill((255,255,255)) if event.type==MOUSEBUTTONDOWN: screen.fill((255,255,255)) #画随机举行 rc=(randint(0,255),randint(0,255),randint(0,255)) rp=(randint(0,639),randint(0,479)) rs=(639-randint(rp[0],639),479-randint(rp[1],479)) pygame.draw.rect(screen,rc,Rect(rp,rs)) #画随机椭圆 rr=randint(1,200) pygame.draw.circle(screen,rc,rp,rr) #获取鼠标点击位置 x,y=pygame.mouse.get_pos() points.append((x,y)) #根据点击位置画弧线 angle=(x/639)*pi*2 pygame.draw.arc(screen,(0,0,0),(0,0,639,479),0,angle,3) #根据点击位置画椭圆 pygame.draw.ellipse(screen,(0,255,0),(0,0,x,y)) #画点击轨迹图 if len(points)>1: pygame.draw.lines(screen,(155,155,0),False,points,2) for p in points: pygame.draw.circle(screen, (155, 155, 155), p, 3) pygame.display.update()
View Code
使用了常用图形的绘制:
矩形
圆形
椭圆
线
相关文章推荐
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等
- Quartz 各种绘制图形用法
- PyQt5利用QPainter绘制各种图形(转)
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等
- 【Android】开源项目汇总-备用 各种图形的绘制,各种效果
- android 用Path 绘制各种图形,Path的方法解析
- Quartz 各种绘制图形用法
- 开始使用SmartDraw绘制开发中的各种图形
- Android 动态绘制曲线等各种图形
- GDI绘制各种图形和文字
- amCharts在网页上绘制各种图形
- Android采用canvas绘制各种图形
- 开始使用SmartDraw绘制开发中的各种图形
- android之各种图形绘制
- 开始使用SmartDraw绘制开发中的各种图形
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等
- 自定义View绘制各种图形
- android使用achartengine实现各种图形绘制
- 纯CSS3实现绘制各种图形实现代码详细整理
- IOS Quartz 各种绘制图形用法---实现画图片、写文字、画线、椭圆、矩形、棱形等