circle(x, y, d);
Draw a circle on the screen.
Arguments
x
The x position of the circley
The y position of the circled
The diameter of the circlefunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
circle(100, 100, 32);
end
Output
ellipse(x, y, w, h);
Draw an ellipse on the screen.
Arguments
x
The x position of the ellipsey
The y position of the ellipsew
The width diameter of the ellipseh
The height diameter of the ellipsefunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
ellipse(100, 100, 64, 32);
end
Output
rect(x, y, w, h);
Draw a rectangle on the screen.
Arguments
x
The x position of the rectangley
The y position of the rectanglew
The widthh
The heightfunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
-- rectangle near the top-left corner
rect(30, 30, 120, 80);
end
Output
square(x, y, s);
Draw a square on the screen.
Arguments
x
The x position of the squarey
The y position of the squares
The size of the squarefunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
-- square near the top-left corner
rect(30, 20, 64);
end
Output
line(x1, y1, x2, y2);
Draw a line on the screen.
Arguments
x1
The x position of the first pointy1
The y position of the first pointx2
The x position of the second pointy2
The y position of the second pointfunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
stroke('white');
-- diagonal line from top-left to mouse pointer
line(0, 0, mouseX, mouseY);
end
Output
arc(x, y, w, h, start, stop);
Draw an arc on the screen.
Arguments
x
The x position of the arcy
The y position of the arcw
The width of the arch
The height of the arcstart
The angle to start the arcstop
The angle to stop the arcfunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
local angle = map(mouseX, 0, width, PI, TWO_PI);
arc(100, 100, 64, 64, 0, angle);
end
Output
point(x, y);
Draw a point on the screen.
Arguments
x
The pointy
The pointUse stroke
to set the point's color, and use strokeWeight
to set the point's radius.
Setting the color with fill
will not affect point
function setup()
createWindow(200, 200);
end
function draw()
background('purple');
strokeWeight(4);
stroke('white');
point(width/2, height/2);
end
Output
quad(x1, y1, x2, y2, x3, y3, x4, y4);
Draw a quad on the screen.
Arguments
x1
The x position of the first pointy1
The y position of the first pointx2
The x position of the second pointy2
The y position of the second pointx3
The x position of the third pointy3
The y position of the third pointx4
The x position of the fourth pointy4
The y position of the fourth pointfunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
quad(30, 60, 160, 50, 130, 165, 40, 145);
end
Output
triangle(x1, y1, x2, y2, x3, y3);
Draw a triangle on the screen.
Arguments
x1
The x position of the first pointy1
The y position of the first pointx2
The x position of the second pointy2
The y position of the second pointx3
The x position of the third pointy3
The y position of the third pointfunction setup()
createWindow(200, 200);
end
function draw()
background('purple');
triangle(50, 150, 100, 50, 150, 150);
end
Output
beginShape([mode]);
Begin adding vertices to a custom shape.
Arguments
[mode]
The opengl shape mode LINES
, POINTS
, QUADS
, TRIANGLES
, TRIANGLE_FAN
, default is LINES
The mode param is not completely implemented in lu5-wasm
function setup()
createWindow(300, 300);
end
function draw()
background('purple');
beginShape();
vertex(150, 50);
vertex(170, 130);
vertex(250, 130);
vertex(185, 170);
vertex(210, 250);
vertex(150, 200);
vertex( 90, 250);
vertex(115, 170);
vertex( 50, 130);
vertex(130, 130);
endShape();
end
Output
vertex(x, y);
Add a vertex to a custom shape.
Arguments
x
The x positiony
The y positionbeginShape
must be called prior.