diff --git a/poisson-disk-sampling.py b/poisson-disk-sampling.py index d569c1d..5886d78 100644 --- a/poisson-disk-sampling.py +++ b/poisson-disk-sampling.py @@ -51,7 +51,7 @@ def player_input(w: World): w.points.append(p) idx = int(p.y // cell_size * cols + p.x // cell_size) if idx < len(w.grid): - w.grid[idx] = 1 + w.grid[idx] = p if RL.is_key_pressed(RL.KEY_SPACE): w.debug_draw = not w.debug_draw if RL.is_key_pressed(RL.KEY_ENTER): diff --git a/rect-radius.py b/rect-radius.py new file mode 100644 index 0000000..8adb5cc --- /dev/null +++ b/rect-radius.py @@ -0,0 +1,80 @@ +import pyray as RL +from pyray import (Rectangle as Rect, Vector2 as Vec2, Vector3 as Vec3, Camera3D, BoundingBox, Color) +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('', '') + for field in dir(struct): + data = struct.__getattribute__(field) + if str(data).startswith(" World: + cam = Camera3D(Vec3(0, 10, 10), Vec3(0, 0, 0), Vec3(0, 1, 0), 45, RL.CAMERA_PERSPECTIVE) + return World(cam) + +def player_input(w: World): + pass + +def update(w: World): + pass + +def draw_2d(w: World): + radius = 100 + grid_size = 13 + rect_size = radius / math.sqrt(2) + half_size = rect_size // 2 + mid_size = 5 * rect_size + mid_x = screen_width // 2 - mid_size // 2 + mid_y = screen_height // 2 - mid_size // 2 + mid_rect = Rect(mid_x, mid_y, mid_size, mid_size) + RL.draw_rectangle_rec(mid_rect, (Color)(45, 30, 45, 255)) + center_rect = Rect(screen_width // 2 - half_size, screen_height // 2 - half_size, rect_size, rect_size) + RL.draw_rectangle_rec(center_rect, (Color)(100, 30, 45, 255)) + for row in range(grid_size): + for col in range(grid_size): + x = screen_width // 2 - half_size + (row - grid_size // 2) * rect_size + y = screen_height // 2 - half_size + (col - grid_size // 2) * rect_size + rect = Rect(x, y, rect_size, rect_size) + RL.draw_rectangle_lines_ex(rect, 2, RL.GREEN) + mouse_pos = RL.get_mouse_position() + if mouse_pos.x < screen_width // 2 - half_size: mouse_pos.x = screen_width // 2 - half_size + if mouse_pos.x > screen_width // 2 + half_size: mouse_pos.x = screen_width // 2 + half_size + if mouse_pos.y < screen_height // 2 - half_size: mouse_pos.y = screen_height // 2 - half_size + if mouse_pos.y > screen_height // 2 + half_size: mouse_pos.y = screen_height // 2 + half_size + RL.draw_circle_v(mouse_pos, 5, RL.WHITE) + RL.draw_circle_lines_v(mouse_pos, radius, RL.RED) + + +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((Color)(30, 30, 45, 255)) + + draw_2d(w) + + RL.end_drawing() + w.frame_count += 1 +