Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * wt = 500 ht = 600 b1 = { "xpos" : 50, "ypos" : 50, "xh" : 4, "yh" : 2, "rad" : 10 } b2 = { "xpos" : 200, "ypos" : 250, "xh" : 5, "yh" : 10, "rad" : 20 } b3 = { "xpos" : 475, "ypos" : 375, "xh" : -10, "yh" : -20, "rad" : 6 } #Custom functions - not part of the processing package itself def drawB1(): fill(0, 0, 255) ellipse(b1["xpos"], b1["ypos"], b1["rad"]*2, b1["rad"]*2) #NOTE: moveball() CONTAINS ITS PARAMETERS def moveB1(): b1["xpos"] = b1["xpos"] + b1["xh"] b1["ypos"] = b1["ypos"] + b1["yh"] if b1["xpos"] + b1["rad"] >= wt or b1["xpos"] - b1["rad"] <= 0: b1["xh"] = b1["xh"]*-1 if b1["ypos"] + b1["rad"] >= ht or b1["ypos"] - b1["rad"] <= 0: b1["yh"] = b1["yh"]*-1 def drawB2(): fill(255, 127, 0) ellipse(b2["xpos"], b2["ypos"], b2["rad"]*2, b2["rad"]*2) def moveB2(): b2["xpos"] = b2["xpos"]+b2["xh"] b2["ypos"] = b2["ypos"]+b2["yh"] if b2["xpos"] + b2["rad"] >= wt or b2["xpos"] - b2["rad"] <= 0: b2["xh"] = b2["xh"]*-1 if b2["ypos"] + b2["rad"] >= ht or b2["ypos"] - b2["rad"] <= 0: b2["yh"] = b2["yh"]*-1 def drawB3(): fill(255, 255, 0) ellipse(b3["xpos"], b3["ypos"], b3["rad"]*2, b3["rad"]*2) def moveB3(): b3["xpos"] = b3["xpos"] + b3["xh"] b3["ypos"] = b3["ypos"] + b3["yh"] if b3["xpos"] + b3["rad"] >= wt or b3["xpos"] - b3["rad"] <= 0: b3["xh"] = b3["xh"] * -1 if b3["ypos"] + b3["rad"] >= ht or b3["ypos"] - b3["rad"] <= 0: b3["yh"] = b3["yh"] * -1 #The processing package begins HERE def setup(): size(wt, ht) def draw(): background(0, 0, 0) drawB1() moveB1() drawB2() moveB2() drawB3() moveB3() run()
ch_ThreeBouncingBalls.py
( around 68 lines python code )
Published By:
EM5700
Published on
2020-02-24T22:31:47Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here