draw_mountain_2.py

Created by wperez274

Created on August 22, 2022

1.22 KB


# drawing a line without Turtle() :-)
from math import *
from random import *
from random import randint as R
from kandinsky import *
from ion import *
from time import *

bg=(R(210,255),R(210,255),R(210,255))


mx=0
my=R(100,200)
mw=3
mh=2
mc=(0,0,0)

mountain_c=(R(0,155),R(0,155),0)


def draw_line():
  global mx,my,mw,mh,bg,mountain_c 
  mx+=1
  my+=randint(-2,2)
  fill_rect(mx,my,mw,mh,bg)
  fill_rect(mx,my,2,200,mountain_c)
  draw_string("[RGB] Sky :     "+str(bg),0,0,"black",bg)
  draw_string("[RGB] Mountain: "+str(mountain_c),0,20,"black",bg)
  draw_string("Keys [OK],[EXE] = New Mountain.",4,45,(0,0,95),"white")
  if mx>322:
    mx=322

def redraw():
  global mx,my,mw,mh,bg,mountain_c
  bg=(R(200,255),R(200,255),R(200,255))
  mx=0
  my=R(100,200)
  mountain_c=(R(0,155),R(0,155),R(0,155))
  fill_rect(0,0,322,222,bg)
  mx+=1
  my+=randint(-2,2)
  fill_rect(mx,my,mw,mh,bg)
  fill_rect(mx,my,2,200,mountain_c)
  draw_string("Sky:"+str(bg),0,0,"black",bg)
  draw_string("Mountain:"+str(mountain_c),0,20,"black",bg)

  
  if mx>322:
    mx=322
  

  
fill_rect(0,0,322,222,bg)
while 1:
  fill_rect(mx,my,mw,mh,mc)
  
  draw_line()
  
  
  if keydown(KEY_OK) or keydown(KEY_EXE):
    sleep(0.2)
    redraw()

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.