-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtwopoints.py
64 lines (49 loc) · 1.52 KB
/
twopoints.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from random import random
import numpy as np
from PIL import Image, ImageDraw
from pyghthouse.utils import from_hsv
from pyghthouse import Pyghthouse
from config import UNAME, TOKEN
SPEED_FACTOR = 0.02
COLOR_SPEED = 0.01
class BouncyPoint:
def __init__(self):
self.x = random()
self.y = random()
self.vx = SPEED_FACTOR * (random() + 0.5)
self.vy = SPEED_FACTOR * (random() + 0.5)
def update(self):
self.x += self.vx
self.y += self.vy
if self.x < 0:
self.vx *= -1
self.x *= -1
elif self.x > 1:
self.vx *= -1
self.x = 2 - self.x
if self.y < 0:
self.vy *= -1
self.y *= -1
elif self.y > 1:
self.vy *= -1
self.y = 2 - self.y
class ImageMaker:
def __init__(self):
self.p1 = BouncyPoint()
self.p2 = BouncyPoint()
self.img = Image.new('RGB', (280, 140))
self.draw = ImageDraw.Draw(self.img)
self.hue = 0.0
def callback(self):
self.p1.update()
self.p2.update()
self.hue += COLOR_SPEED
self.draw.line([(self.p1.x * 280, self.p1.y * 140), (self.p2.x * 280, self.p2.y * 140)], width=10,
fill=tuple(from_hsv(self.hue, 1, 1)))
output = self.img.copy()
output.thumbnail((28, 14))
return np.asarray(output)
if __name__ == '__main__':
i = ImageMaker()
p = Pyghthouse(UNAME, TOKEN, image_callback=i.callback, frame_rate=60)
p.start()