コード例 #1
0
 def update(self):
     offset = 5 * (tween.easeInOutSine(self.step / 11) - 0.5)
     self.rect.centery = self.pos.y + offset * self.direction
     self.step += 0.4
     if self.step > 10:
         self.step = 0
         self.direction *= -1
コード例 #2
0
 def Loop(self, DISPLAY: pygame.surface.Surface, dt):
     DISPLAY.blit(self.img, self.img_rect)
     DISPLAY.blit(self.text, (WIDTH / 2 - self.text.get_width() / 2,
                              HEIGHT * 3 / 4 - self.text.get_height() / 2))
     self.time += dt
     if self.time <= 4:
         sur = pygame.surface.Surface((WIDTH, HEIGHT))
         sur.fill(pygame.Color(0, 0, 0))
         sur.set_alpha(255 - 255 * tween.easeInOutSine(self.time / 4))
         DISPLAY.blit(sur, (0, 0))
     elif self.time <= 8:
         sur = pygame.surface.Surface((WIDTH, HEIGHT))
         sur.fill(pygame.Color(0, 0, 0))
         sur.set_alpha(255 * tween.easeInOutSine((self.time - 4) / 4))
         DISPLAY.blit(sur, (0, 0))
     else:
         self.state["atual"] = GameState()
コード例 #3
0
def make_frame(t):
    #colorDiv = t + 0.01
    #color1= [1.0 / colorDiv, 0.0, 0.0]
    #color2 = [0.0, 1.0 / colorDiv, 0.0]

    #gradient= gizeh.ColorGradient("linear",((0,(0,.5,1)),(1,(0,1,1))), xy1=(-cosR,-sinR), xy2=(cosR,sinR))

    #gradRad1 = radius1 - 20
    #gradRad2 = radius1 + 20
    #gradient = gizeh.ColorGradient(type="radial",
    #                               stops_colors = [(0,color1),(1,color2)],
    #                               xy1=[0.0,0.0], xy2=[gradRad1,0.0], xy3 = [0.0,gradRad2])
    surface = gizeh.Surface(W,H)

    # orbit halo
    #circle1 = gizeh.circle(radius1, xy = (W/2, H/2), stroke=gradient, stroke_width=5)
    #circle1.draw(surface)

    for i in range(numParticles):
      # Orbiting planet
      particle = particles[i]

      if (particle.easing == 1):
        angle = pytweening.linear((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 2):
        angle = pytweening.easeInQuad((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 3):
        angle = pytweening.easeOutQuad((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 4):
        angle = pytweening.easeInOutQuad((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 5):
        angle = pytweening.easeInSine((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 6):
        angle = pytweening.easeOutSine((duration - t) / duration) * 360 * particle.direction
      elif (particle.easing == 7):
        angle = pytweening.easeInOutSine((duration - t) / duration) * 360 * particle.direction
      radians = math.radians(angle)
      cosR = math.cos(radians)
      sinR = math.sin(radians)
      x = W/2 + cosR * particle.orbit_radius
      y = H/2 + sinR * particle.orbit_radius
      fill = particle.color
      #circle = gizeh.circle(particle.radius, xy = (x, y), fill=(1,0,1))
      circle = gizeh.circle(particle.radius, xy = (x, y), fill=fill)
      circle.draw(surface)

    return surface.get_npimage()
コード例 #4
0
ファイル: map.py プロジェクト: YandexLazyBoy/hotline_miami
 def render(self, rm):
     self.image = self.orig_canvas.copy()
     self.bullets.draw(self.image)
     if rm in (0, 1):
         self.animated_geometry.draw(self.image)
     overlap = self.checkCollision()
     self.image.blit(self.player.image, self.player.o_rect)
     r = math.degrees(math.atan2(abs(self.map_size[1] // 2 - self.player.center[1]),
                                 abs(self.map_size[0] // 2 - self.player.center[0])))
     if r > 45:
         r = 90 - r
     r = tween.easeInOutSine(r / 45)
     if overlap:
         if len(overlap[0]) > 2:
             pygame.draw.polygon(self.image, (255, 120, 120), overlap[0], 0)
             pygame.draw.line(self.image, (120, 130, 130), overlap[1], overlap[2], 2)
     self.image = pygame.transform.rotate(self.image, r)
     if self.DL == 4:
         pygame.draw.rect(self.image, self.dbc, self.image.get_rect(), 2)
コード例 #5
0
 def update(time_ms: float):
     print(f'time_ms={time_ms}')
     duration = 12000                    # 12000
     if time_ms < duration: # spin
         progress = time_ms / duration
         rotation = pytweening.easeInOutSine(progress) * 360
         ax.view_init(30, rotation)
         return ax
     time_ms -= duration
     duration = 3000                     # 15000
     if time_ms < duration: # wait
         if time_ms - 16.67 <= 0:
             ax.view_init(30, 0)
             return ax
         return tuple()
     time_ms -= duration
     duration = 3000                     # 18000
     if time_ms < duration: # elev from 30 to -30
         progress = time_ms / duration
         elev = 30 - 60 * pytweening.easeInOutBack(progress)
         ax.view_init(elev, 0)
         return ax
     time_ms -= duration
     duration = 1500                     # 19500
     if time_ms < duration: # wait
         if time_ms - 16.67 <= 0:
             ax.view_init(-30, 0)
             return ax
         return tuple()
     time_ms -= duration
     duration = 3000                     # 22500
     if time_ms < duration: # elev from -30 to 30
         progress = time_ms / duration
         elev = -30 + 60 * pytweening.easeInOutBack(progress)
         ax.view_init(elev, 0)
         return ax
     time_ms -= duration
     # wait rest                         # 24000
     if time_ms - 16.67 <= 0:
         ax.view_init(30, 0)
         return ax
     return tuple()
コード例 #6
0
ファイル: wait_circles.py プロジェクト: mysteryDate/pyvector
def make_frame(t):
    surface = gz.Surface(R, R)
    background = gz.square(l=R, xy= [R/2,R/2], fill = (1,1,1,1))
    background.draw(surface)
    r = R/4
    ith = -np.pi/2
    C = pytweening.easeInOutSine(t/DURATION)
    # C = t/DURATION
    for i in range(NCIRCLES):
		th = ith + (i+1)*(2*np.pi*NROTATIONS) * C
		center = gz.polar2cart(R/4,th)
		color = (1.0,1.0,1.0,1.0/255)
		if i % 3 == 0:
			color = (1.0,0,0,1.0/255)
		elif i % 3 == 1:
			color = (0,1.0,0,1.0/255)
		else:
			color = (0,0,1.0,1.0/255)
		cir = gz.circle(R/4 - (i/4), fill=color, xy=center)
		cir.translate([R/2,R/2]).draw(surface)
    im = 255*((surface.get_npimage()) % 2)
    return im
コード例 #7
0
    def blur(self):
        #difumina la pantalla
        if not self.hacer_blur:
            self.hacer_blur = True
            self.signo = 1
            self.blur_value = 1
            self.step = 1.0
            self.last_update_blur = 0
            self.loop = 1
            print 'hola'

        #modificar blur
        now = pg.time.get_ticks()
        if now - self.last_update_blur > 50:
            self.last_update_blur = now
            offset = 5 * (tween.easeInOutSine(self.step / 10))
            self.blur_value = round(self.blur_value + offset * self.signo, 3)

            self.step += 0.78
            if self.step > 5:
                if self.loop > 3:
                    self.hacer_blur = False
                self.step = 0
                self.signo *= -1
                self.loop += 1

        #aplicar blur
        surface = self.game.pantalla.copy()
        surf_size = surface.get_size()
        self.scale = 1.0 / self.blur_value
        scale_size = (int(surf_size[0] * self.scale),
                      int(surf_size[1] * self.scale))

        surf = pg.transform.smoothscale(surface, scale_size)

        surf = pg.transform.smoothscale(surf, surf_size)
        self.game.pantalla.blit(surf, (0, 0))
コード例 #8
0
 def ease_in_out_sine(n):
     """ 两端快,中间慢(正弦函数) """
     return pytweening.easeInOutSine(n)
コード例 #9
0
def run_pattern(df,
                target,
                iters=100000,
                num_frames=100,
                decimals=2,
                shake=0.2,
                max_temp=0.4,
                min_temp=0,
                ramp_in=False,
                ramp_out=False,
                freeze_for=0,
                labels=["X Mean", "Y Mean", "X SD", "Y SD", "Corr."],
                reset_counts=False,
                custom_points=False):

    global frame_count
    global it_count

    if reset_counts:
        it_count = 0
        frame_count = 0

    r_good = df.copy()

    # this is a list of frames that we will end up writing to file
    write_frames = [
        int(round(pytweening.linear(x) * iters))
        for x in np.arange(0, 1, 1 / (num_frames - freeze_for))
    ]

    if ramp_in and not ramp_out:
        write_frames = [
            int(round(pytweening.easeInSine(x) * iters))
            for x in np.arange(0, 1, 1 / (num_frames - freeze_for))
        ]
    elif ramp_out and not ramp_in:
        write_frames = [
            int(round(pytweening.easeOutSine(x) * iters))
            for x in np.arange(0, 1, 1 / (num_frames - freeze_for))
        ]
    elif ramp_out and ramp_in:
        write_frames = [
            int(round(pytweening.easeInOutSine(x) * iters))
            for x in np.arange(0, 1, 1 / (num_frames - freeze_for))
        ]

    extras = [iters] * freeze_for
    write_frames.extend(extras)

    # this gets us the nice progress bars in the notbook, but keeps it from crashing
    looper = trange
    if is_kernel():
        looper = tnrange

    # this is the main loop, were we run for many iterations to come up with the pattern
    for i in looper(iters + 1,
                    leave=True,
                    ascii=True,
                    desc=target + " pattern"):
        t = (max_temp - min_temp) * s_curve(((iters - i) / iters)) + min_temp

        if target in all_targets:
            test_good = perturb(r_good.copy(),
                                initial=df,
                                target=target,
                                temp=t)
        else:
            raise Exception("bah, that's not a proper type of pattern")

        # here we are checking that after the purturbation, that the statistics are still within the allowable bounds
        if is_error_still_ok(df, test_good, decimals):
            r_good = test_good

        # save this chart to the file
        for x in xrange(write_frames.count(i)):
            save_scatter_and_results(r_good,
                                     target + "-image-" +
                                     format(int(frame_count), '05'),
                                     150,
                                     labels=labels)
            #save_scatter(r_good, target + "-image-"+format(int(frame_count), '05'), 150)
            r_good.to_csv(target + "-data-" + format(int(frame_count), '05') +
                          ".csv")

            frame_count = frame_count + 1
    return r_good