Skip to content

Commit

Permalink
feat(other): ✨ Added a limit switch onto the wrapping func!!!!
Browse files Browse the repository at this point in the history
It looks pretty darn cool!!! :D :D :D :D :D
  • Loading branch information
Tsunami014 (Max) authored and Tsunami014 (Max) committed Dec 26, 2024
1 parent e21fb40 commit 04a98ad
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
16 changes: 11 additions & 5 deletions BlazeSudio/utils/wrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def wrapLevel(
lvl: int,
top: int|float = 1,
bottom: int|float = 0,
quality: float = 1.0,
limit: bool = True,
startRot: int|float = 0,
constraints: list[Segment] = [],
) -> tuple[pygame.Surface]:
Expand All @@ -47,7 +47,7 @@ def wrapLevel(
lvl (int): The level number.
top (int|float, optional): The position of the top of the wrapped image. See below 'positioning'. Defaults to 1.
bottom (int|float, optional): The position of the bottom of the wrapped image. See below 'positioning'. Defaults to 0.
quality (float, optional): The quality of the output, in terms of percentage of calculated total size as a decimal. Defaults to 1.0 (regular sized).
limit (bool, optional): Whether to limit the warp so it MUST be a height of `pg.get_height()`. Making this False may give some very warped results. Constrains the bottom of the image. Defaults to True.
startRot (int|float, optional): The starting rotation. Defaults to 0.
constraints (list[Segment], optional): A list of constraints to apply to the image. Defaults to [].
Expand All @@ -69,12 +69,12 @@ def wrapLevel(
for i in world.get_level(lvl).layers:
i.tileset = None # So it has to render blocks instead >:)
pg2 = world.get_pygame(lvl, transparent_bg=True)
return wrapSurface(pg, top, bottom, quality, startRot, constraints, pg2)
return wrapSurface(pg, top, bottom, limit, startRot, constraints, pg2)

def wrapSurface(pg: pygame.Surface,
top: int|float = 1,
bottom: int|float = 0,
quality: float = 1.0,
limit: bool = True,
startRot: int|float = 0,
constraints: list[Segment] = [],
pg2: bool|pygame.Surface = True,
Expand All @@ -87,7 +87,7 @@ def wrapSurface(pg: pygame.Surface,
pg (pygame.Surface): The pygame surface to wrap.
top (int|float, optional): The position of the top of the wrapped image. See below 'positioning'. Defaults to 1.
bottom (int|float, optional): The position of the bottom of the wrapped image. See below 'positioning'. Defaults to 0.
quality (float, optional): The quality of the output, in terms of percentage of calculated total size as a decimal. Defaults to 1.0 (regular sized).
limit (bool, optional): Whether to limit the warp so it MUST be a height of `pg.get_height()`. Making this False may give some very warped results. Constrains the bottom of the image. Defaults to True.
startRot (int|float, optional): The starting rotation. Defaults to 0.
constraints (list[Segment], optional): A list of constraints to apply to the image. Defaults to [].
pg2 (bool|pygame.Surface, optional): A pygame surface for the alpha wrapping, or a bool as to whether to return it in the first place. Defaults to True.
Expand Down Expand Up @@ -253,6 +253,12 @@ def closestTo(li, p):
else:
innerP1 = seg.p1
innerP2 = seg.p2

if limit:
phi1 = collisions.direction(outerp1, innerP1)
innerP1 = collisions.rotate(outerp1, (outerp1[0], outerp1[1]-height), math.degrees(phi1)+90)
phi2 = collisions.direction(outerp2, innerP2)
innerP2 = collisions.rotate(outerp2, (outerp2[0], outerp2[1]-height), math.degrees(phi2)+90)

poly = [
outerp1,
Expand Down
16 changes: 13 additions & 3 deletions demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,9 +482,11 @@ def _LoadUI(self):
self.offset = len(topF['Main'])
topF['Main'].extend([
GUI.Text(topF, RTOP, 'Top'),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, empty=1, start=None, min=0, max=2, placeholdOnNum=None, decimals=8),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, empty=0.5, start=None, min=0, max=2, placeholdOnNum=None, decimals=8),
GUI.Text(topF, RTOP, 'Bottom'),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, empty=-1, start=None, min=-1, max=0, placeholdOnNum=None, decimals=8),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, empty=-0.5, start=None, min=-1, max=0, placeholdOnNum=None, decimals=8),
GUI.Text(topF, RTOP, 'Limit'),
GUI.Switch(topF, RTOP, default=True),
])

topF['Main'].append(GUI.Text(topF, GO.PCTOP, 'INPUT IMAGE', font=GO.FTITLE))
Expand Down Expand Up @@ -573,7 +575,15 @@ def load(slf):
for seg in self.segs:
conns.append(Segment(seg[0], seg[1]))

slf['surf'] = yield from wrapSurface(topF[-1].get(), topF[off+1].get(), topF[off+3].get(), pg2=False, constraints=conns, isIter=True)
slf['surf'] = yield from wrapSurface(
topF[-1].get(),
topF[off+1].get(),
topF[off+3].get(),
topF[off+5].get(),
pg2=False,
constraints=conns,
isIter=True
)

yield 'Finishing up'

Expand Down

0 comments on commit 04a98ad

Please sign in to comment.