Python-现代艺术画

先放程序运行结果:

 

该程序会随机画100个大小不等、位置不同、颜色不一的矩形。运行时每次得到的图形都不一样。你看这个程序,很漂亮的(〃'▽'〃)。

此程序脱胎于《与小卡特一起学编程》,原代码需要下载pygame和colordict两个模块,修改后只需要下载pygame一个模块。(因为蠢没下到colordict_(:з」∠)_

咳咳,上代码:

import pygame,sys,random
import random
pygame.init()
screen=pygame.display.set_mode([640,480])
screen.fill([0,0,0])
for i in range(100):
    width=random.randint(0,250);height=random.randint(1,100)
    top=random.randint(0,400);left=random.randint(1,500)
    color_random=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
    color=color_random
    line_width=random.randint(1,3)
    pygame.draw.rect(screen,color,[left,top,width,height],line_width)
pygame.display.flip()
running=True
while running:
    for even in pygame.event.get():
        if even.type==pygame.QUIT:
            running=False
pygame.quit()

耶~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值