Äîêóìåíò âçÿò èç êýøà ïîèñêîâîé ìàøèíû. Àäðåñ îðèãèíàëüíîãî äîêóìåíòà : http://kodomo.cmm.msu.su/trac/petri_dish/changeset/20
Äàòà èçìåíåíèÿ: Unknown
Äàòà èíäåêñèðîâàíèÿ: Sun Apr 10 02:49:51 2016
Êîäèðîâêà: IBM-866
Changeset 20:2df48c61bd42 òÀÓ Petri Dish

Changeset 20:2df48c61bd42


Ignore:
Timestamp:
12/20/10 01:44:18 (5 years ago)
Author:
Yashina Ksenia <ksenia_yashina@òÀæ>
Branch:
default
Message:

now cells can move,reproduce

Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • scale.py

    r18 r20 ˆà
    11from Tkinter import *ˆà
    2ˆàimport Bacteriaˆà
    3ˆàimport Petriˆà
    ˆà2from math import *ˆà
    ˆà3import bacteriaˆà
    ˆà4import petriˆà
    ˆà5import randomˆà
    ˆà6import vectorˆà
    47ˆà
    58class IF(object):ˆà
    6ˆà    def __init__(self,delay=10,diam=300,num=1,env=1,reprod_a=False,reprod_s=False,life=1):ˆà
    ˆà9    def __init__(self,delay=2,diam=300,num=1,env=1,reprod_a=False,reprod_s=False,life=1):ˆà
    710        self.delay=delayˆà
    811        self.diam=diamˆà
    òÀæ òÀæ ˆà
    1720                                         self.env,self.reprod_a,\ˆà
    1821                                         self.reprod_s,self.life)ˆà
    19ˆà    def mutate():ˆà
    20ˆà        passˆà
    ˆà22    def mutate(self):ˆà
    ˆà23        for bact in p.bacteria:ˆà
    ˆà24            if not(bact.mutated):ˆà
    ˆà25                bact.mutated=Trueˆà
    ˆà26                returnˆà
    2127ˆà
    2228    def sbmt(self):ˆà
    ˆà29        b=[]ˆà
    2330        submit.config(text="Stop",command=self.stop)ˆà
    2431        scl1.config(state=DISABLED)ˆà
    òÀæ òÀæ ˆà
    3441        c.grid(row=0,column=2,rowspan=6,padx=50,pady=10)ˆà
    3542        dish=c.create_oval(10,10,self.diam+10,self.diam+10,fill="white")ˆà
    36ˆà        print selfˆà
    ˆà43        for i in range(self.num):ˆà
    ˆà44            x_i=random.randint(-self.diam/2+15,self.diam/2-15)ˆà
    ˆà45            y_i=random.randint(15+(int)(-sqrt((self.diam/2)**2-x_i**2)),-15+(int)(sqrt((self.diam/2)**2-x_i**2)))ˆà
    ˆà46            b.append(bacteria.Bacteria(vector.Vector(x_i,y_i),ˆà
    ˆà47                              vector.Vector(0,1),ˆà
    ˆà48                              self.life,False))ˆà
    ˆà49        for bact in b:ˆà
    ˆà50            bact.velocity = bact.rnd_velocity(pi/4*random.randrange(0,8))ˆà
    ˆà51        p.num=self.numˆà
    ˆà52        p.bacteria=bˆà
    ˆà53        p.radius=self.diam/2ˆà
    ˆà54        p.delta=5ˆà
    ˆà55        p.bact_r=5ˆà
    ˆà56        p.full_lifetime=self.lifeˆà
    ˆà57        self.depict()ˆà
    3758ˆà
    3859    def stop(self):ˆà
    ˆà60        c.after_cancel(self.rep)ˆà
    ˆà61        c.delete("all")ˆà
    3962        submit.config(text="Submit",command=self.sbmt)ˆà
    4063        scl1.config(state=NORMAL)ˆà
    òÀæ òÀæ ˆà
    5982    ˆà
    6083    def depict(self):ˆà
    61ˆà        passˆà
    ˆà84        c.delete("all")ˆà
    ˆà85        dish=c.create_oval(10,10,self.diam+10,self.diam+10,fill="white")ˆà
    ˆà86        env=scl.get()ˆà
    ˆà87        p.step(0.5,int(env),self.reprod_a,self.reprod_s)ˆà
    ˆà88        for bact in p.bacteria:ˆà
    ˆà89            if bact.mutated:ˆà
    ˆà90                color="black"ˆà
    ˆà91            else:ˆà
    ˆà92                color="white"ˆà
    ˆà93            c.create_oval(10+self.diam/2+bact.position.x-p.bact_r,10+self.diam/2+bact.position.y-p.bact_r,\ˆà
    ˆà94                          10+self.diam/2+bact.position.x+p.bact_r*2,\ˆà
    ˆà95                          10+self.diam/2+bact.position.y+p.bact_r*2,fill=color)ˆà
    ˆà96        self.rep=c.after(self.delay,self.depict)ˆà
    6297ˆà
    63ˆàdef update_scale(widget, times):ˆà
    64ˆà    value = widget.get()ˆà
    65ˆà    length = widget['to'] - widget['from']ˆà
    66ˆà    value += length * times / 10ˆà
    67ˆà    widget.set(value)ˆà
    ˆà98    def update_scale(widget, times):ˆà
    ˆà99        value = widget.get()ˆà
    ˆà100        length = widget['to'] - widget['from']ˆà
    ˆà101        value += length * times / 10ˆà
    ˆà102        widget.set(value)ˆà
    68103ˆà
    69104root = Tk()ˆà
    òÀæ òÀæ ˆà
    71106intf=IF()ˆà
    72107c=Canvas()ˆà
    ˆà108p=petri.Petri()ˆà
    ˆà109b=[]ˆà
    73110ˆà
    74111root.bind_class("Scale", "<4>", lambda ev: update_scale(ev.widget, +1))ˆà
    òÀæ òÀæ ˆà
    99136init_frame.grid(padx=15,pady=10)ˆà
    100137scl1 = Scale(init_frame,orient=HORIZONTAL,length=100,from_=1,\ˆà
    101ˆà                to=50,sliderlength=7,width=10)ˆà
    ˆà138                to=10,sliderlength=7,width=10)ˆà
    102139scl1.grid(row=0, column=0,padx=10,pady=5)ˆà
    103140lbl1 = Label(init_frame,text="number of cells",bg="white")ˆà
    òÀæ òÀæ ˆà
    109146lbl2.grid(row=1,column=1,padx=10)ˆà
    110147scl3 = Scale(init_frame,orient=HORIZONTAL,length=100,from_=1,\ˆà
    111ˆà                to=30,sliderlength=7,width=10)ˆà
    ˆà148                to=1000,sliderlength=7,width=10)ˆà
    112149scl3.grid(row=2, column=0,padx=10,pady=5)ˆà
    113150lbl3 = Label(init_frame,text="cells' lifetime",bg="white")ˆà
Note: See TracChangeset for help on using the changeset viewer.