from SkyScrapperClasSS import Sky
width = 1000
height = width/2
num = 100
heights = []
counter = 0
gap = num*10/13
swapped = False
caounter = 0
getg = False
r = color(255,0,0)
def setup():
size(width,height)
for i in range(num):
heights.append(Sky(i*10,random (height)))
def draw():
global gap,getg,counter,swapped
print(gap)
background(0)
swapped = False
if getg:
gap = gapper(gap)
for i in range(num):
if getg:
getg = False
if counter >= num - gap and not getg:
getg = True
if counter == i or counter == i + gap:
text(heights[i].x/10,heights[i].x,10)
fill(255,0,0)
else:
fill(255)
heights[i].show()
if not(counter >= num - gap):
if heights[counter].y > heights[counter + gap].y:
swapped = True
print("swappin")
heights[counter].x, heights[counter + gap].x = heights[counter + gap].x, heights[counter].x
counter += 1
if not swapped and gap == 1:
print("Printin :")
for i in range(num):
print(heights[i].x,heights[i].y)
noLoop()
def gapper(gap):
gap = int((gap*10) / 13)
if gap < 1:
return 1
return gap
class Sky:
def __init__(self,x,y):
self.x = x
self.y = y
def show(self):
rect(self.x,height-self.y,10,self.y)
(I know that this code is a mess, a class is too much i could’ve used an array of pvectors and other stuff)The point is, i am swapping the X coordinate of a rect if his height is higer,and when i print theyr X, i can see the X actually swapped, but on the screen nothing changes