Advertisement
chrisCNG

CloudsPygame

Jul 2nd, 2020
959
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.89 KB | None | 0 0
  1. # clouds with pygame
  2. # Import Libraries
  3. import pygame, sys
  4. from pygame.locals import *
  5. pygame.init()
  6. import math
  7. from random import randint
  8.  
  9.  
  10. DarkBlue = (0,153,255)
  11. Grey1 =(142, 150, 163)
  12. Mist1 = (213, 216, 222)
  13. Pink1 =(255, 230, 234)
  14. White1 = (255,255,255)
  15.  
  16. def draw_cloud(x, y, l, h):
  17.     if y > 200:
  18.         col = Grey1
  19.     elif y > 170:
  20.         col = Mist1
  21.     elif y < 130:
  22.         col = Pink1
  23.     else:
  24.         col = White1
  25.  
  26.     pygame.draw.ellipse(mainDisplay, col, [x, y, l, h])
  27.  
  28.  
  29. def polar(r, theta):
  30.     pi = 3.1415927
  31.     ang = theta * pi /180
  32.     yn = int(r*math.sin(ang)) + 200
  33.     xn = int(r*math.cos(ang)) + 200
  34.     return xn, yn
  35.  
  36.  
  37. # Set up display area
  38. Width = 500
  39. Height = 500
  40. mainDisplay = pygame.display.set_mode((Width,Height))
  41. mainDisplay.fill(DarkBlue)
  42.  
  43. pygame.display.set_caption('Clouds')
  44.  
  45.  
  46. # Main section
  47. # mid cloud
  48. for loop in range(10):
  49.  
  50.     ll = randint(30,70)
  51.     hh = randint(30,70)
  52.     th0 = randint(180,360)
  53.     rr = randint(10,80)
  54.     coords = polar(rr, th0)
  55.     draw_cloud(coords[0], coords[1], ll, hh)
  56.  
  57. # mid cloud
  58. for loop in range(150):
  59.  
  60.     ll = randint(10,30)
  61.     hh = randint(10,30)
  62.     th0 = randint(180,360)
  63.     rr = randint(30,100)
  64.     coords = polar(rr, th0)
  65.     draw_cloud(coords[0], coords[1], ll, hh)
  66.  
  67. # outer cloud
  68. for loop in range(300):
  69.  
  70.     ll = randint(2,10)
  71.     hh = randint(2,10)
  72.     th0 = randint(180,360)
  73.     rr = randint(55,100)
  74.     coords = polar(rr, th0)
  75.     draw_cloud(coords[0], coords[1], ll, hh)
  76.  
  77. # under cloud
  78. for loop in range(100):
  79.  
  80.     ll = randint(2,10)
  81.     hh = randint(2,10)
  82.     th0 = randint(0,180)
  83.     rr = randint(30,60)
  84.     coords = polar(rr, th0)
  85.     draw_cloud(coords[0], coords[1], ll, hh)
  86.  
  87. while True: # main game loop
  88.     for event in pygame.event.get():
  89.         if event.type == QUIT:
  90.             pygame.quit()
  91.             sys.exit()
  92.     pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement