city.py

Created by chambounaudaubin

Created on November 05, 2024

4.59 KB

utiliser lesfleches pour avancer


from time import *
from math import *
from turtle import *
from kandinsky import *
from ion import *
def grass():
  fill_rect(-100,-100,500,500,color(0,200,100))
def am(a,b):
  fill_rect(a,b,10,30,color(100,50,50))
  fill_rect(a,b,10,10,color(0,100,0))
  fill_rect(a-5,b-5,10,10,color(0,100,0))
  fill_rect(a+5,b+5,10,15,color(0,100,0))
  fill_rect(a+20,b+10,20,20,'yellow')
  fill_rect(a+20,b+10,20,5,'red')
  fill_rect(a+25,b+5,10,5,'red')
  fill_rect(a+28,b+2,3,3,'red')
def amerase(a,b):
  fill_rect(a,b,10,30,color(0,200,100))
  fill_rect(a,b,10,10,color(0,200,100))
  fill_rect(a-5,b-5,10,10,color(0,200,100))
  fill_rect(a+5,b+5,10,15,color(0,200,100))
  fill_rect(a+20,b+10,20,20,color(0,200,100))
  fill_rect(a+20,b+10,20,5,color(0,200,100))
  fill_rect(a+25,b+5,10,5,color(0,200,100))
  fill_rect(a+28,b+2,3,3,color(0,200,100))
def building(e,f):
  fill_rect(e,f,15,40,'white')
  fill_rect(e+6,f+37,3,3,'blue')
  fill_rect(e+3,f+32,3,3,'blue')
  fill_rect(e+9,f+32,3,3,'blue')
  fill_rect(e+3,f+26,3,3,'blue')
  fill_rect(e+9,f+26,3,3,'blue')
  fill_rect(e+3,f+20,3,3,'blue')
  fill_rect(e+9,f+20,3,3,'blue')
  fill_rect(e+3,f+14,3,3,'blue')
  fill_rect(e+9,f+14,3,3,'blue')
  fill_rect(e+3,f+8,3,3,'blue')
  fill_rect(e+9,f+8,3,3,'blue')
  fill_rect(e+3,f+9,3,3,'blue')
  fill_rect(e+9,f+9,3,3,'blue')
def buildingerase(e,f):
  fill_rect(e,f,15,40,color(0,200,100))
  fill_rect(e+6,f+37,3,3,color(0,200,100))
  fill_rect(e+3,f+32,3,3,color(0,200,100))
  fill_rect(e+9,f+32,3,3,color(0,200,100))
  fill_rect(e+3,f+26,3,3,color(0,200,100))
  fill_rect(e+9,f+26,3,3,color(0,200,100))
  fill_rect(e+3,f+20,3,3,color(0,200,100))
  fill_rect(e+9,f+20,3,3,color(0,200,100))
  fill_rect(e+3,f+14,3,3,color(0,200,100))
  fill_rect(e+9,f+14,3,3,color(0,200,100))
  fill_rect(e+3,f+8,3,3,color(0,200,100))
  fill_rect(e+9,f+8,3,3,color(0,200,100))
  fill_rect(e+3,f+9,3,3,color(0,200,100))
  fill_rect(e+9,f+9,3,3,color(0,200,100))
  
def house(g,h):
  fill_rect(g,h,20,20,'white')
  fill_rect(g+9,h+15,2,5,'brown')  
  fill_rect(g,h-5,20,5,'blue')
  fill_rect(g+5,h-10,10,5,'blue')
  fill_rect(g+8,h-15,4,5,'blue')
def houseerase(g,h):
  fill_rect(g,h,20,20,color(0,200,100))
  fill_rect(g+9,h+15,2,5,color(0,200,100))
  fill_rect(g,h-5,20,5,color(0,200,100))
  fill_rect(g+5,h-10,10,5,color(0,200,100))
  fill_rect(g+8,h-15,4,5,color(0,200,100))
def road(i,j):
  fill_rect(i-20,j-20,150,10,'gray')
  fill_rect(i-20,j-170,10,150,'gray')
  fill_rect(i-20,j-170,150,10,'gray')
  fill_rect(i+130,j-170,10,160,'gray')
def roaderase(i,j):
  fill_rect(i-20,j-20,150,10,color(0,200,100))
  fill_rect(i-20,j-170,10,150,color(0,200,100))
  fill_rect(i-20,j-170,150,10,color(0,200,100))
  fill_rect(i+130,j-170,10,160,color(0,200,100))
def car():
  if o==90 or o==-90:  
    fill_rect(100-1,180+2,12,2,'black')
    fill_rect(100-1,180+15,12,2,'black')
    fill_rect(100,180,10,20,'red')
  if o==0 or o==180:
    fill_rect(100+2,180-1,2,12,'black')
    fill_rect(100+15,180-1,2,12,'black')
    fill_rect(100,180,20,10,'red')
def carerase():
  if o==90 or o==-90:  
    fill_rect(100-1,180+2,12,2,color(0,200,100))
    fill_rect(100-1,180+15,12,2,color(0,200,100))
    fill_rect(100,180,10,20,color(0,200,100))
    fill_rect(100-1,180+7,12,2,color(0,200,100))
    fill_rect(100+2,180-1,2,12,color(0,200,100))
    fill_rect(100+15,180-1,2,12,color(0,200,100))
    fill_rect(100,180,20,10,color(0,200,100))
    fill_rect(100+7,180-1,2,12,color(0,200,100))  
  if o==0 or o==180:
    fill_rect(100+2,180-1,2,12,color(0,200,100))
    fill_rect(100+15,180-1,2,12,color(0,200,100))
    fill_rect(100,180,20,10,color(0,200,100))
    fill_rect(100+7,180-1,2,12,color(0,200,100))
    fill_rect(100-1,180+2,12,2,color(0,200,100))
    fill_rect(100-1,180+15,12,2,color(0,200,100))
    fill_rect(100,180,10,20,color(0,200,100))
    fill_rect(100-1,180+7,12,2,color(0,200,100))
x=100
y=100
def map(x,y):
  am(x,y)
  am(x+50,y+40)
  building(x+60,y-20)
  building(x+50,y-10)
  building(x+80,y-20)
  house(x+100,y+50)
  house(x+20,y-20)
  road(x,y+100)
def maperase(x,y):
  amerase(x,y)
  amerase(x+50,y+40)
  buildingerase(x+60,y-20)
  buildingerase(x+50,y-10)
  buildingerase(x+80,y-20)
  houseerase(x+100,y+50)
  houseerase(x+20,y-20)
  roaderase(x,y+100)
grass()
map(x,y)
go=1
o=180
car()
while go>0:
  if keydown(KEY_RIGHT):
    x=x-4
    maperase(x+4,y)
    map(x,y)
    o=0
    carerase()
    car()
  if keydown(KEY_LEFT):
    x=x+4
    maperase(x-4,y)
    map(x,y)
    o=180
    carerase()
    car()
  if keydown(KEY_UP):
    y=y+4
    maperase(x,y-4)
    map(x,y)
    o=90
    carerase()
    car()
  if keydown(KEY_DOWN):
    y=y-4
    maperase(x,y+4)
    map(x,y)
    o=-90
    carerase()
    car()

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.