1월, 2021의 게시물 표시

파이썬 예제 (랜덤 그리기)

이미지
들어가며 오늘은 파이썬의 랜덤과 쓰레드를 이용한 랜덤 그리기 예제입니다. 실행하면 아래와 같이 0.1초 주기로 원, 사각형을 무작위의 위치와 색 으로 그려주는 방식으로 만들어 보았습니다. [랜덤 그리기 실행모습] 소스코드 from PyQt5.QtWidgets import QApplication, QWidget from PyQt5.QtGui import QPainter, QColor, QBrush from PyQt5.QtCore import Qt, QRect from threading import Thread import time import random import sys QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True) class Shape: def __init__(self, type=0, r=0, g=0, b=0, a=0,rect=QRect()): self.type = type self.color = QColor(r, g, b, a) self.rect = rect class Form(QWidget): def __init__(self): super().__init__() self.setWindowTitle('OCS Drawing') self.resize(600,600) self.shapes = [] #Create thread self.bRun = True self.t = Thread(target = self.threadFunc) self.t.start() def paintEvent(self, e): qp = QPainter(

이 블로그의 인기 게시물

Qt Designer 설치하기

C++ 예제 (소켓 서버, 이미지, 파일전송)