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 * import random wt = 500 ht = 600 b = { "xp" : 50, "yp" : 50, "xh" : 4, "yh" : 2, "rad" : 10 } def drawB(): fill(255, 255, 255) ellipse(b["xp"], b["yp"], (b["rad"]*2), (b["rad"]*2)) def moveB(): b["xp"] = b["xp"] + b["xh"] b["yp"] = b["yp"] + b["yh"] if b["xp"] + b["rad"] == wt or b["xp"] - b["rad"] == 0: if b["xh"] > 0: b["xh"] = random.randint(-10, -1) #print "x : " + str(b["xh"]) + " |", elif b["xh"] < 0: b["xh"] = random.randint(1, 10) #print "x : " + str(b["xh"]) + " |", elif b["xp"] + b["rad"] > wt: distToRightEdge = wt - (b["xp"] + b["rad"]) b["xp"] = b["xp"] + distToRightEdge if b["xh"] > 0: b["xh"] = random.randint(-10, -1) #print "x : " + str(b["xh"]) + " |", elif b["xh"] < 0: b["xh"] = random.randint(1, 10) #print "x : " + str(b["xh"]) + " |", elif b["xp"] - b["rad"] < 0: distToLeftEdge = b["xp"] - b["rad"] b["xp"] = b["xp"] - distToLeftEdge if b["xh"] > 0: b["xh"] = random.randint(-10, -1) #print "x : " + str(b["xh"]) + " |", elif b["xh"] < 0: b["xh"] = random.randint(1, 10) #print "x : " + str(b["xh"]) + " |", if b["yp"] + b["rad"] == ht or b["yp"] - b["rad"] == 0: if b["yh"] > 0: b["yh"] = random.randint(-10, -1) #print "y : " + str(b["yh"]) + " |", elif b["yh"] < 0: b["yh"] = random.randint(1, 10) #print "y : " + str(b["yh"]) + " |", elif b["yp"] + b["rad"] > ht: distToBottomEdge = ht - (b["yp"] + b["rad"]) b["yp"] = b["yp"] + distToBottomEdge if b["yh"] > 0: b["yh"] = random.randint(-10, -1) #print "y : " + str(b["yh"]) + " |", elif b["yh"] < 0: b["yh"] = random.randint(1, 10) #print "y : " + str(b["yh"]) + " |", elif b["yp"] - b["rad"] < 0: distToTopEdge = b["yp"] - b["rad"] b["yp"] = b["yp"] - distToTopEdge if b["yh"] > 0: b["yh"] = random.randint(-10, -1) #print "y : " + str(b["yh"]) + " |", elif b["yh"] < 0: b["yh"] = random.randint(1, 10) #print "x : " + str(b["yh"]) + " |", #:::::::::::::THE PROCESSING PACKAGE::::::::::::::::::::::::::::: def setup(): size(wt, ht) background(0, 0, 0) def draw(): drawB() moveB() run()
ch_RandomBallPath.py
( around 75 lines python code )
Published By:
EM5700
Published on
2020-03-03T16:57:53Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here