コード例 #1
0
ファイル: anthill.py プロジェクト: quadrohedron/anthill
 def draw(self):
     if self.ds:
         dn, dx = self.ds
         z = self.zoom
         if True:
             for x in range(-dn, dn + 1):
                 for y in range(-dn, dn + 1):
                     if (x, y) in self.content:
                         t = self.content[x, y]
                         scdr.fill(self.types[t][1])
                     else:
                         scdr.fill(self.bgr[1])
                     xr = dx + z * (dn + x)
                     yr = dx + z * (dn + y)
                     scdr.rect(xr, yr, z, z)
         elif self.redraw:
             x, y = self.redraw
             if (x, y) in self.content:
                 t = self.content[x, y]
                 scdr.fill(self.types[t][1])
             else:
                 scdr.fill(self.bgr[1])
             xr = dx + z * (dn + x)
             yr = dx + z * (dn + y)
             scdr.rect(xr, yr, z, z)
コード例 #2
0
		def draw(self):
			if draw_hit_boxes:
				scene_drawing.stroke_weight(2)
				scene_drawing.no_fill()
				
				scene_drawing.stroke(255,0,0)
				scene_drawing.rect(*self.cr.frame)
				
				scene_drawing.stroke(0,0,255)
				scene_drawing.rect(*self.sq.frame)
コード例 #3
0
 def draw(self):
     if debug:
         scene_drawing.stroke(255, 0, 0)
         scene_drawing.stroke_weight(2)
         scene_drawing.no_fill()
         scene_drawing.rect(*self.flapo.get_hitbox())
コード例 #4
0
ファイル: xplodrrr.py プロジェクト: sheblirzan/qdh_pythonista
 def update(self):
     if self.state == 'setup':
         if not self.ghostps or self.realps:
             cd = self.cdict
             Gx, Gy, npart, vmu, sigvmu, thmu, sigthmu = cd['Gx'], cd[
                 'Gy'], cd['npart'], cd['vmu'], cd['sigvmu'], cd[
                     'thmu'] * pi / 180, cd['sigthmu'] * pi / 180
             self.ghostps = []
             for i in range(npart):
                 V = random.gauss(vmu, sigvmu)
                 if thmu < 0:
                     th = 2 * pi * random.random()
                 else:
                     th = random.gauss(thmu, sigthmu)
                 v = vectd(V * cos(th), V * sin(th))
                 c = hsv2rgb(360 * random.random(),
                             min(100, random.gauss(100, 15)),
                             min(100, random.gauss(100, 25)))
                 self.ghostps.append(particle(vectd(Gx, Gy), v, c))
                 self.realps = []
     elif self.state == 'running':
         #			TS=time.time()
         #			DT=TS-self.timestamp
         DT = 1 / 60
         self.deltat += DT
         #			self.timestamp=TS
         ghlen = len(self.ghostps)
         resk = self.cdict['resk']
         for j in range(ghlen + len(self.realps)):
             if j >= ghlen:
                 i = self.realps[j - ghlen]
             else:
                 i = self.ghostps[j]
             if self.boundson:
                 COR = self.cdict['cor']
                 nx = i.p.x + i.v.x * 100 * DT
                 if nx < 0:
                     i.p.x = 0
                     i.v.x *= -COR
                     i.v.y *= COR
                 elif nx > 723:
                     i.p.x = 723
                     i.v.x *= -COR
                     i.v.y *= COR
                 else:
                     i.p.x = nx
                 ny = i.p.y + i.v.y * 100 * DT
                 if ny < 0:
                     i.p.y = 0
                     i.v.x *= COR
                     i.v.y *= -COR
                 elif ny > 703:
                     i.p.y = 703
                     i.v.x *= COR
                     i.v.y *= -COR
                 else:
                     i.p.y = ny
                 nx = i.p.x + i.v.x * 100 * DT
                 if nx < 0:
                     i.p.x = 0
                     i.v.x *= -COR
                     i.v.y *= COR
                 elif nx > 723:
                     i.p.x = 723
                     i.v.x *= -COR
                     i.v.y *= COR
             else:
                 i.p += i.v * (100 * DT)
             if self.reson:
                 i.v -= i.v.norm() * (i.v.dot(i.v) * resk)
             i.v += self.g * DT
     for i in self.ghostps + self.realps:
         scdr.fill(i.c)
         scdr.rect(i.p.x - 2, i.p.y - 2, 4, 4)
     if self.mainview:
         self.mainview['timelabel'].text = 'T = ' + str(self.deltat)
コード例 #5
0
    def update(self):
        if self.state == 'setup':
            if not self.ghostps or self.realps:
                cd = self.cdict
                Gx, Gy, npart, vmu, sigvmu, thmu, sigthmu = cd['Gx'], cd[
                    'Gy'], cd['npart'], cd['vmu'], cd['sigvmu'], cd[
                        'thmu'] * pi / 180, cd['sigthmu'] * pi / 180
                self.ghostps = []
                for i in range(npart):
                    V = random.gauss(vmu, sigvmu)
                    if thmu < 0:
                        th = 2 * pi * random.random()
                    else:
                        th = random.gauss(thmu, sigthmu)
                    v = vectd(V * cos(th), V * sin(th))
                    c = hsv2rgb(360 * random.random(),
                                min(100, random.gauss(100, 15)),
                                min(100, random.gauss(100, 25)))
                    self.ghostps.append(particle(vectd(Gx, Gy), v, c))
                    self.realps = []
        elif self.state == 'running':
            #			TS=time.time()
            #			DT=TS-self.timestamp
            DT = 1 / 60
            self.deltat += DT
            #			self.timestamp=TS
            rlen = len(self.realps)
            resk = self.cdict['resk']
            if self.ghostps:
                reloc = []
            COR = self.cdict['cor']
            for j in range(rlen + len(self.ghostps)):
                if j >= rlen:
                    i = self.ghostps[j - rlen]
                else:
                    i = self.realps[j]
                    for q in self.realps[:j] + self.realps[j + 1:]:
                        if abs(q.p - i.p) < 4:
                            c = (q.p - i.p).norm()
                            nc = vectd(-c.y, c.x)
                            vic, vqc = c.dot(i.v), c.dot(q.v)
                            vin, vqn = nc.dot(i.v), nc.dot(q.v)
                            vcmu = (vic + vqc) / 2
                            i.p -= c * 2
                            q.p += c * 2
                            i.v = c * (vcmu - vic * COR) + nc * vin
                            q.v = c * (vcmu - vqc * COR) + nc * vqn
                if self.boundson:
                    nx = i.p.x + i.v.x * 100 * DT
                    if nx < 0:
                        i.p.x = 0
                        i.v.x *= -COR
                    elif nx > 723:
                        i.p.x = 723
                        i.v.x *= -COR
                    else:
                        i.p.x = nx
                    ny = i.p.y + i.v.y * 100 * DT
                    if ny < 0:
                        i.p.y = 0
                        i.v.y *= -COR
                    elif ny > 703:
                        i.p.y = 703
                        i.v.y *= -COR
                    else:
                        i.p.y = ny
                    nx = i.p.x + i.v.x * 100 * DT
                    if nx < 0:
                        i.p.x = 0
                        i.v.x *= -COR
                    elif nx > 723:
                        i.p.x = 723
                        i.v.x *= -COR
                else:
                    i.p += i.v * (100 * DT)
                if j >= rlen:

                    if not sum(
                            map(
                                lambda x: abs(x.p - i.p) < 4,
                                self.ghostps[:j - rlen] +
                                self.ghostps[j + 1 - rlen:] + self.realps)):
                        reloc.append(j - rlen)
                if self.reson:
                    i.v -= i.v.norm() * (i.v.dot(i.v) * resk)
                i.v += self.g * DT
            if self.ghostps and reloc:
                for i in reloc:
                    self.realps.append(self.ghostps[i])
                for i in sorted(reloc, key=int.__neg__):
                    del self.ghostps[i]
        for i in self.ghostps + self.realps:
            scdr.fill(i.c)
            scdr.rect(i.p.x - 2, i.p.y - 2, 4, 4)
        if self.mainview:
            self.mainview['timelabel'].text = 'T = ' + str(self.deltat)
コード例 #6
0
	def update(self):
		if self.state=='setup':
			if not self.ghostps or self.realps:
				cd=self.cdict
				Gx,Gy,npart,vmu,sigvmu,thmu,sigthmu= cd['Gx'],cd['Gy'],cd['npart'],cd['vmu'],cd['sigvmu'], cd['thmu']*pi/180,cd['sigthmu']*pi/180
				self.ghostps=[]
				for i in range(npart):
					V=random.gauss(vmu,sigvmu)
					if thmu<0:
						th=2*pi*random.random()
					else:
						th=random.gauss(thmu,sigthmu)
					v=vectd(V*cos(th),V*sin(th))
					c=hsv2rgb(360*random.random(), min(100,random.gauss(100,15)),min(100, random.gauss(100,25)))
					self.ghostps.append(particle(vectd(Gx,Gy),v,c))
					self.realps=[]
		elif self.state=='running':
#			TS=time.time()
#			DT=TS-self.timestamp
			DT=1/60
			self.deltat+=DT
#			self.timestamp=TS
			rlen=len(self.realps)
			resk=self.cdict['resk']
			if self.ghostps:
				reloc=[]
			COR=self.cdict['cor']
			for j in range(rlen+len(self.ghostps)):
				if j>=rlen:
					i=self.ghostps[j-rlen]
				else:
					i=self.realps[j]
					for q in self.realps[:j]+self.realps[j+1:]:
						if abs(q.p-i.p)<4:
							c=(q.p-i.p).norm()
							nc=vectd(-c.y,c.x)
							vic,vqc=c.dot(i.v),c.dot(q.v)
							vin,vqn=nc.dot(i.v),nc.dot(q.v)
							vcmu=(vic+vqc)/2
							i.p-=c*2
							q.p+=c*2
							i.v=c*(vcmu-vic*COR)+nc*vin
							q.v=c*(vcmu-vqc*COR)+nc*vqn
				if self.boundson:
					nx=i.p.x+i.v.x*100*DT
					if nx<0:
						i.p.x=0
						i.v.x*=-COR
					elif nx>723:
						i.p.x=723
						i.v.x*=-COR
					else:
						i.p.x=nx
					ny=i.p.y+i.v.y*100*DT
					if ny<0:
						i.p.y=0
						i.v.y*=-COR
					elif ny>703:
						i.p.y=703
						i.v.y*=-COR
					else:
						i.p.y=ny
					nx=i.p.x+i.v.x*100*DT
					if nx<0:
						i.p.x=0
						i.v.x*=-COR
					elif nx>723:
						i.p.x=723
						i.v.x*=-COR
				else:
					i.p+=i.v*(100*DT)
				if j>=rlen:
					
					if not sum(map(lambda x:abs(x.p-i.p)<4, self.ghostps[:j-rlen]+self.ghostps[j+1-rlen:] +self.realps)):
						reloc.append(j-rlen)
				if self.reson:
					i.v-=i.v.norm()*(i.v.dot(i.v)*resk)
				i.v+=self.g*DT
			if self.ghostps and reloc:
				for i in reloc:
					self.realps.append(self.ghostps[i])
				for i in sorted(reloc,key=int.__neg__):
					del self.ghostps[i]
		for i in self.ghostps+self.realps:
			scdr.fill(i.c)
			scdr.rect(i.p.x-2,i.p.y-2,4,4)
		if self.mainview:
			self.mainview['timelabel'].text='T = '+str(self.deltat)
コード例 #7
0
	def update(self):
		if self.state=='setup':
			if not self.ghostps or self.realps:
				cd=self.cdict
				Gx,Gy,npart,vmu,sigvmu,thmu,sigthmu= cd['Gx'],cd['Gy'],cd['npart'],cd['vmu'],cd['sigvmu'], cd['thmu']*pi/180,cd['sigthmu']*pi/180
				self.ghostps=[]
				for i in range(npart):
					V=random.gauss(vmu,sigvmu)
					if thmu<0:
						th=2*pi*random.random()
					else:
						th=random.gauss(thmu,sigthmu)
					v=vectd(V*cos(th),V*sin(th))
					c=hsv2rgb(360*random.random(), min(100,random.gauss(100,15)),min(100, random.gauss(100,25)))
					self.ghostps.append(particle(vectd(Gx,Gy),v,c))
					self.realps=[]
		elif self.state=='running':
#			TS=time.time()
#			DT=TS-self.timestamp
			DT=1/60
			self.deltat+=DT
#			self.timestamp=TS
			ghlen=len(self.ghostps)
			resk=self.cdict['resk']
			for j in range(ghlen+len(self.realps)):
				if j>=ghlen:
					i=self.realps[j-ghlen]
				else:
					i=self.ghostps[j]
				if self.boundson:
					COR=self.cdict['cor']
					nx=i.p.x+i.v.x*100*DT
					if nx<0:
						i.p.x=0
						i.v.x*=-COR
						i.v.y*=COR
					elif nx>723:
						i.p.x=723
						i.v.x*=-COR
						i.v.y*=COR
					else:
						i.p.x=nx
					ny=i.p.y+i.v.y*100*DT
					if ny<0:
						i.p.y=0
						i.v.x*=COR
						i.v.y*=-COR
					elif ny>703:
						i.p.y=703
						i.v.x*=COR
						i.v.y*=-COR
					else:
						i.p.y=ny
					nx=i.p.x+i.v.x*100*DT
					if nx<0:
						i.p.x=0
						i.v.x*=-COR
						i.v.y*=COR
					elif nx>723:
						i.p.x=723
						i.v.x*=-COR
						i.v.y*=COR
				else:
					i.p+=i.v*(100*DT)
				if self.reson:
					i.v-=i.v.norm()*(i.v.dot(i.v)*resk)
				i.v+=self.g*DT
		for i in self.ghostps+self.realps:
			scdr.fill(i.c)
			scdr.rect(i.p.x-2,i.p.y-2,4,4)
		if self.mainview:
			self.mainview['timelabel'].text='T = '+str(self.deltat)