python小球在窗口弹来弹去_在屏幕上弹30个球

我的任务是在创建的窗口上显示30个弹跳球。我刚开始学习课程,我似乎不知道如何显示30个球弹跳。我能把一个球从四面墙上弹开。在#! /usr/bin/env python3

# Dorthy Petrick

# Display 30 bouncing balls bouncing around the screen

from graphics import *

from time import sleep

from random import *

class Ball:

def __init__(self):

self.dx = 1

self.dy = 1

def draw(self, win):

self.ball = Circle(Point(25, 60), 3)

self.ball.setFill('blue')

self.ball.draw(win)

def move(self):

self.ball.move(self.dx,self.dy)

xValue = self.ball.getCenter().getX()

yValue = self.ball.getCenter().getY()

if 550 < xValue:

self.dx = -self.dx

if -xValue > xValue:

self.dx = -self.dx

if 500 < yValue:

self.dy = -self.dy

if -yValue > yValue:

self.dy = -self.dy

def main():

win = GraphWin("bouncy.py", 550, 500)

ball = Ball()

ball.draw(win)

counters = []

while True:

for i in range(30):

ball.move()

counter = Counter()

counter.setCounterId(i + 1)

balls.append(ball)

win.getMouse()

win.close()

if __name__ == '__main__':

main()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值