Skip to content

Commit

Permalink
Quartz V2 Pre-Release
Browse files Browse the repository at this point in the history
  • Loading branch information
BloodhavenStudios authored Dec 14, 2024
1 parent b04c7f1 commit e6f1822
Show file tree
Hide file tree
Showing 27 changed files with 1,107 additions and 1,421 deletions.
100 changes: 100 additions & 0 deletions Docs/Engine/CAMERA.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# 📹 Camera
Object to handle rendering `Frame`'s
```py
class Quartz.Engine.Camera(...)
```
```py
class Quartz.Engine.Camera(
frame: Frame,
position: Vec2,
scale: Vec2,
border: str
)
```

## Contents
[**Arguments**](#arguments)

[**Methods**](#methods)
- [\_\_init\_\_](#\_\_init\_\_)

## Arguments
`frame`: The `Frame` to render

`position`: Where the center of the `Camera` is positioned on the `Frame`

`scale`: The size of the lens of the `Camera` or scale of how much it sees

`border`: The outside of the frame of the camera If left as None no border will be showed.

## Methods

### \_\_init\_\_
Sets up the `Camera` based on parameters
```py
def __init__(
self,
frame: "Frame",
position: "Vec2",
scale: "Vec2",
border: str = None
):
self.frame = frame
self.position = position
self.scale = scale
self.border = border
```

### render
Renders the `Frame` and `Pixel`'s inside of it, selecting the highest layer pixel per position.
```py
def render(self):
# Calculate rendering bounds
half_width, half_height = self.scale.x // 2, self.scale.y // 2
start_x, end_x = self.position.x - half_width, self.position.x + half_width
start_y, end_y = self.position.y - half_height, self.position.y + half_height

# Combine parent and child pixel positions
pixel_positions = self.frame.get_pixels_position()
for position, pixels in pixel_positions.items():
for pixel in pixels:
if pixel.type == "Parent":
for child_pixel in pixel.children_pixels:
pixel_positions.setdefault(child_pixel.position, set()).add(child_pixel)

# Build the render buffer
render_buffer = []
if self.border: render_buffer.append(self.border * (self.scale.x + 3)) # Top border

for y in range(start_y, end_y + 1):
row = [self.border] if self.border else []
for x in range(start_x, end_x + 1):
highest_layer_pixel = max(
(
pixel
for position, pixels in pixel_positions.items()
for pixel in pixels
if position.x == x and position.y == y
),
key=lambda p: p.layer,
default=None,
)
row.append(highest_layer_pixel.texture if highest_layer_pixel else self.frame.backdrop)
if self.border:
row.append(self.border) # Right border
render_buffer.append("".join(row))

if self.border:
render_buffer.append(self.border * (self.scale.x + 3)) # Bottom border

# Print the render buffer
print("\n".join(render_buffer))
```

<div style="width: 100%; margin-bottom: 7.5px;display: flex; justify-content: space-between;">
<a href="#📹-camera" style="width: 100%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Top</a>
</div>
<div style="width: 100%; display: flex; justify-content: space-between;">
<a href="FRAME.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Frame</a>
<a href="GEOMETRY.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Next To Geometry</a>
</div>
21 changes: 21 additions & 0 deletions Docs/Engine/CONTENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 💪 Quartz.Engine
## Reference for everything inside `Quartz.Engine`

<div style="width: 100%; margin-bottom: 7.5px; display: flex; justify-content: space-between;">
<a href="PIXEL.md" style="width: 47%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Pixel</a>
<a href="DYNAMICS.md" style="width: 47%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">To Dynamics</a>
</div>

<div style="width: 100%; margin-bottom: 7.5px; display: flex; justify-content: space-between;">
<a href="FRAME.md" style="width: 47%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Frame</a>
<a href="CAMERA.md" style="width: 47%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Camera</a>
</div>

<div style="width: 100%; margin-bottom: 7.5px; display: flex; justify-content: ;">
<a href="GEOMETRY.md" style="width: 47%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Geometry</a>
</div>

<div style="width: 100%; margin-bottom: 7.5px; display: flex; justify-content: space-between;">
<a href="../INTRO.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Intro</a>
<a href="PIXEL.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Next to Pixel</a>
</div>
54 changes: 54 additions & 0 deletions Docs/Engine/DYNAMICS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# ⬇️ Dynamics
Manipulates how `Pixel`'s interact with other `Pixel`'s.
```py
class Quartz.Engine.Dynamics(...)
```
```py
class Quartz.Engine.Dynamics(
is_collidable: bool,
collidable_pixels: list,
non_collidable_pixels: list,
gravity_force: int
)
```

## Contents
[**Arguments**](#arguments)

[**Methods**](#methods)
- [\_\_init\_\_](#\_\_init\_\_)

## Arguments
`is_collidable`: Boolean that decides if the `Dynamics` allow the attached `Pixel` to Collide with other Collidable `Pixel`'s

`collidable_pixels`: List of valid collidable `Pixel`'s

`non_collidable_pixels`: List of invalid collidable `Pixel`'s even if they have `is_collidable` set to true

`gravity_force`: The weight of gravity against the `Pixel` if set to 0 the pixel doesn't have gravity on it.

## Methods

### \_\_init\_\_
Sets up `Dynamics` based on parameters
```py
def __init__(
self,
is_collidable: bool,
collidable_pixels: list,
non_collidable_pixels: list,
gravity_force: int
) -> None:
self.is_collidable = is_collidable
self.collidable_pixels = collidable_pixels
self.non_collidable_pixels = non_collidable_pixels
self.gravity_force = gravity_force
```

<div style="width: 100%; margin-bottom: 7.5px;display: flex; justify-content: space-between;">
<a href="#⬇️-dynamics" style="width: 100%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Top</a>
</div>
<div style="width: 100%; display: flex; justify-content: space-between;">
<a href="PIXEL.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Pixel</a>
<a href="FRAME.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Next To Frame</a>
</div>
81 changes: 81 additions & 0 deletions Docs/Engine/FRAME.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# 🖼️ Frame
Object to store `Pixel`'s inside of so they do something.
```py
class Quartz.Engine.Frame(...)
```
```py
class Quartz.Engine.Frame(
backdrop: str | Pixel
)
```

## Contents
[**Arguments**](#arguments)

[**Methods**](#methods)
- [\_\_init\_\_](#\_\_init\_\_)
- [get_pixels](#get_pixels)
- [get_pixels_position](#get_pixels_position)
- [get_pixels_position_as_string](#get_pixels_position_as_string)
- [get_pixels_by_cluster](#get_pixels_by_cluster)

## Arguments
`backdrop`: What the background of the `Frame` looks like.

## Methods

### \_\_init\_\_
Sets up the `Frame` based on parameters
```py
def __init__(self, backdrop: "Pixel") -> None:
self.backdrop = backdrop
self.pixels = list()
self.cameras = set()
```

### get_pixels
Returns every `Pixel` placed on the `Frame`
```py
def get_pixels(self) -> list:
return self.pixels
```

### get_pixels_position
Returns every `Pixel` in each `Vec2` Position
```py
def get_pixels_position(self) -> dict:
positions = {}
for pixel in self.get_pixels():
positions.setdefault(pixel.position, []).append(pixel)
return positions
```

### get_pixels_position_as_string
Returns every `Pixel` in each `Vec2` Position in string format
```py
def get_pixels_position_as_string(self) -> dict:
positions, pos_string = {}, ""
for pixel in self.get_pixels():
positions.setdefault(pixel.position(), []).append(pixel())
return positions
```

### get_pixels_by_cluster
Returns every `Pixel` in a specific cluster placed on this `Frame`.
```py
def get_pixel_by_cluster(self, cluster: str) -> set:
pixels = self.get_pixels()
target_pixels = list()
for pixel in pixels:
if pixel.cluster == cluster:
target_pixels.append(pixel)
return target_pixels
```

<div style="width: 100%; margin-bottom: 7.5px;display: flex; justify-content: space-between;">
<a href="#⬇️-dynamics" style="width: 100%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Top</a>
</div>
<div style="width: 100%; display: flex; justify-content: space-between;">
<a href="DYNAMICS.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Dynamics</a>
<a href="CAMERA.md" style="display: flex; justify-content: center; align-items: center; width: 47%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Next To Camera</a>
</div>
50 changes: 50 additions & 0 deletions Docs/Engine/GEOMETRY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 📐 Geometry
Handles `Vec2` Objects for `Pixel`'s, `Frame`'s, and `Camera`'s
```py
Quartz.Engine.Vec2(...)
```
```py
Quartz.Engine.Vec2(
x: int,
y: int
)
```

## Contents
[**Arguments**](#arguments)

[**Methods**](#methods)
- [\_\_init\_\_](#\_\_init\_\_)
- [\_\_call\_\_](#\_\_call\_\_)
- [\_\_str\_\_](#\_\_str\_\_)

## Arguments

### \_\_init\_\_
Sets up the `Vec2` based on parameters
```py
def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
```

### \_\_call\_\_
Returns `Vec2.x` and `Vec2.y` on call
```py
def __call__(self):
return (self.x, self.y)
```

### \_\_str\_\_
Returns `Vec2.x` and `Vec2.y` as a string
```py
def __str__(self):
return f"({self.x}, {self.y})"
```

<div style="width: 100%; margin-bottom: 7.5px;display: flex; justify-content: space-between;">
<a href="#📐-geometry" style="width: 100%; height: 2rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Top</a>
</div>
<div style="width: 100%; display: flex; justify-content: space-between;">
<a href="CAMERA.md" style="display: flex; justify-content: center; align-items: center; width: 100%; height: 3rem; background-color: #151B23; color: white; border-radius: 7.5px; padding: 10px; text-align: center; font-size: 16px; font-weight: 400;">Back to Camera</a>
</div>
Loading

0 comments on commit e6f1822

Please sign in to comment.