import glob
import time
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir
# You have to call this to make it work.
pygame.init()
# Set up some variables containing the screeen size
sizeX=600
sizeY=600
# Set the starting colour
colour =
device_folder
# Create the pygame window
window =
device_file
# Create the clock object
clock =
def read_temp_raw():
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp():
lines = read_temp_raw()
while lines[0].strip()[-3:] != 'YES':
lines = read_temp_raw()
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
temp_f = temp_c * 9.
# Put a name on the window.
pygame.display.set_caption("Spirograph")
# Initialise more variables
# k and l are numbers between 0
return temp_c, temp_f
# k is the ratio of the distance of the small circle from the big circle
l=random.random()
# l is the ratio of the small circles radius (to the hole with the pen in)
# to the distance from the centre of the large circle.
k=random.random()
# Counter - real number - not integer.
i=0.0
# Scaling factor (Radius of big circle)
R=300
x=0
y=0
# This will loop forever.
while True:
time.sleep(5)
newx = R * ((1-k) * math.cos(t) + l*k*math.cos((1-k) * t / k ))
newy = R * ((1-k) * math.sin(t) - l*k*math.sin((1-k) * t / k ))
if (x==0 and y==0):
pass
else:
pygame.draw.line(window,colour,(x+R,y+R),(newx+R,newy+R),2)
x=newx
y=newy
i=i+5
clock.tick(40)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
sys.exit()
sys.exit()