0% found this document useful (0 votes)
7 views4 pages

Pygame Eye Animation Script

The document is a Python script that uses Pygame to create an interactive graphical application featuring two animated 'eyes' represented by rectangles that can blink, look around, and switch to a heart shape. The 'SquareEye' class manages the behavior of these eyes, including their drawing, blinking, and sleeping states. The main loop handles user input and updates the display at a frame rate of 60 FPS.

Uploaded by

emirtan839
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Pygame Eye Animation Script

The document is a Python script that uses Pygame to create an interactive graphical application featuring two animated 'eyes' represented by rectangles that can blink, look around, and switch to a heart shape. The 'SquareEye' class manages the behavior of these eyes, including their drawing, blinking, and sleeping states. The main loop handles user input and updates the display at a frame rate of 60 FPS.

Uploaded by

emirtan839
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import sys

import [Link] as genai


import speech_recognition as sr
from pygame import mixer
import pygame
import webbrowser
from gtts import gTTS
import time
import os
import requests
from bs4 import BeautifulSoup
import subprocess
import [Link]
import psutil
import speedtest
import pyautogui
import tkinter as tk
import pyperclip
import datetime
import random

# Initialize pygame
[Link]()

SCREEN_WIDTH, SCREEN_HEIGHT = 1920, 1080


screen = [Link].set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
[Link].set_caption("Atlas ")

BLACK = (0, 0, 0)
CYAN = (0, 200, 255)
WHITE = (255, 255, 255)
RED = (0, 200, 255)

clock = [Link]()
FPS = 60

# SquareEye class to manage eye behavior


class SquareEye:
def __init__(self, x, y, width, height):
self.x = x
self.y = y
[Link] = width
[Link] = height
self.original_height = height
self.original_width = width
self.look_offset = [0, 0]
self.look_target = [0, 0]
self.look_speed = 10
[Link] = False
[Link] = False
self.sleep_timer = 0
self.blink_frame = 0
self.is_heart = False
self.heart_timer = 0

def draw(self):
if self.is_heart:
self.draw_heart()
else:
[Link](
screen, CYAN,
(self.x + self.look_offset[0], self.y + self.look_offset[1],
[Link], [Link]),
border_radius=20
)
[Link](
screen, WHITE,
(self.x + self.look_offset[0], self.y + self.look_offset[1],
[Link], [Link]),
2,
border_radius=20
)

def draw_heart(self):
center_x = self.x + [Link] // 2 + self.look_offset[0]
center_y = self.y + [Link] // 2 + self.look_offset[1]
[Link](screen, RED, [
(center_x, center_y - [Link] // 2),
(center_x - [Link] // 2, center_y),
(center_x, center_y + [Link] // 2),
(center_x + [Link] // 2, center_y)
])
[Link](screen, RED, (center_x - [Link] // 4, center_y -
[Link] // 4), [Link] // 4)
[Link](screen, RED, (center_x + [Link] // 4, center_y -
[Link] // 4), [Link] // 4)

def look_around(self, x_offset, y_offset):


if not [Link] and not self.is_heart:
self.look_target = [x_offset, y_offset]

def update_look(self):
if self.look_offset[0] != self.look_target[0]:
step_x = (self.look_target[0] - self.look_offset[0]) / self.look_speed
self.look_offset[0] += step_x
if self.look_offset[1] != self.look_target[1]:
step_y = (self.look_target[1] - self.look_offset[1]) / self.look_speed
self.look_offset[1] += step_y

def blink(self):
if not [Link] and not [Link] and not self.is_heart:
[Link] = True
self.blink_frame = 10
elif [Link]:
if self.blink_frame > 0:
scale = self.blink_frame / 10
[Link] = int(self.original_height * scale)
self.blink_frame -= 1
else:
[Link] = self.original_height
[Link] = False

def sleep(self):
if not [Link]:
[Link] = True
self.sleep_timer = 20 * FPS
else:
if self.sleep_timer > 0:
scale = max(self.sleep_timer / (20 * FPS), 0.1)
[Link] = int(self.original_height * scale)
self.sleep_timer -= 1
else:
[Link] = self.original_height
[Link] = False

def activate_heart_mode(self):
self.is_heart = True
self.heart_timer = 5 * FPS

def update_heart_mode(self):
if self.is_heart:
if self.heart_timer > 0:
self.heart_timer -= 1
else:
self.is_heart = False

left_eye = SquareEye(SCREEN_WIDTH // 2 - 180, SCREEN_HEIGHT // 2 - 100, 140, 130)


right_eye = SquareEye(SCREEN_WIDTH // 2 + 40, SCREEN_HEIGHT // 2 - 100, 140, 130)

look_timer = 0
blink_timer = 0
sleep_timer = 0
direction_x = 0
direction_y = 0

while True:
[Link](BLACK)

for event in [Link]():


if [Link] == [Link]:
[Link]()
[Link]()
elif [Link] == [Link]:
if [Link] == pygame.K_SPACE:
left_eye.activate_heart_mode()
right_eye.activate_heart_mode()

left_eye.draw()
right_eye.draw()

left_eye.update_look()
right_eye.update_look()

blink_timer += 1
if blink_timer >= FPS * 5 and not left_eye.sleeping and not right_eye.sleeping:
left_eye.blink()
right_eye.blink()
blink_timer = 0

if not left_eye.sleeping and not right_eye.sleeping and not left_eye.is_heart


and not right_eye.is_heart:
look_timer += 1
if look_timer >= FPS * 2:
direction = [Link]([
(-20, 10), (20, 10),
(-20, -10), (20, -10),
(-20, 0), (20, 0),
(0, -10), (0, 10)
])
direction_x, direction_y = direction
look_timer = 0

left_eye.look_around(direction_x, direction_y)
right_eye.look_around(direction_x, direction_y)

sleep_timer += 1
if sleep_timer >= FPS * 30:
left_eye.sleep()
right_eye.sleep()
sleep_timer = 0

if left_eye.blinking:
left_eye.blink()
if right_eye.blinking:
right_eye.blink()

if left_eye.sleeping:
left_eye.sleep()
if right_eye.sleeping:
right_eye.sleep()

left_eye.update_heart_mode()
right_eye.update_heart_mode()

[Link]()
[Link](FPS)

You might also like