Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pygame for loop for draw shape

import pygame 
from pygame.locals import *
from sys import exit
from random import *

pygame.init()

screen = pygame.display.set_mode((640, 480), 0,32)

class Rectangle:
    def __init__(self, pos, color, size):
        self.pos = pos
        self.color = color
        self.size = size
    def draw(self):
        pygame.draw.rect(screen, self.color, Rect(self.pos, self.size))

rectangles = []     

for count in range(10):
    random_color = (randint(0,255), randint(0,255), randint(0,255))
    random_pos = (randint(0,639), randint(0,479))
    random_size = (639-randint(random_pos[0], 639), 479-randint(random_pos[1],479))

    rectangles.append(Rectangle(random_pos, random_color, random_size))



while True:
    for event in pygame.event.get():
        if event.type == QUIT:
            exit()
    screen.lock()
    for rectangle in rectangles:
        rectangle.draw()
    screen.unlock()
    pygame.display.update()
Comment

PREVIOUS NEXT
Code Example
Python :: cdf empírica python 
Python :: How to hyperlink image in blender 
Python :: access data frame element by loc 
Python :: python seaborn violin stack overflow 
Python :: corona data with python flask get pdf 
Python :: timedelta64 total_mins 
Python :: how to call the tkinter insert command from another class 
Python :: Return the indices of the bins 
Python :: delete add replace conttent from csv by using python 
Python :: how to print anything in python 
Python :: convert c++ code to python online 
Python :: anagrams python 
Python :: tensorflow albumentations object detection 
Python :: import cv2 illegal instruction (core dumped) jetson nano 
Python :: columnspan vs column tkinter 
Python :: gym notebook render env 
Python :: AI Challenge 
Python :: ipython widget display 
Python :: login urls 
Python :: is python procedural 
Python :: python join tuple integer to string 
Python :: python for comparing url path 
Python :: daraframe get top n max value 
Python :: reverse lis tpyhon 
Python :: how to add base map in pyqgis 
Python :: description of imdb dataset python 
Python :: cs50 templating urls 
Python :: how to compile opencv_traincascade 
Python :: Automatic stationary conversion 
Python :: how to use django-filters with viewset 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =