IN_IDLE = 0 ################################# ## Stereogramm mit Blümchentapete ################################# DPI = 75 # inch resolution of display media OBSDIST = DPI*20 # inch distance of observer to media EYESEP = DPI*2.5 # eye separation MINDEPTH = DPI*1 MAXDEPTH = DPI*6 DEPTHSTEPS = 10 # so viele Tiefenstufen zulassen WIDTH = DPI*10 # Bildbreite HEIGHT = DPI*8 # Bildhöhe LINES = 12 DY = HEIGHT/(LINES+1) from Tkinter import * class Bluemchentapete: def __init__(self): self.root = Tk() self.c = Canvas(self.root, width=WIDTH+6,height=HEIGHT+6) self.c.pack() self.MID = WIDTH/2+3 # maximal separation EYESET/2 als Musterbreite, # dahinterliegende Muster enger setzen def plotline(self,y,depth): y = y*DY # y position on canvas depth = DEPTHSTEPS-depth z = MINDEPTH+float(depth)/DEPTHSTEPS*(MAXDEPTH-MINDEPTH) separation = 0.5*EYESEP*float(OBSDIST)/(z+OBSDIST) # make smaller pattern by this factor resize = 1.0/OBSDIST*(z+OBSDIST) d = self.MID/separation for k in range(-d+1,d+1): xpos = self.MID-separation/2+k*separation # plot pattern at (x/y), max size, with depth resize self.stamp(xpos,y,EYESEP/2.0,resize) # plot a single pattern def stamp(self,x,y,maxsize,scale): # s = maxsize/8.0 # alles gleich groß s = maxsize/8.0*scale # mit Verkleinerung nach Hinten self.c.create_oval(x-s,y-s,x+s,y+s,width=4, outline="#0000ff",fill="#ff0000") d = s/2.5 for x1 in (-s/1.4,s/1.4): for y1 in (-s/1.4,s/1.4): self.c.create_oval(x+x1-d,y+y1-d,x+x1+d,y+y1+d,fill="#00ff00") def test(self): self.plotline(1,0) self.plotline(2,2) self.plotline(3,4) self.plotline(4,6) self.plotline(5,8) self.plotline(6,10) self.plotline(7,10) self.plotline(8,8) self.plotline(9,6) self.plotline(10,4) self.plotline(11,2) self.plotline(12,0) if not IN_IDLE: self.root.mainloop() b = Bluemchentapete() b.test()