gaming-pads/flood-fill.py

77 lines
1.9 KiB
Python

import pyray as RL
from pyray import (Rectangle as Rect, Vector2 as Vec2, Vector3 as Vec3, Camera3D, BoundingBox)
import math
import pdb
import random
from typing import Optional, Tuple, List
from dataclasses import dataclass, field
def dump(struct):
s = f"{RL.ffi.typeof(struct)}: (".replace('<ctype ', '').replace('>', '')
for field in dir(struct):
data = struct.__getattribute__(field)
if str(data).startswith("<cdata"):
data = dump(data)
s += f"{field}:{data} "
s += ")"
return s
screen_width = 900
screen_height = 900
max_radius = 25
paint_tank_max = 250
@dataclass
class World:
buffer: RL.Image
texture: RL.Texture
player_pos = Vec2(10, 10)
paint_float: int = 0
frame_count: int = 0
def init() -> World:
buf = RL.gen_image_color(screen_width, screen_height, RL.BLACK)
RL.image_draw_circle(buf, 0, 100, 100, RL.RED)
texture = RL.load_texture_from_image(buf)
return World(buf, texture)
# def flood_fill(w: World):
def player_input(w: World):
if RL.is_mouse_button_pressed(0):
w.paint_tank = paint_tank_max
if RL.is_mouse_button_down(0):
mouse_pos = RL.get_mouse_position()
RL.begin_texture_mode(w.render_tx);
mdt = RL.get_mouse_delta()
mag = RL.vector2_length(mdt)
if mag > 0 and w.paint_tank > 0:
w.paint_tank -= mag
r = w.paint_tank // 10
RL.draw_circle_v(mouse_pos, r, RL.RED);
RL.end_texture_mode();
def update(w: World):
RL.update_texture(w.texture, w.buffer.data)
def draw_2d(w: World):
RL.draw_texture_rec(w.texture, Rect(0, 0, screen_width, screen_height), Vec2(0, 0), RL.WHITE);
RL.init_window(screen_width, screen_height, "Starter");
RL.set_target_fps(60)
w = init()
while not RL.window_should_close():
# player_input(w)
update(w)
# Drawing
RL.begin_drawing()
RL.clear_background(RL.WHITE)
draw_2d(w)
RL.end_drawing()
w.frame_count += 1