python 模拟球在空间内跳动

Posted momozsdf

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 模拟球在空间内跳动相关的知识,希望对你有一定的参考价值。

import cv2

x,y = 0,0

movex,movey = 50,0

color = (255,255,255)

s = True

r=5

g = 1

h = 1

x,y = x+r,y+r 

z = 1

f = 1

img = cv2.imread("E:\\wangzc\\code\\.math\\\\a.png")

while True:

    if s == True:

        img = cv2.imread("E:\\wangzc\\code\\.math\\\\a.png")

    print(movex,movey,x,y)

    if x<r or x>img.shape[1]-r-1:

        movex = -movex

        movey+=g

        if movey<0:

            if abs(movey)<=z*g:

                movey=0

            else:

                movey+=z*g

        elif movey>0:

            if abs(movey)<=z*g:

                movey=0

            else:

                movey-=z*g

        else:

            movey =0

        if movex<0:

            if abs(movex)<=f:

                movex=0

            else:

                movex+=f

        elif movex>0:

            if abs(movex)<=f:

                movex=0

            else:

                movex-=f

        else:

            movex =0

    if y<r or y>img.shape[0]-r-1:

        movey=-movey

        if movex<0:

            if abs(movex)<=z*g:

                movex=0

            else:

                movex+=z*g

        elif movex>0:

            if abs(movex)<=z*g:

                movex=0

            else:

                movex-=z*g

        else:

            movex =0

        movey+=g

        if movey<0:

            if abs(movey)<=f:

                movey=0

            else:

                movey+=f

        elif movey>0:

            if abs(movey)<=f:

                movey=0

            else:

                movey-=f

        else:

            movey =0    

    movey+=h*g

    if x>img.shape[1]-r-1:

        x=img.shape[1]-r-1

    if y>img.shape[0]-r-1:

        y = img.shape[0]-r-1

    if x<=r:

        x=r

    if y<=r:

        y=r  

   

    for i in range(r+1):

        cv2.circle(img,(x,y),i,color)

    print(movex,movey,x,y)

    x+=movex

    y+=movey

    cv2.imshow('img',img)

    a = cv2.waitKey(0)

    if a==27:

        break

   

以上是关于python 模拟球在空间内跳动的主要内容,如果未能解决你的问题,请参考以下文章

球在不可见的盒子内弹跳/移动 ios/xcode

如何用canvas画板实现一个简单的球在盒子内反弹运动

一面字节跳动,被面试官吊打!幸得华为内推,三面拿到offer

模拟退火小结

软件测试字节跳动一面,被面试官吊打!幸得华为内推,三面拿到offer

软件测试字节跳动一面,被面试官吊打!幸得华为内推,三面拿到offer