Skip to main content
Dat 1. Sem Efterår 2025
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Common Functions

FunctionExplanation
size(width, height)Sets the dimensions of the sketch window (must be in setup()).
setup()Runs once at the beginning; used to set size, background, initialize variables.
draw()Loops continuously after setup(), used for drawing and animation.
background(color)Sets the background color each frame.
fill(color)Sets the fill color for shapes.
stroke(color)Sets the outline color for shapes.
noFill()Disables shape filling.
noStroke()Disables shape outlines.
line(x1, y1, x2, y2)Draws a line between two points.
rect(x, y, w, h)Draws a rectangle at (x,y) with width w and height h.
ellipse(x, y, w, h)Draws an ellipse (or circle if w == h).
triangle(x1, y1, x2, y2, x3, y3)Draws a triangle with three corner points.
quad(x1, y1, x2, y2, x3, y3, x4, y4)Draws a quadrilateral.
point(x, y)Draws a single point.
text(str, x, y)Draws a text string at the given position.
textSize(size)Sets the font size for text.
mouseX, mouseYVariables storing the current mouse position.
key, keyCodeVariables holding the last pressed key.
mousePressed()Runs when the mouse button is pressed.
keyPressed()Runs when a key is pressed.
random(max) / random(min, max)Generates a random float between the given range.
map(value, start1, stop1, start2, stop2)Maps a value from one range to another.
frameRate(fps)Sets or returns the frame rate of draw().
pushMatrix() / popMatrix()Saves and restores transformations (rotation, scale, translate).
translate(x, y)Moves the origin of the drawing coordinate system.
rotate(angle)Rotates the coordinate system.
scale(factor)Scales the coordinate system.
loadImage(filename)Loads an image from the data/ folder.
image(img, x, y, w, h)Draws an image at the given position and size.