diduk001

drawer

Sep 16th, 2020
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 KB | None | 0 0
  1. import pygame
  2. import random
  3. from pygame.locals import *
  4. from pygame.mixer import Sound, get_init, pre_init
  5. import os
  6. from array import array
  7. import math
  8. from time import sleep
  9. import time
  10.  
  11. SCREEN_WIDTH = random.randint(400, 750)
  12. SCREEN_HEIGHT = random.randint(400, 750)
  13. SCREEN_CAPTION = random.choice(('какдила какдила', 'паша техник пишет биты здесь', 'понятие драйв', 'мне кажется, это маша михайленко', 'разбулятор', 'бильбоа', 'генератор случайного чего-то', 'подарок на др маши',
  14. '[вс т авитьтекст_)', 'рэпер фейс', 'набор для творчества0', 'весёлые картинки с муз сопровождением'))
  15.  
  16. COLOR_MIN = random.randint(0, 50)
  17. COLOR_MAX = random.randint(150, 255)
  18. COLOR_DELTA = random.randint(10, 50)
  19.  
  20. RADIUS_MIN = random.randint(1, 10)
  21. RADIUS_MAX = random.randint(30, 75)
  22. RADIUS_DELTA = random.randint(5, 15)
  23.  
  24. NOTE_MIN = random.randint(50, 150)
  25. NOTE_DELTA = random.randint(10, 50)
  26. NOTE_MAX = random.randint(1000, 2000)
  27.  
  28. NOTE_BASS = random.randint(NOTE_MIN, (NOTE_MAX - NOTE_MIN) // 2)
  29. NOTE_DRUM = random.randint(NOTE_BASS, NOTE_BASS + (NOTE_MAX - NOTE_BASS) // 2)
  30. NOTE_SYNTH = random.randint(NOTE_DRUM + (((NOTE_MAX - NOTE_DRUM) // 3) * 2), NOTE_MAX)
  31.  
  32.  
  33. class Note(Sound):
  34.  
  35. def __init__(self, frequency, volume=1):
  36. self.frequency = frequency
  37. Sound.__init__(self, self.build_samples())
  38. self.set_volume(volume)
  39.  
  40. def build_samples(self):
  41. period = int(round(get_init()[0] / self.frequency))
  42. samples = array("h", [0] * period)
  43. amplitude = 2 ** (abs(get_init()[1]) - 1) - 1
  44. for time in range(period):
  45. if time < period / 2:
  46. samples[time] = amplitude
  47. else:
  48. samples[time] = -amplitude
  49. return samples
  50.  
  51.  
  52. def change_color(color):
  53. color0 = color[0]
  54. color1 = color[1]
  55. color2 = color[2]
  56.  
  57. color0 = min(max(color0 + random.randint(-COLOR_DELTA,
  58. COLOR_DELTA), COLOR_MIN), COLOR_MAX)
  59. color1 = min(max(color1 + random.randint(-COLOR_DELTA,
  60. COLOR_DELTA), COLOR_MIN), COLOR_MAX)
  61. color2 = min(max(color2 + random.randint(-COLOR_DELTA,
  62. COLOR_DELTA), COLOR_MIN), COLOR_MAX)
  63.  
  64. return (color0, color1, color2)
  65.  
  66.  
  67. def change_radius(radius):
  68. radius_new = min(max(radius + random.randint(-RADIUS_DELTA,
  69. RADIUS_DELTA), RADIUS_MIN), RADIUS_MAX)
  70.  
  71. return radius_new
  72.  
  73.  
  74. def change_note(note_old):
  75. note_new = min(
  76. max(NOTE_MIN, note_old + random.randint(-NOTE_DELTA, +NOTE_DELTA)), NOTE_MAX)
  77. return note_new
  78.  
  79.  
  80. pre_init(44100, -16, 1, 1024)
  81. pygame.init()
  82. screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
  83. pygame.display.set_caption(SCREEN_CAPTION)
  84.  
  85. background = pygame.Surface((SCREEN_WIDTH, SCREEN_HEIGHT))
  86. background = background.convert()
  87.  
  88. background.fill((0, 0, 0))
  89. color = (random.randint(COLOR_MIN, COLOR_MAX), random.randint(
  90. COLOR_MIN, COLOR_MAX), random.randint(COLOR_MIN, COLOR_MAX))
  91. startPos = (0, 0)
  92. radius = random.randint(RADIUS_MIN, RADIUS_MAX)
  93.  
  94. note = random.randint(NOTE_MIN, NOTE_MAX)
  95.  
  96. while True:
  97.  
  98. Note(note, volume=2).play(1)
  99. note = change_note(note)
  100.  
  101. pressed = pygame.key.get_pressed()
  102.  
  103. if pressed[K_c]:
  104. background.fill((0, 0, 0))
  105. color = (random.randint(COLOR_MIN, COLOR_MAX), random.randint(
  106. COLOR_MIN, COLOR_MAX), random.randint(COLOR_MIN, COLOR_MAX))
  107. radius = random.randint(RADIUS_MIN, RADIUS_MAX)
  108. note = random.randint(NOTE_MIN, NOTE_MAX)
  109.  
  110. for i in pygame.event.get():
  111. if i.type == pygame.QUIT or pressed[pygame.K_q]:
  112. exit()
  113. elif i.type == pygame.MOUSEMOTION:
  114. endPos = pygame.mouse.get_pos()
  115. if pygame.mouse.get_pressed() == (1, 0, 0):
  116. if startPos[0] > endPos[0]:
  117. note = max(1, note - abs(startPos[1] - endPos[1]))
  118. # if startPos[1] < endPos[1]:
  119. # note = min(2500, note + abs(startPos[0] - endPos[0]))
  120.  
  121. pygame.draw.line(background, color,
  122. startPos, endPos, radius)
  123.  
  124. elif pygame.mouse.get_pressed() == (0, 0, 1):
  125. pygame.draw.line(background, (0, 0, 0), startPos, endPos, 10)
  126. startPos = endPos
  127.  
  128. screen.blit(background, (0, 0))
  129.  
  130. color = change_color(color)
  131. radius = change_radius(radius)
  132.  
  133. pygame.display.flip()
  134. Note(NOTE_BASS, volume=0.3).play(1)
  135. Note(NOTE_DRUM, volume=0.3).play(1)
  136. Note(NOTE_SYNTH, volume=0.7).play(1)
  137. NOTE_SYNTH += 1
  138. if NOTE_SYNTH == NOTE_MAX:
  139. NOTE_SYNTH = NOTE_MIN
  140. time.sleep(1 / random.randint(35, 120))
  141.  
Advertisement
Add Comment
Please, Sign In to add comment