terrain_generator.py

Created by naul

Created on February 28, 2023

1.1 KB

Générateur de terrain en 3D. Script qui peut être seedé, c’est à dire obtenir une suite de nombre qui peut être sauvergardé pour regénérer la même carte encore. Requiert Islandseeder.py pour fonctionner .(https://my.numworks.com/python/naul/islandseeder)


from math import *
from matplotlib.pyplot import *
from kandinsky import *
from random import *
from ion import *
from time import *
def ranseed():
  seedy=[]
  for i in range(32):
    power=randint(1,8)
    seedy.append(power)
    x=randint(0,24)
    seedy.append(x)
    y=randint(0,24)
    seedy.append(y)
  return seedy
seedy=ranseed()
from islandseeder import print_map 
print_map(seedy)
def draw_col_cube(x,y,col):fill_rect(x,y+2,10,6,col);fill_rect(x+2,y+1,6,8,col);fill_rect(x+4,y,2,10,col)
def print3d(seedy):
  for i in range(30):
    for j in range(30):
      for deep in range(6):
        height=round(((get_pixel(j,i)[0]/8))*5)
        if height==0:
          draw_col_cube(155+5*j-5*i,10+3*j+3*i+deep*5,(0,0,255))
        else:
          draw_col_cube(155+5*j-5*i,10+3*j+3*i+(25-5*deep)-height,(0,((height*10)+(deep*15))/3,0))
while True:
  print3d(seedy)
  seedy=[]
  for i in range(32):
    power=randint(1,8)
    seedy.append(power)
    x=randint(0,24)
    seedy.append(x)
    y=randint(0,24)
    seedy.append(y)
  sleep(4)
  fill_rect(0,0,330,230,(255,255,255))
  print_map(seedy)

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.