Répartition des carrés fonctionnelle
parent
a10b47bc4e
commit
f9e29df51e
|
|
@ -1,27 +1,45 @@
|
||||||
import random
|
import random
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def disableCells(cellX,cellY,wsq):
|
||||||
|
for y in range(wsq):
|
||||||
|
for x in range(wsq):
|
||||||
|
cells[cellX+x][cellY+y] = False
|
||||||
|
|
||||||
|
def availSpace(cellX,cellY):
|
||||||
|
countX = 0
|
||||||
|
countY = 0
|
||||||
|
for x in range(cellX,cols):
|
||||||
|
if cells[x][cellY]:
|
||||||
|
countX +=1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
for y in range(cellY,rows):
|
||||||
|
if cells[cellX][y]:
|
||||||
|
countY +=1
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
return min(countX,countY,maxsize)
|
||||||
|
|
||||||
size(600,600)
|
size(600,600)
|
||||||
|
palette = ['#0d3b66','#faf0ca','#f4d35e','#ee964b','#f95738']
|
||||||
cols = 30
|
cols = 60
|
||||||
rows = 30
|
rows = 60
|
||||||
|
maxsize = 3
|
||||||
cells = [[True for x in range(cols)] for y in range(rows)]
|
cells = [[True for x in range(cols)] for y in range(rows)]
|
||||||
|
|
||||||
wsq = width/cols
|
wsq = width/cols
|
||||||
hsq = height/rows
|
hsq = height/rows
|
||||||
noStroke()
|
#noStroke()
|
||||||
|
|
||||||
for y in range(rows):
|
|
||||||
for x in range(cols):
|
|
||||||
cells[x][y] = bool(random.getrandbits(1))
|
|
||||||
|
|
||||||
|
|
||||||
for y in range(rows):
|
for y in range(rows):
|
||||||
for x in range(cols):
|
for x in range(cols):
|
||||||
if cells[x][y]:
|
if cells[x][y]:
|
||||||
fill(255)
|
fill(random.choice(palette))
|
||||||
else:
|
sqsize = random.randint(1,availSpace(x,y))
|
||||||
fill(0)
|
print(sqsize)
|
||||||
rect(x*wsq,y*hsq,width/cols,height/rows)
|
rect(x*wsq,y*hsq,width/cols * sqsize,height/rows * sqsize)
|
||||||
|
disableCells(x,y,sqsize)
|
||||||
|
|
||||||
print(cells)
|
filename = datetime.now().strftime('%Y%m%d%H%M%S.tga')
|
||||||
|
#save(filename)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue