From f9e29df51e77b907c1e18bddc37880a98c7be62f Mon Sep 17 00:00:00 2001 From: Yohann Dedy Date: Fri, 31 Aug 2018 00:43:13 +0200 Subject: [PATCH] =?UTF-8?q?R=C3=A9partition=20des=20carr=C3=A9s=20fonction?= =?UTF-8?q?nelle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- randomSquares.pyde | 48 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/randomSquares.pyde b/randomSquares.pyde index 93d8d21..6d459ea 100644 --- a/randomSquares.pyde +++ b/randomSquares.pyde @@ -1,27 +1,45 @@ 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) - -cols = 30 -rows = 30 - +palette = ['#0d3b66','#faf0ca','#f4d35e','#ee964b','#f95738'] +cols = 60 +rows = 60 +maxsize = 3 cells = [[True for x in range(cols)] for y in range(rows)] wsq = width/cols hsq = height/rows -noStroke() - -for y in range(rows): - for x in range(cols): - cells[x][y] = bool(random.getrandbits(1)) - +#noStroke() for y in range(rows): for x in range(cols): if cells[x][y]: - fill(255) - else: - fill(0) - rect(x*wsq,y*hsq,width/cols,height/rows) + fill(random.choice(palette)) + sqsize = random.randint(1,availSpace(x,y)) + print(sqsize) + 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)