Text Size
Text Size
Exit Full Screen
Python Mini
Show
Source Code
View Source Code in Full Screen
Open in New Tab
from processing import * width = 550 height = 400 sqx = width/2 sqy = height/2 sqw = 10 sqh = 10 r = 255 g = 255 b = 255 def setup(): size(width, height) background(0) def draw(): fill(r, g, b) stroke(r, g, b) rect(sqx, sqy, sqw, sqh) def keyPressed(): global sqx, sqy, r, g, b if keyboard.key == "a": sqx -= 2 if keyboard.key == "d": sqx += 2 if keyboard.key == "w": sqy -= 2 if keyboard.key == "s": sqy += 2 if keyboard.keyCode == 32: background(0) if keyboard.keyCode == ENTER: color = input("Choose a color: red, blue, green, navy blue, plum, pink") color = color.lower() if color == "red": r = 255 g = 0 b = 0 elif color == "blue": r, g, b = 0, 0, 255 elif color == "green": r, g, b = 0, 255, 0 elif color == "navy blue": r, g, b = 0, 51, 102 elif color == "plum": r, g, b = 51, 0, 51 elif color == "pink": r, g, b = 255, 153, 153 else: r, g, b = 255, 255, 255 run()
etch_a_sketch.py
( around 49 lines python code )
Published By:
Dev
Published on
2019-07-17T16:43:33Z
Python Mini
- an
OYOclass
application,
own your own class today
.
Run
Result
×
Error message shows here