本文整理汇总了Python中weather.Weather.update方法的典型用法代码示例。如果您正苦于以下问题:Python Weather.update方法的具体用法?Python Weather.update怎么用?Python Weather.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类weather.Weather
的用法示例。
在下文中一共展示了Weather.update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Visualization
# 需要导入模块: from weather import Weather [as 别名]
# 或者: from weather.Weather import update [as 别名]
class Visualization(object):
def __init__(self, width=64, height=64):
self.width = width
self.height = height
self.frame = 0
self.starttime = time.time()
self.im = Image.new("RGBA", (width,height), "black")
self.im_draw = ImageDraw.Draw(self.im)
self.bg = Image.open("images/bg_normal_big.png")
self.bgofs = 0
self.font = ImageFont.truetype("fonts/spincycle.ttf", 18)
self.font_sm = ImageFont.truetype("fonts/pf_tempesta_seven.ttf", 8)
self.clouds = Cloud.create(20)
self.weather = Weather()
self.rain = Rain()
self.conditions = ""
def drawtime(self):
now = datetime.datetime.now()
t = now.strftime("%I:%M")
size = self.im_draw.textsize(t, font=self.font)
x = self.width / 2 - size[0] / 2
self.im_draw.text((x,0), t, (16,16,16) ,font=self.font)
def updateweather(self):
self.weather.update()
clouds = int(self.weather.cover * 20)
if (self.weather.wind == 0):
cloudspeed = 0
elif (self.weather.windbearing <= 90 or self.weather.windbearing >= 270):
cloudspeed = float(self.weather.wind)/-30.0
else:
cloudspeed = float(self.weather.wind)/30.0
for i in xrange(clouds,20):
if self.clouds[i].active:
self.clouds[i].deactivate()
for i in xrange(clouds):
self.clouds[i].activate(cloudspeed)
if (self.weather.conditions == 'snow' or self.weather.conditions == 'hail' or self.weather.conditions == 'sleet'):
self.bg = Image.open('images/bg_icy_normal.png')
elif (time.time() > self.weather.sunset + 1800 and time.time() < self.weather.sunrise):
self.bg = Image.open('images/bg_night.png')
elif (self.weather.cover > 0.75):
self.bg = Image.open('images/bg_dark.png')
elif (time.time() >= self.weather.sunset and time.time() <= self.weather.sunset + 1800):
self.bg = Image.open('images/bg_sunset_big.png')
elif (time.time() >= self.weather.sunrise and time.time() <= self.weather.sunrise + 1800):
self.bg = Image.open('images/bg_sunset_big.png')
else:
self.bg = Image.open('images/bg_normal_big.png')
def drawweather(self):
cond = self.weather.conditions
if (cond == "rain" or cond == "hail" or
cond == "thunderstorm" or cond == "snow" or
cond == "sleet"):
self.rain.move()
self.rain.paint(self.im_draw, (225,225,225) if (cond =="snow" or cond == "sleet") else (96,96,200))
for i in xrange(20):
self.clouds[i].move()
self.clouds[i].paint(self.im)
self.im_draw.text((17,53), "{0}".format(int(float(self.weather.temp))), (0,0,0) ,font=self.font_sm)
self.im_draw.point((30,57),(0,0,0))
self.im_draw.point((31,58),(0,0,0))
self.im_draw.point((30,59),(0,0,0))
self.im_draw.point((29,58),(0,0,0))
self.im_draw.text((33,53), "{0}".format(int(float(self.weather.rf))), (0,0,0) ,font=self.font_sm)
self.im_draw.point((46,57),(0,0,0))
self.im_draw.point((47,58),(0,0,0))
self.im_draw.point((46,59),(0,0,0))
self.im_draw.point((45,58),(0,0,0))
def drawbg(self):
if self.bg.size[0] > self.width:
if self.frame % 30 == 0:
self.bgofs = self.bgofs + 1
if self.bgofs > self.bg.size[0]:
self.bgofs = 0
self.im.paste(self.bg.crop((self.bgofs,0,self.width+self.bgofs,self.height)), (0,0,self.width,self.height))
if self.bgofs > self.bg.size[0]-self.width:
o = self.width-(self.bg.size[0]-self.bgofs)
self.im.paste(self.bg.crop((0,0,o,self.height)), (self.width-o,0,self.width,self.height))
else:
#.........这里部分代码省略.........
示例2: MapContext
# 需要导入模块: from weather import Weather [as 别名]
# 或者: from weather.Weather import update [as 别名]
#.........这里部分代码省略.........
#self.camera.zoom_target = 1.5/settings.scale
#self.camera.zoom_rate = 7.5
for crow in self.murder.crows:
crow.resting = False
crow.speed = speed
crow.moveTowards(random.random() * 4 + wx, random.random() * 4 + wy )
def on_mouse_release(self, x, y, button, modifiers):
if button == 1:
wx, wy = self.camera.pixel_to_world(x, y)
for crow in self.murder.crows:
crow.resting = False
crow.target = box2d.b2Vec2(
random.randint(int(wx)-3, int(wx)+3),
self.world_height*1.2)
crow.speed = settings.crow_idle_speed
#self.camera.zoom_target = 0.75/settings.scale
#self.camera.zoom_rate = 7.5
self.mouse_down = False
def on_mouse_drag(self, x, y, dx, dy, button, modifiers):
if button == 1:
wx, wy = self.camera.pixel_to_world(x, y)
self.mx, self.my = wx, wy
for crow in self.murder.crows:
crow.moveTowards(random.random() + wx, random.random() + wy )
else:
self.camera.move_by(-dx, -dy)
@property
def width(self): return self.worldAABB.upperBound.x
@property
def height(self): return self.worldAABB.upperBound.y
def spawn_enemies(self, dt):
self.spawn_countdown -= dt
if self.spawn_countdown <= 0:
self.spawn_countdown = self.spawn_time
if self.spawn_countdown < 3.5: self.spawn_countdown = 3.5
self.average_speed += 0.2
self.spawn_time -= 0.15
if self.spawn_time < 2: self.spawn_countdown = 2
for x in range(int(self.spawn_rate)):
self.people.append(person.Person(self.world, (x*2, 70), self.average_speed + random.random()))
self.spawn_rate += 0.15
print "Spawn Countdown:", self.spawn_countdown,
print ", Spawn Rate:", self.spawn_rate,
print ", Average Speed:", self.average_speed
def update(self, dt):
if self.time >= 140:
self.switch_requested("WinContext")
self.time += dt
self.spawn_enemies(dt)
for thing in self.things:
thing.update(dt)
people_to_remove = []
for person in self.people:
person.update(dt)
if len(self.people) > settings.max_people and len(person.joints) <= 3:
people_to_remove.append(person)
elif person.Chest.position.x >= self.world_width - 2 and not person.is_dead:
person.remove_from_world()
gamestats.add_survivor()
#Only remove one of the People To Remove
if len(people_to_remove):
people_to_remove[-1].remove_from_world()
self.people.remove(people_to_remove[-1])
if self.mouse_down:
d = (b2Vec2(self.mx, self.my) - self.camera.look_at).Length()
self.camera.move_towards(self.mx, self.my, max(d, 2), dt)
self.murder.update(dt)
self.weather.update(dt)
self.camera.update(dt)
self.world.SetContinuousPhysics(True)
# Tell Box2D to step
if dt > .1: dt = .1
self.world.Step(dt, 10, 10)
self.world.Validate()
def predraw(self): pass
def draw(self):
with Projection(self.camera) as projection:
self.weather.draw_background()
self.svg.draw(0,0, 0, 0, settings.scale*settings.svgscale)
pyglet.gl.gl.glColor4f(0,0,0,1)
self.murder.draw()
for thing in self.things:
thing.draw()
for person in self.people:
person.draw()
self.weather.draw_foreground()