Graphics
Graphics Programming
Required version: Sponge >=1.0.0
Creating a Window
window(800, 600); # Create 800x600 windowColors
let red = color(255, 0, 0);
let green = color(0, 255, 0);
let blue = color(0, 0, 255);
let white = color(255, 255, 255);Drawing Shapes
Rectangles
let rect = rect(50, 50, 200, 150); # x, y, width, height
draw(rect, color(255, 0, 0)); # Draw outline
fill(rect, color(0, 255, 0)); # Fill with colorCircles
let circle = circle(400, 300, 50); # x, y, radius
draw(circle, color(0, 0, 255)); # Draw outline
fill(circle, color(255, 255, 0)); # Fill with colorTriangles
let triangle = triangle(100, 100, 200, 50, 150, 200);
draw(triangle, color(255, 0, 255));
fill(triangle, color(128, 0, 128));The Game Loop
Use is_open() and present() to create an interactive loop:
window(800, 600);
while is_open() {
clear();
# Draw shapes here
let rect = rect(100, 100, 200, 150);
fill(rect, color(255, 0, 0));
# Update display
present();
}Complete Graphics Example
def main() {
window(1024, 768);
while is_open() {
clear();
# Draw background rectangle
let bg = rect(0, 0, 1024, 768);
fill(bg, color(200, 200, 200));
# Draw a circle
let circle = circle(512, 384, 100);
fill(circle, color(255, 100, 100));
# Draw a triangle
let tri = triangle(200, 200, 400, 150, 300, 400);
draw(tri, color(0, 100, 255));
present();
}
}Utility Functions
print(window_width()); # Get window width
print(window_height()); # Get window height