namuan / llm-playground

Experiments with open source LLMs
MIT License
63 stars 10 forks source link

AI Clippy #1

Open namuan opened 7 months ago

namuan commented 7 months ago

Create an animated character which stays on your screen and provide suggestions/feedback on your code

namuan commented 7 months ago

Prompting Claude Sonnet model

Here's the full code with all the necessary imports and comments:

import arcade
import pyglet
import time

# Dependencies:
# - Python (version 3.6 or later)
# - Arcade library (install with `pip install arcade`)

# Constants
SPRITE_SCALING = 0.5
CHARACTER_SCALING = 0.5
SPRITE_WIDTH = 64
SPRITE_HEIGHT = 64
API_INTERVAL = 5  # API call interval in seconds

# Hard-coded API response for now
API_RESPONSE = "Hello, this is a test response from the API!"

class SpeechBubble(arcade.SpriteSolidColor):
    def __init__(self, text, x, y, width, height, color):
        super().__init__(width, height, color)
        self.text = text
        self.center_x = x
        self.center_y = y

    def draw(self):
        super().draw()
        arcade.draw_text(self.text, self.center_x, self.center_y, arcade.csscolor.BLACK, 12, anchor_x="center", anchor_y="center")

class MyGame(arcade.Window):
    def __init__(self):
        # Get the screen size
        screen_width, screen_height = arcade.get_display_size()

        super().__init__(screen_width, screen_height, borderless=True, transparent=True)
        arcade.set_background_color(arcade.csscolor.TRANSPARENT)

        # Load the sprite sheet
        self.character_sprite_sheet = arcade.load_texture("ghost_sprite_sheet.png")

        # Define the animation sequences
        self.animation_frames = arcade.load_animated_texture_sequence(
            self.character_sprite_sheet,
            0, 0,
            SPRITE_WIDTH, SPRITE_HEIGHT,
            8, 8,
            0.1
        )

        # Create the animated sprite
        self.character_sprite = arcade.AnimatedSprite()
        self.character_sprite.texture_sequence = self.animation_frames
        self.character_sprite.center_x = screen_width - (SPRITE_WIDTH // 2 * CHARACTER_SCALING)
        self.character_sprite.center_y = SPRITE_HEIGHT // 2 * CHARACTER_SCALING
        self.character_sprite.scale = CHARACTER_SCALING

        # Create the speech bubble
        self.speech_bubble = SpeechBubble(API_RESPONSE, screen_width // 2, screen_height // 2, 300, 100, arcade.csscolor.WHITE)

        # Set the last API call time
        self.last_api_call = time.time()

    def on_update(self, delta_time):
        self.character_sprite.update_animation()

        # Make an API call at regular intervals
        current_time = time.time()
        if current_time - self.last_api_call >= API_INTERVAL:
            self.last_api_call = current_time
            # Make API call here and update self.speech_bubble.text

    def on_draw(self):
        self.clear()
        self.character_sprite.draw()
        self.speech_bubble.draw()

def main():
    window = MyGame()
    window.set_visible(True)
    arcade.run()

if __name__ == "__main__":
    main()

To run this code, you'll need to have the following dependencies installed:

  1. Python: You'll need Python 3.6 or later installed on your system. You can download the latest version of Python from the official website: https://www.python.org/downloads/

  2. Arcade Library: The Arcade library is a Python library for creating 2D games. You can install it using pip, the Python package installer:

    pip install arcade

    If you're using a virtual environment or have multiple Python versions installed, make sure you're installing the library in the correct environment.

  3. Sprite Sheet Image: You'll also need the "ghost_sprite_sheet.png" file, which contains the sprite sheet for the animated character. Make sure this file is in the same directory as your Python script.

Once you have Python and the Arcade library installed, and the sprite sheet image file in the correct location, you should be able to run the code without any issues.

Note that this code doesn't include any actual API call functionality; it's just a skeleton to demonstrate how you can integrate API calls and display the response in a speech bubble. You'll need to replace the commented line # Make API call here and update self.speech_bubble.text with your actual API call code and update the self.speech_bubble.text with the received response.

namuan commented 7 months ago

Generated sprite sheet using StableDiffusion IMG_6684

namuan commented 7 months ago

Claude.ai seems to be making up some stuff. Here is the answer from GPT 4

Below is a Python script that uses the Arcade library to animate a character walking using a sprite sheet. The sprite sheet is assumed to be arranged in an 8x8 grid, with each cell containing a frame of the animation.

Firstly, ensure that you have installed the Arcade library in your Python environment. You can install it using pip:

pip install arcade

Here's a simple script to animate the character:

import arcade
import os

# Constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
SCREEN_TITLE = "Sprite Sheet Animation Example"

# Constants for the sprite sheet
SPRITE_SCALING = 1.0
SPRITE_SIZE = 128  # The size of the sprite in the sheet
SPRITE_IMAGE_COUNT = 64  # Assuming an 8x8 grid
COLUMNS = 8
COUNTDOWN = 1  # Time in seconds to update the frame

class MyGame(arcade.Window):
    def __init__(self):
        super().__init__(SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_TITLE)

        self.character_list = None

        # Load the texture at the beginning
        self.character_walk_textures = []

        # Set up the player info
        self.current_texture = 0
        self.frame = 0
        self.countdown = COUNTDOWN

        # Set the background color
        arcade.set_background_color(arcade.color.AMAZON)

    def setup(self):
        # Set up the game and initialize the variables
        self.character_list = arcade.SpriteList()

        # Assuming the sprite sheet is in the 'resources/images' directory
        sprite_sheet_path = os.path.join("resources", "images", "character_sheet.png")

        # Load the sprite sheet
        self.character_walk_textures = arcade.load_spritesheet(
            sprite_sheet_path,
            SPRITE_SIZE, SPRITE_SIZE,
            COLUMNS, SPRITE_IMAGE_COUNT // COLUMNS, SPRITE_SCALING
        )

        # Create the sprite
        self.character_sprite = arcade.Sprite()
        for texture in self.character_walk_textures:
            self.character_sprite.append_texture(texture)

        # Set the sprite's initial texture
        self.character_sprite.set_texture(self.current_texture)
        self.character_sprite.center_x = SCREEN_WIDTH // 2
        self.character_sprite.center_y = SCREEN_HEIGHT // 2

        # Add the sprite to the list of sprites
        self.character_list.append(self.character_sprite)

    def on_draw(self):
        # Render the screen
        arcade.start_render()

        # Draw the sprites
        self.character_list.draw()

    def update(self, delta_time):
        # Update the animation every second
        self.countdown -= delta_time
        if self.countdown <= 0:
            self.countdown = COUNTDOWN
            self.current_texture += 1
            if self.current_texture >= len(self.character_walk_textures):
                self.current_texture = 0
            self.character_sprite.set_texture(self.current_texture)

def main():
    game = MyGame()
    game.setup()
    arcade.run()

if __name__ == "__main__":
    main()

In this script:

Make sure to replace "resources", "images", "character_sheet.png" with the correct path to your sprite sheet image file in the setup method. The SPRITE_SIZE and SPRITE_SCALING values should also be adjusted based on the actual size of your sprites and how large you want them displayed on the screen.