etcha_sketch.py

Created by wperez274

Created on February 23, 2023

1.44 KB


from math import *
from kandinsky import *
from ion import *
from time import *
from random import *

sketch=True
bg=(180,190,200)

R=choice(["white","green",
"red","cyan",
"yellow","brown",
"gray","pink"])

x=150
y=110
sketch_w=2

S=3/1000

fill_rect(0,0,322,222,bg)
fill_rect(0,0,322,5,(200,0,0))
fill_rect(0,217,322,5,(200,0,0))
fill_rect(0,0,5,222,(200,0,0))
fill_rect(315,0,5,222,(200,0,0))

while 1:
  
  c=x
  d=y
  fill_rect(c,d,sketch_w,sketch_w,R)
  
  if sketch:
    draw_string("Black ",245,6,"black",bg)
    fill_rect(x,y,2,2,"black")
  else:
    R=(randint(0,255),randint(0,255),randint(0,255))
    
    draw_string("Random",245,6,"blue",bg)
    

  if keydown(KEY_LEFT):
    direc=1
    sleep(S)
    x-=1
  if x<5:
    x=5
  if keydown(KEY_RIGHT):
    sleep(S)
    x+=1
  if x+sketch_w>313:
    x=313-sketch_w
  if keydown(KEY_UP):
    sleep(S)
    y-=1
  if y<5:
    y=5
  if keydown(KEY_DOWN):
    sleep(S)
    y+=1
  if y+sketch_w>215:
    y=215-sketch_w
  if keydown(KEY_BACKSPACE):
    fill_rect(5,5,310,212,bg)
    sketch_w=1
    x=150
    y=110
    
  if keydown(KEY_OK) and sketch==True:
    sleep(0.2)
    sketch=False
  if keydown(KEY_OK) and sketch==False:
    sleep(0.2)
    sketch=True
  if keydown(KEY_PLUS):
    sleep(0.01)
    sketch_w+=1
  if keydown(KEY_MINUS):
    sleep(0.01)
    sketch_w-=1
  if sketch_w<1:
    sketch_w=1
  if keydown(KEY_ANS):
    sleep(0.02)
    sketch_w=1
    x=150
    y=110

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.