perlin.py

Created by stimorol

Created on November 11, 2022

776 Bytes

Script dessinant des cartes avec le bruit de perlin. Le deuxième argument de la fonction apply est le nombre de fois que l’algorithme va être performé sur la carte.


from math import *
from time import *
from random import *
from kandinsky import *
def apply(grid,count,borderX,borderY):
  i=0
  while i<count:
    for y in range(borderY):
      for x in range(borderX):
        surrounding=[grid[y+1][x],grid[y-1][x],grid[y][x+1],grid[y][x-1],grid[y+1][x+1],grid[y-1][x-1],grid[y-1][x+1],grid[y+1][x-1]]
        if surrounding.count(0)>4:grid[y][x]=0
        elif surrounding.count(1)>4: grid[y][x]=1
        fill_rect(x*10,y*10,10,10,'blue' if bool(grid[y][x]) else 'green')
        sleep(.0002)
    i+=1

sgrid=[[randint(0,1) for i in range(33)] for i in range(23)]

for i in range(len(sgrid)):
  for x in range(len(sgrid[i])):
    fill_rect(x*10,i*10,10,10,'blue' if sgrid[i][x] else 'green')
sleep(.5)
apply(sgrid,15,32,22)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.