Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, math
- import pygame, sys
- from pygame.locals import *
- from pygame import gfxdraw
- pygame.init()
- screen_width = 1000
- screen_height = 800
- rect_x = 500
- rect_y = 250
- rect_width = 100
- rect_height = 75
- rand_max = (screen_width * screen_height) - (rect_width * rect_height)
- rect_start = (screen_width * rect_y) + rect_x
- rect_end = (screen_width * (rect_y + rect_height)) + rect_x + rect_width
- def rand_point():
- rand_raw = random.randint(0, rand_max-1)
- if rand_raw > rect_end:
- rand_raw += rect_width * rect_height
- elif rand_raw > rect_start:
- rows_add = rand_raw // screen_width
- col = rand_raw % screen_width
- if col >= rect_x:
- rand_raw += rect_width
- rand_raw += rows_add * screen_width
- x = rand_raw % screen_width
- y = rand_raw // screen_width
- return (x, y)
- window = pygame.display.set_mode((screen_width, screen_height))
- window.fill((0, 0, 0))
- while True:
- x, y = rand_point()
- print x, y
- gfxdraw.pixel(window, x, y, (255, 0, 0))
- for event in pygame.event.get():
- if event.type == QUIT:
- pygame.quit()
- sys.exit()
- pygame.display.update()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement