minecraft_terrain_generator.py

Created by naul

Created on January 29, 2023

3.25 KB

Un générateur 3D de terrain minecraft. Contient aussi un programme permettant de créer une pyramide dans le style de QBert. La génération est infini et se répète 6 secondes après s’être terminée.


from math import *
from kandinsky import *
from random import *
from time import *
def draw_cube(x,y,j):
  col=255*(j/n)
  fill_rect(x+1,y+2,9,3,color(0,col,0));fill_rect(x+3,y+1,5,5,color(0,col,0));fill_rect(x+5,y,1,7,color(0,col,0));fill_rect(x,y+3,11,1,color(0,col,0));fill_rect(x,y+5,3,3,color(col,0,0));set_pixel(x,y+4,color(col,0,0));fill_rect(x+1,y+8,2,1,color(col,0,0));fill_rect(x+1,y+6,5,2,color(col,0,0));fill_rect(x+3,y+7,3,3,color(col,0,0));set_pixel(x+5,y+10,color(col,0,0));fill_rect(x+6,y+6,5,2,color(0,0,col));fill_rect(x+6,y+8,4,1,color(0,0,col));fill_rect(x+6,y+9,2,1,color(0,0,col));fill_rect(x+8,y+5,3,1,color(0,0,col));set_pixel(x+10,y+4,color(0,0,col))
def draw_col_cube(x,y,col):
  fill_rect(x,y+3,11,5,col);fill_rect(x+1,y+2,9,7,col);fill_rect(x+3,y+1,5,9,col);fill_rect(x+5,y,1,11,col)
def draw_tree(x,y,w):
  for s in range(5):
    draw_col_cube(x,y-(s*4),(140*(w/n),113*(w/n),82*(w/n)))
  for j in range(3):
    for i in range(3):
      for k in range(2):
        draw_col_cube(x+(6*i)-(5*j),y-24+(3*i)+(j*3)-(k*4),(0,255*(w/n),0))
#200-(4*k)
def draw_ore(x,y,col,i,n):
  draw_col_cube(x,y,col)
  altitude=round((200-(k*4))/4)
  if altitude>=20:
    if randint(0,1)==0:
      cool=(0,0,255*(i/n))
    else:
      cool=(150*(i/n),150*(i/n),150*(i/n))
  elif altitude>=5 and altitude<19:
    if randint(0,100)<25:
      cool=(0,0,0)
    else:
      cool=(150*(i/n),150*(i/n),150*(i/n))
  else:
    cool=(0,0,0)
  set_pixel(x+1,y+6,cool);set_pixel(x+2,y+7,cool);set_pixel(x+4,y+6,cool);set_pixel(x+4,y+8,cool);set_pixel(x+8,y+7,cool);set_pixel(x+9,y+6,cool);set_pixel(x+9,y+8,cool);set_pixel(x+7,y+8,cool)
#programme 1:dessine un terrain 3D
n=16#power of two <=64
#fill_rect(0,0,320,222,(200,)*3)
#for j in range(n):
#  for i in range(n):
#    for k in range(2):
#      draw_cube(151+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(8+(4*round(sin(i+j*1.5)))-(4*k)),i)
#    draw_cube(151+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(4*round(sin(i+j*1.5))),i)
#    if randint(0,50)==0:
#      draw_tree(151+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(4*round(sin(i+j*1.5))))

#programme 1.5: boucle infinie

while True:
  fill_rect(0,0,320,222,(200,)*3)
  for j in range(n):
    for i in range(n):
      e=4*randint(-0,1)
      for k in range(50):
        draw_cube(146+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(200+(4*round(sin(i+j*1.5)))-(4*k))+e,i)
        if randint(0,14)==0:
          draw_ore(146+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(200+(4*round(sin(i+j*1.5)))-(4*k))+e,(100*(i/n),100*(i/n),100*(i/n)),i,n)
      draw_cube(146+(6*i)-(5*j),round((111-((n*7)/2)))+(3*i)+(j*3)+(4*round(sin(i+j*1.5)))+e,i)
      if randint(0,45)==0:
        draw_tree(146+(6*i)-(5*j),-4+round((111-((n*7)/2)))+(3*i)+(j*3)+e+(4*round(sin(i+j*1.5))),i)
  sleep(6)

#programme 2:dessine une pyramide qbert

#fill_rect(0,0,320,222,(200,)*3)
#def draw_pyramid(x,y,t):
#  for k in range(t):
#    for i in range(k):
#      draw_cube(x-((k-1)*5)+((i-1)*11),y+((k-1)*8),255)
#draw_pyramid(152,40,16)

#version 1.0:adding core program
#version 1.1:adding shading
#version 1.2:adding trees
#version 1.3:adding trees shading
#version 1.4:adding ores
#version 1.5:adding ores shading
#version 1.6:adding different ores
#version 1.7:regulating ores altitude generation

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.