def draw():
global yPos
# draw() loops forever. Until stopped
background(204)
yPos = yPos-1
if yPos < 0:
yPos = height()
line(0, yPos, width(), yPos)
yPos = height()
timer(draw)
draw()
def onMousePressed():
global go
if go == True:
noLoop()
else:
loop()
go = not go
def draw():
global x
background(204)
x = x + 1
if x > width():
x = 0
line(x, 0, x, height())
x = 0
timer(draw)
mousePressed(onMousePressed)
go = True
loop()
def draw():
noLoop()
background(200)
line(10, 10, 90, 90)
timer(draw)
def draw():
global x
if mouseIsPressed() == True:
noLoop()
background(204)
x = x + 1
if x > width():
x = 0
line(x, 0, x, height() )
x = 0
timer(draw)
noLoop()
def draw():
global counter
background(200)
text(counter)
if keyIsPressed() == True:
NoLoop()
counter += 1
counter = 0
timer(draw)
Timer = "Method"
def draw():
global x
background(204)
x = x + 1
if x > width():
x = 0
line(x, 0, x, height())
x = 0
timer(draw)
frameRate(30)
frameRate(fps)
frameRate()
def draw():
background(200)
text(frameCount())
timer(draw)
frameCount()
def output():
background(204)
millisecond = millis()
text("Milliseconds \n running: \n"+ str(millisecond), 5, 40)
timer(output)
millis()
def draw():
background(200)
text(f"Width: {width()}\nHeight: {height()}")
width(100)
height(100)
timer(draw)
def draw():
background(200)
text(f"Width: {width()}\nHeight: {height()}")
width(100)
height(100)
timer(draw)
def draw():
background(204)
widthMid = width() / 2
heightMid = height() / 2
line(widthMid, 0, widthMid, height())
line(0, heightMid, width(), heightMid)
if mouseX() < widthMid and mouseY() < heightMid:
cursor("Arrow")
elif mouseX() > widthMid and mouseY() < heightMid:
cursor("No")
elif mouseX() > widthMid and mouseY() > heightMid:
cursor("SizeAll")
else:
cursor("UpArrow")
timer(draw)
cursor("Cursortype")
r = random(50, 100)
line(30 + r, 40, 85, r)
random(min, max)
background(200)
a = 20
b = 80
c = lerp(a, b, 0.2)
d = lerp(a, b, 0.5)
e = lerp(a, b, 0.8)
y = 50
strokeWeight(5)
circle(a, y, 5)
circle(b, y, 5)
stroke(100)
circle(c, y, 5)
circle(d, y, 5)
circle(e, y, 5)
lerp(start, stop, amt);
background(200)
x1 = 20
x2 = 80
y = 50
strokeWeight(5)
circle(x1, y, 5)
circle(x2, y, 5)
d = dist(x1, y, x2, y)
text("Distance: " + str(d))
dist(x1, y1, x2, y2);
background(200)
triangle(20,20, 110,20, 20,100)
x = dist(20, 20, 110, 20)
y = dist(20, 20, 20, 100)
h = hypot(x, y)
text("Hypotenuse Length: " + str(h))
hypot(first, second);
def draw():
background(200)
leftWall = 25
rightWall = 75
# x1 is just the mouseX, while
# x2 is the mouseX, but constrained
# between the leftWall and rightWall!
x1 = mouseX()
x2 = constrain(mouseX(), leftWall, rightWall)
# draw the walls
stroke(150)
line(leftWall, 0, leftWall, height())
line(rightWall, 0, rightWall, height())
# draw x1 and x2 as circles
noStroke()
fill(150)
ellipse(x1, 33, 9, 9) # not constrained
fill(0)
ellipse(x2, 66, 9, 9) # constrained
timer(draw)
constrain(n, low, high);
background(200)
value = 23
m = map(value, 20, 80, 0, 100, True)
text(m); # output: 5
map(value, start1, stop1, start2, stop2, [withinBounds])
background(200)
value = 30
n = norm(value, 0, 100)
text(n) # output: 0.3
norm(value, start, stop)
deg = 45.0
rad = radians(deg)
text(f"{deg} degrees is {rad} radians")
radians(degrees)
def draw():
global xoff
background(200)
xoff = xoff + 0.01
n = noise(xoff) * width() / 2
line(n, 0, n, height())
text(noise(xoff))
xoff = 0.0
timer(draw)
noise(x, [y], [z])
text(PI)
text(TWO_PI)
text(HALF_PI)
text(QUARTER_PI)
def draw():
background(200)
line(mouseX(), 0, mouseX(), height())
timer(draw)
mouseX()
def draw():
background(200)
line(0, mouseY(), width(), mouseY())
timer(draw)
mouseY
def draw():
background(237, 34, 93)
fill(0)
if mouseIsPressed() == True:
ellipse(50, 50, 50, 50)
else:
rect(50, 50, 50, 50)
text("mouseIsPressed: " + str(mouseIsPressed()))
timer(draw)
mouseIsPressed()
def onMousePressed():
global value
fill(value)
rect(25, 25, 50, 50)
if value == 0:
value = 255
else:
value = 0
mousePressed(onMousePressed)
value = 0
background(200)
mousePressed()
def draw():
background(237, 34, 93)
fill(0)
if mouseButton() == LEFT_BUTTON:
ellipse(50, 50, 50, 50)
if mouseButton() == RIGHT_BUTTON:
rect(50, 50, 50, 50)
if mouseButton() == MIDDLE_BUTTON:
triangle(23, 75, 50, 20, 78, 75)
print(mouseButton())
timer(draw)
mouseButton()
def draw():
fill(0)
if keyIsPressed() == True:
fill(255)
else:
fill(0)
square(25, 25, 25)
timer(draw)
keyIsPressed()
def draw():
global value
fill(value)
if value == 0:
value = 255
else:
value = 0
square(25, 25, 25)
keyPressed(draw)
value = 0
keyPressed()
def onKeyPressed():
background(204)
text(key(), 25, 25)
keyPressed(onKeyPressed)
key()
def onKeyPressed():
background(204)
text(keyCode(), 25, 25)
keyPressed(onKeyPressed)
keyCode()
ellipse(45, 45, 50, 80)
ellipse(x, y, w, [h])
circle(45, 45, 50)
circle(x, y, d)
rect(45, 45, 50, 65)
rect(x, y, w, h)
square(45, 40.35, 50)
square(x, y, w)
line(40, 60, 80, 100)
line(x1, y1, x2, y2)
triangle(20, 10, 80, 80, 100, 10)
triangle(x1, y1, x2, y2, x3, y3)
path = "http://mana-buch.de/150/cover.png"
image(path)
path = "C:\images\Flappy.png"
image(path, 5, 10)
image(path, [x], [y])
point(20, 40)
point(x, y)
arc(100, 100, 200, 250, 50, 80, 45, True)
arc(x1, y1, x2, y2, w, h, angle rotation, clockwise)
bezier(25, 20, 100, 180, 280, 12, 305, 350, True)
bezier(xStart, yStart, x1, y1, x2, y2, x3, y3, isClosed)
text("Test", 25, 30, 20, 30)
Text(text, x, y, [w], [h])
color = random(0, 255)
background(color)
background(value)
background(x1, x2, x3)
background(x1, x2, x3, alpha)
background(colorString)
fill(51)
rect(50,50,60,60)
Fill(value)
fill(x1, x2, x3)
fill(x1, x2, x3, alpha)
fill(gray value, alpha)
fill(colorString)
noFill()
rect(50,50,60,60)
noFill()
strokeWeight(4)
stroke(51)
rect(100, 100, 60, 60)
stroke(value)
stroke(x1, x2, x3)
stroke(x1, x2, x3, alpha)
stroke(gray value, alpha)
stroke(colorString)
fill("LightBlue")
noStroke()
rect(50, 50, 60, 60)
noStroke()
textSize(13)
text("Font Size 13", 10, 30)
textSize(15)
text("Font Size 15", 10, 60)
textSize(17)
text("Font Size 17", 10, 90)
textSize(size)
textSize(22)
textFont("Georgia")
text("Georgia", 12, 30)
textFont("Helvetica")
text("Helvetica", 12, 60)
textFont(textFont)
textColor("Red")
text("Text Color", 10, 30)
textColor(value)
textColor(x1, x2, x3)
textColor(x1, x2, x3, alpha)
textColor(colorString)
def draw():
background(128)
translate(2,2)
rotate(radians(0.45))
rect(width()/2, height()/2, 50, 50)
timer(draw)
rotate(angle)
rect(40, 40, 55, 55)
translate(30, 20)
rect(50, 50, 55, 55)
translate(14, 14)
rect(60, 60, 55, 55)
def draw():
rectangle.Translate(1, 1)
timer(draw)
rectangle = rect(0, 0, 55, 55)
translate(x, y)
strokeWeight(1)
line(20, 20, 80, 20)
strokeWeight(4)
line(20, 40, 80, 40)
strokeWeight(10)
line(20, 70, 80, 70)
strokeWeight(weight)
strokeWeight(12)
strokeCap(FLAT)
line(20, 10, 80, 10)
strokeCap(SQUARE)
line(20, 30, 80, 30)
strokeCap(ROUND)
line(20, 50, 80, 50)
strokeCap(TRIANGLE)
line(20, 70, 80, 70)
strokeCap(cap)
ellipseMode(CORNER)
fill(255)
ellipse(15, 15, 30, 30)
ellipseMode(mode)
rectMode(CORNER)
fill(255)
rect(25,25,50,50)
rectMode(mode)
print("Hello World")
print()