Skip to content

Commit

Permalink
feat(other): ✨ Implemented the top and bottom params!!
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsunami014 (Max) authored and Tsunami014 (Max) committed Dec 15, 2024
1 parent 75177be commit a49cf55
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 16 deletions.
73 changes: 60 additions & 13 deletions BlazeSudio/utils/wrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def wrapLevel(
0 = the image width (wrapped)
-1 = the centroid (or centroid line(s)) of the polygon made by the wrapped image width
```
- Top **must** be >= 0 and bottom **must** be <= 0 and >= -1.
"""

pg = world.get_pygame(lvl, transparent_bg=True)
Expand Down Expand Up @@ -106,6 +107,7 @@ def wrapSurface(pg: pygame.Surface,
0 = the image width (wrapped)
-1 = the centroid (or centroid line(s)) of the polygon made by the wrapped image width
```
- Top **must** be >= 0 and bottom **must** be <= 0 and >= -1.
"""
def wrap():
yield 'Initialising wrap', {'amount': 3}
Expand All @@ -115,6 +117,10 @@ def wrap():
raise ValueError(
'The 2 input surfaces are of different sizes!!!'
)
if top < 0 or bottom > 0 or bottom < -1:
raise ValueError(
'Top must be >= 0 and bottom must be <= 0 and >= -1'
)
shape = MakeShape(width)
def checkX1(x):
for con in constraints:
Expand Down Expand Up @@ -191,27 +197,68 @@ def closestTo(li, p):
totd = 0
total = sum(shape.jointDists)

yield 'Calculating segments', {'amount': len(collsegs), 'done': 0}

lastP1 = None
lnsLen = len(lns.shapes)

yield 'Calculating segments', {'amount': len(collsegs), 'done': 0}

for idx, seg in enumerate(collsegs):
d = shape.jointDists[idx]

# TODO: Trace the large poly along bcos it may have multiple segments
if lastP1 is None:
p1Closests = small.closestPointTo(collisions.Point(*seg.p1))
p1Closests.sort(key=lambda x: (x[0]-seg.p1[0])**2+(x[1]-seg.p1[1])**2)

if top != 0:
out1 = closestTo(lns[idx].whereCollides(hitsLge), seg.p1)
out2 = closestTo(lns[(idx+1)%lnsLen].whereCollides(hitsLge), seg.p2)
if top == 1:
outerp1 = out1
outerp2 = out2
else:
inner1 = seg.p1
outerp1 = (
(inner1[0]-out1[0])*top+out1[0],
(inner1[1]-out1[1])*top+out1[1]
)
inner2 = seg.p2
outerp2 = (
(inner2[0]-out2[0])*top+out2[0],
(inner2[1]-out2[1])*top+out2[1]
)
else:
p1Closests = [lastP1]
p2Closests = small.closestPointTo(collisions.Point(*seg.p2))
p2Closests.sort(key=lambda x: (x[0]-seg.p2[0])**2+(x[1]-seg.p2[1])**2)
lastP1 = p2Closests[0]
outerp1 = seg.p1
outerp2 = seg.p2

if bottom != 0:
if lastP1 is None:
p1Closests = small.closestPointTo(collisions.Point(*seg.p1))
p1Closest = closestTo(p1Closests, seg.p1)
else:
p1Closest = lastP1
p2Closests = small.closestPointTo(collisions.Point(*seg.p2))
p2Closest = closestTo(p2Closests, seg.p2)
lastP1 = p2Closest

if bottom == -1:
innerP1 = p1Closest
innerP2 = p2Closest
else:
innerP1 = (
(p1Closest[0]-seg.p1[0])*abs(bottom)+seg.p1[0],
(p1Closest[1]-seg.p1[1])*abs(bottom)+seg.p1[1]
)
innerP2 = (
(p2Closest[0]-seg.p2[0])*abs(bottom)+seg.p2[0],
(p2Closest[1]-seg.p2[1])*abs(bottom)+seg.p2[1]
)
else:
innerP1 = seg.p1
innerP2 = seg.p2

poly = [
closestTo(lns[idx].whereCollides(hitsLge), seg.p1),
closestTo(lns[(idx+1)%len(lns.shapes)].whereCollides(hitsLge), seg.p2),
p2Closests[0],
p1Closests[0],
outerp1,
outerp2,
innerP2,
innerP1,
]

draw_quad(cir, poly, pg.subsurface(((totd/total)*width, 0, math.ceil((d/total)*width), pg.get_height())))
Expand Down
8 changes: 5 additions & 3 deletions demos.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,10 @@ def _LoadUI(self):
RTOP = GO.PNEW((1, 0), (0, 1))
self.offset = len(topF['Main'])
topF['Main'].extend([
GUI.Text(topF, RTOP, 'Ri'),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, start=0, min=0, max=500, placeholdOnNum=None),
GUI.Text(topF, RTOP, 'Top'),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, start=1, min=0, max=2, placeholdOnNum=None),
GUI.Text(topF, RTOP, 'Bottom'),
GUI.NumInputBox(topF, RTOP, 100, GO.RHEIGHT, start=-1, min=-1, max=0, placeholdOnNum=None),
])

topF['Main'].append(GUI.Text(topF, GO.PCTOP, 'INPUT IMAGE', font=GO.FTITLE))
Expand Down Expand Up @@ -570,7 +572,7 @@ 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(), pg2=False, constraints=conns, isIter=True)
slf['surf'] = yield from wrapSurface(topF[-1].get(), topF[off+1].get(), topF[off+3].get(), pg2=False, constraints=conns, isIter=True)

yield 'Finishing up'

Expand Down

0 comments on commit a49cf55

Please sign in to comment.