Last active
July 31, 2018 08:51
-
-
Save dybber/9a5bf90bf609bc2aaac925144ba4b2ad to your computer and use it in GitHub Desktop.
Kombinationslås, PyProcessing, Kickstart i Programmering, DIKU 2018
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Tilstandsvariablen | |
lockState = "LOCKED" | |
# Tegner en lås givet (x,y) koordinat, størrelsesangivelse og | |
# en boolean open, der angiver om låsen skal tegnes som låst | |
# eller åben (True = Åben) | |
def drawLock(x, y, size, open): | |
fill(0) | |
rect(x-1.3*size/2,y-size/2, 1.3*size, size, size/10) | |
noFill() | |
stroke(0) | |
strokeWeight(size/7) | |
if open: | |
arc(x+size, y-size/2, size, size, PI, TWO_PI) | |
else: | |
arc(x, y-size/2, size, size, PI, TWO_PI) | |
stroke(255) | |
line(x, y-size/10, x, y+size/10) | |
noStroke() | |
fill(255) | |
ellipse(x, y-size/10, size/4, size/4) | |
def setup(): | |
size(200, 200) | |
def draw(): | |
global lockState | |
background(255, 255, 255) | |
# Debug print at tilstandsvariablen | |
fill(0) | |
text(lockState, 20, 20) | |
if lockState == "UNLOCKED": | |
drawLock(width/2, height/2, 50, True) | |
else: | |
drawLock(width/2, height/2, 50, False) | |
def keyPressed(): | |
global lockState | |
# Tilstandsmaskinen indkodet som if-sætninger | |
if lockState == "LOCKED": | |
if key == '8': | |
lockState = "FIRST_CORRECT" | |
else: | |
lockState = "LOCKED" | |
elif lockState == "FIRST_CORRECT": | |
if key == '3': | |
lockState = "SECOND_CORRECT" | |
else: | |
lockState = "FIRST_CORRECT" | |
elif lockState == "SECOND_CORRECT": | |
if key == '7': | |
lockState = "UNLOCKED" | |
else: | |
lockState = "SECOND_CORRECT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment