Carrés de 20x20 pixels aléatoirement noir ou blancs

master
Yohann Dedy 2018-08-30 23:49:49 +02:00
commit 8bd77de320
1 changed files with 27 additions and 0 deletions

27
randomSquares.pyde Normal file
View File

@ -0,0 +1,27 @@
import random
size(600,600)
cols = 30
rows = 30
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))
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)
print(cells)