-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbaking.py
executable file
·56 lines (49 loc) · 1.46 KB
/
baking.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import math
import time
def cir2aud(coord):
"""Convert from -1..-1 to 0..255 byte (character)."""
return chr(int((coord+1.0)/2 * 255))
def emit(x, y):
sys.stdout.write(cir2aud(y))
sys.stdout.write(cir2aud(x))
def arm(x, y, steps, length=1.0):
for i in range(steps, -1, -1) + range(0, steps+1, 1):
emit(x * i / steps * length, y * i / steps * length)
def cyferblat():
year, month, day, hours, minutes, seconds, weekday, yearday, isdst = time.localtime()
arm1 = ((hours % 12) * 5) + int(minutes/12)
arm2 = minutes
arm3 = seconds
angle = 0.0
steps = 60
increment = 2.0 * math.pi / steps
for step in xrange(steps):
x = math.cos(angle)
y = math.sin(angle)
angle += increment
if step % 5 == 0:
dwell = 40
else:
dwell = 8
for d in xrange(dwell/2):
yield x, y
if step == arm1:
arm(x, y, 50, 0.5)
if step == arm2:
arm(x, y, 30, 0.7)
if step == arm3:
arm(x, y, 20, 0.9)
for d in xrange(dwell/2):
yield x, y
if sys.stdout.isatty():
print >>sys.stderr, "I cowardly refuse to clobber thy teletype!"
print >>sys.stderr, "Usage: ./baking.py | ./bread"
print >>sys.stderr, "Also, is thy oscilloscope hooked up accordingly?"
sys.exit(1)
while True:
for x, y in cyferblat():
emit(x, y)