forked from tstriker/hamster-experiments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmoire_circular.py
More file actions
executable file
·84 lines (63 loc) · 2.49 KB
/
moire_circular.py
File metadata and controls
executable file
·84 lines (63 loc) · 2.49 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
# - coding: utf-8 -
# Copyright (C) 2014 Toms Bauģis <toms.baugis at gmail.com>
"""Circular moire, epilepse your heart out!
Move mouse left and right to adjust the circle disposition
and up and down to increase and decrease the number of circles and line
thickness
"""
import math
from gi.repository import Gtk as gtk
from lib import graphics
class Circles(graphics.Sprite):
def __init__(self, color, **kwargs):
graphics.Sprite.__init__(self, **kwargs)
self.color = color
self.connect("on-render", self.on_render)
self.cache_as_bitmap = True
self.distance = 5
def on_render(self, sprite):
self.graphics.set_line_style(width=1)
circles = 500 / self.distance
line_width = max(self.distance / 2, 1)
for i in range(circles):
radius = i * self.distance + 1
self.graphics.move_to(radius, 0)
self.graphics.circle(0, 0, radius)
self.graphics.set_line_style(width = line_width)
self.graphics.stroke(self.color)
class Scene(graphics.Scene):
def __init__(self):
graphics.Scene.__init__(self)
self.base = Circles("#f00", x=400, y=300)
self.sattelite = Circles("#00f", x=500, y=300)
self.add_child(self.base, self.sattelite)
self.distance = 20
self.connect("on-enter-frame", self.on_enter_frame)
self.connect("on-mouse-move", self.on_mouse_move)
def on_mouse_move(self, sprite, event):
middle = self.width / 2.0
distance = (event.x - middle) * 1.0 / middle
self.distance = int(distance * 250)
middle = self.height / 2.0
circle_distance = abs((event.y - middle) * 1.0 / middle)
circle_distance = circle_distance * 20 + 5
for circle in (self.base, self.sattelite):
circle.distance = int(circle_distance)
self.redraw()
def on_enter_frame(self, scene, context):
self.base.x, self.base.y = self.width / 2, self.height / 2
distance = self.distance
self.sattelite.x, self.sattelite.y = self.base.x + distance, self.base.y
class BasicWindow:
def __init__(self):
window = gtk.Window()
window.set_default_size(800, 500)
window.connect("delete_event", lambda *args: gtk.main_quit())
window.add(Scene())
window.show_all()
if __name__ == '__main__':
window = BasicWindow()
import signal
signal.signal(signal.SIGINT, signal.SIG_DFL) # gtk3 screws up ctrl+c
gtk.main()