Created
April 25, 2023 03:21
-
-
Save dimastopel/df7bf6ace21701ab4d9957228b879210 to your computer and use it in GitHub Desktop.
Playing with pygame
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pygame as p | |
from scipy.stats import poisson | |
run = True | |
max_r = 80 | |
des_r = 35 | |
paint = False | |
p.init() | |
sc = p.display.set_mode((1000, 1000)) | |
sc.fill((255, 255, 255)) | |
p.display.update() | |
while run: | |
for event in p.event.get(): | |
if event.type == p.QUIT: | |
run = False | |
if event.type == p.KEYDOWN and event.key == p.K_ESCAPE: | |
run = False | |
if event.type == p.MOUSEBUTTONDOWN and event.button == 3: | |
sc.fill((255, 255, 255)) | |
if event.type == p.MOUSEBUTTONDOWN and event.button == 1: | |
paint = True | |
if event.type == p.MOUSEBUTTONUP and event.button == 1: | |
paint = False | |
if event.type == p.MOUSEWHEEL: | |
des_r += event.y | |
if des_r < 1: | |
des_r = 1 | |
print(des_r) | |
rel = p.mouse.get_rel() | |
dist = p.math.Vector2(rel).magnitude() | |
if dist > 0: | |
r = max_r / dist | |
r = p.math.clamp(r, 0, des_r) | |
r = poisson.rvs(mu=r) | |
if paint: | |
p.draw.circle(sc, 0, p.mouse.get_pos(), r) | |
p.display.update() | |
p.quit() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment