Skip to content
Snippets Groups Projects
Verified Commit 19891b80 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: small improvements in examples

Also changed `save_image()` method to removed auto format append in file name.
parent 26ba7a72
Branches
Tags
1 merge request!36Support for Python
Pipeline #3635 passed
from time import time
from boytacean import GameBoy, CPU_FREQ
from os.path import dirname, realpath, join
CURRENT_DIR = dirname(realpath(__file__))
ROM_PATH = join(CURRENT_DIR, "../../res/roms/demo/pocket.gb")
CLOCK_COUNT = 100000000
gb = GameBoy(apu_enabled=False, serial_enabled=False)
gb.load_rom("../../res/roms/demo/pocket.gb")
gb.load_rom(ROM_PATH)
start = time()
cycles = gb.clocks(CLOCK_COUNT)
total = time() - start
print(f"Time taken: {total:.2f} seconds")
print(f"Speedup: {cycles / (CPU_FREQ * total):.2f}x")
gb.save_image("pocket.png")
from time import time
from boytacean import GameBoy, VISUAL_FREQ
from os.path import dirname, realpath, join
CURRENT_DIR = dirname(realpath(__file__))
ROM_PATH = join(CURRENT_DIR, "../../res/roms/demo/pocket.gb")
FRAME_COUNT = 12000
gb = GameBoy(apu_enabled=False, serial_enabled=False)
gb.load_rom("../../res/roms/demo/pocket.gb")
gb.load_rom(ROM_PATH)
start = time()
for _ in range(FRAME_COUNT):
gb.next_frame()
......
from time import time
from pyboy import PyBoy, VISUAL_FREQ
from pyboy import PyBoy
from os.path import dirname, realpath, join
CURRENT_DIR = dirname(realpath(__file__))
ROM_PATH = join(CURRENT_DIR, "../../res/roms/demo/pocket.gb")
FRAME_COUNT = 12000
VISUAL_FREQ = 59.7275
with PyBoy("../../res/roms/demo/pocket.gb", disable_renderer=True) as pyboy:
with PyBoy(ROM_PATH, disable_renderer=True) as pyboy:
pyboy.set_emulation_speed(0)
print(pyboy.cartridge_title())
start = time()
......@@ -12,4 +17,6 @@ with PyBoy("../../res/roms/demo/pocket.gb", disable_renderer=True) as pyboy:
total = time() - start
print(f"Time taken: {total:.2f} seconds")
print(f"Speedup: {FRAME_COUNT / total / VISUAL_FREQ:.2f}x")
pyboy.screen_image().save("pocket_pyboy.png")
image = pyboy.screen_image()
if image:
image.save("pocket_pyboy.png")
......@@ -97,7 +97,7 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
def save_image(self, filename: str, format: str = "png"):
image = self.image()
image.save(f"{filename}.{format.lower()}", format=format)
image.save(filename, format=format)
def video(
self,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment