Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. class Box:
  2.     def __init__(self, x, y, s):
  3.         self.x = x
  4.         self.y = y
  5.         self.s = s
  6.     def draw(self, cam):
  7.         rect(self.x * cam['z'] - cam['x'], self.y * cam['z'] - cam['y'], self.s * cam['z'], self.s * cam['z'])
  8.        
  9. cam = {'x': 0, 'y': 0, 'z': 1}
  10.  
  11. boxes = []
  12.  
  13. def setup():
  14.     size(800, 600)
  15.    
  16.     for i in range(20):
  17.         boxes.append(Box(random(-20,20) * 20, random(-20,20) * 20, random(10,30)))
  18.  
  19. def draw():
  20.     if mousePressed:
  21.         cam['x'] -= mouseX - pmouseX
  22.         cam['y'] -= mouseY - pmouseY
  23.    
  24.     background(123)
  25.    
  26.     wmouseY = (mouseY + cam['y']) / cam['z']
  27.     wmouseX = (mouseX + cam['x']) / cam['z']
  28.    
  29.     text(str(wmouseX) + ', ' + str(wmouseY), 20, 20)
  30.    
  31.     for b in boxes:
  32.         b.draw(cam)
  33.        
  34. def keyPressed():
  35.     if key == 'e':
  36.         cam['z'] += 0.5
  37.     elif key == 'q':
  38.         cam['z'] -= 0.5
  39.     if cam['z'] < 0.5:
  40.         cam['z'] = 0.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement