Advertisement
Guest User

Untitled

a guest
Jul 17th, 2021
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.92 KB | None | 0 0
  1. from vpython import *
  2. import time
  3.  
  4. def RGB(r, g, b): return vector(r / 255.0, g / 255.0, b / 255.0)
  5.  
  6. cor1 = vector(0, 0, -1.5)
  7. cor2 = vector(50, 100, 1.5)
  8.  
  9. canvas(x = 0, y = 0, width = 540, height = 720, center = (cor1 + cor2) * 0.5, background = RGB(232, 255, 232))
  10.  
  11. colors = [RGB(0, 0, 0), RGB(128, 128, 128), RGB(0, 0, 128), RGB(128, 128, 192), RGB(128, 0, 0), RGB(255, 255, 255),
  12.           RGB(0, 255, 0), RGB(255, 255, 0), RGB(0, 0, 255), RGB(255, 0, 0), RGB(255, 128, 0), RGB(0, 255, 255),
  13.           RGB(160, 160, 0), RGB(255, 192, 0), RGB(255, 128, 128), RGB(0, 64, 192), RGB(0, 0, 192)]
  14.  
  15. File = open('../../Documents/CPP/Charles/charles_output.txt', 'r') # change file path to your own
  16.  
  17. def getfloat(): return float(File.readline())
  18. def getint(): return int(File.readline())
  19.  
  20. curve(pos = [vector(0, 0,0), vector(0, 100,0), vector(50, 100,0), vector(50, 0,0), vector(0, 0,0)], color = RGB(255, 255, 255))
  21.  
  22. boxes = []
  23. balls = []
  24.  
  25. def clear(t):
  26.     while len(t) > 0:
  27.         t[-1].visible = False
  28.         del t[-1]
  29. def tin(x, y):
  30.     #return True
  31.     return not((x > cor2.y + 1 or x < -1) or (y > cor2.x + 1 or y < -1))
  32.  
  33. ct = 0
  34. start = 0
  35.  
  36. while True:
  37.     #time.sleep(0.1)
  38.     t = File.readline()
  39.     if t == '': break
  40.     clear(boxes)
  41.     clear(balls)
  42.        
  43.     t = int(t)
  44.     for i in range(t):
  45.         x, y, a, b = getfloat(), getfloat(), getfloat(), getfloat()
  46.         if tin(x, y) and ct >= start: boxes.append(box(pos = vector(y, cor2.y - x, 0), length = b, height = a, width = 1, color = colors[4]))
  47.     t = getint()
  48.     for i in range(t):
  49.         x, y, r, k = getfloat(), getfloat(), getfloat(), getint()
  50.         #print(x, y)
  51.         if tin(x, y) and ct >= start: balls.append(cylinder(pos = vector(y, cor2.y - x, 0), axis = vector(0, 0, 1), radius = r, color = colors[k]))
  52.     if ct >= start: rate(50)
  53.     ct += 1
  54.     if ct % 50 == 0: print(ct / 50)
  55.  
  56. print ('end')
  57. while True: sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement