2D math, camera helpers, transforms, and simple 2D drawing utilities used by the GUI stack.
Key exports
Vec2(x, y)— 2D vector constructorRect2(x, y, width, height)— axis-aligned rectangleTransform2D(options)— translation/rotation/scale transformCamera2D(options)— simple 2D camera withworldToScreen2D/screenToWorld2D- 2D draw helpers:
drawRect2D,drawCircle2D,drawPolyline2D,drawPolygon2D drawEllipse2D(deps, window, cx, cy, rx, ry, color, filled?, borderColor?)— ellipse with independent radiidrawArc2D(deps, window, cx, cy, radius, startAngle, endAngle, color)— arc segment (degrees)drawTriangle2D(deps, window, x1, y1, x2, y2, x3, y3, color, filled?, borderColor?)— triangle shorthanddrawRoundedRect2D(deps, window, x, y, w, h, radius, color, filled?, borderColor?)— rectangle with rounded cornersdrawStar2D(deps, window, cx, cy, outerR, innerR, points, color, filled?, borderColor?)— regular star polygondrawBezier2D(deps, window, points, color, steps?)— quadratic (3 pts) or cubic (4 pts) bezier curvedrawRing2D(deps, window, cx, cy, outerR, innerR, color)— filled annulus (ring)drawCross2D(deps, window, cx, cy, size, thickness, color, filled?)— plus/cross shapedrawDiamond2D(deps, window, cx, cy, width, height, color, filled?)— rotated squaredrawArrow2D(deps, window, x1, y1, x2, y2, color, headSize?)— line with arrowheaddrawCapsule2D(deps, window, cx, cy, width, height, color, filled?)— stadium/pill shapedrawSector2D(deps, window, cx, cy, radius, startAngle, endAngle, color, filled?)— pie wedgedrawRegularPolygon2D(deps, window, cx, cy, radius, sides, color, filled?)— regular n-gondrawSpiral2D(deps, window, cx, cy, startRadius, growth, turns, color)— Archimedean spiraldrawThickLine2D(deps, window, x1, y1, x2, y2, thickness, color)— line with widthdrawDashedLine2D(deps, window, x1, y1, x2, y2, color, dashLen?, gapLen?)— dashed line
All fillable 2D shapes (drawRect2D, drawCircle2D, drawPolygon2D, drawEllipse2D, drawTriangle2D, drawRoundedRect2D, drawStar2D) accept an optional borderColor parameter as their last argument. When provided on a filled shape, the shape is first filled with color, then its outline is drawn with borderColor.
gui := import('GUI')
// Filled red rectangle with a white border
gui.drawRect2D(window, 50, 50, 200, 100, gui.rgb(255, 0, 0), true, gui.rgb(255, 255, 255))
// Filled blue circle with a yellow border
gui.drawCircle2D(window, 200, 200, 60, gui.rgb(0, 0, 255), true, gui.rgb(255, 255, 0))
// Without borderColor — works exactly as before
gui.drawRect2D(window, 50, 50, 200, 100, gui.rgb(255, 0, 0), true)
Usage
Import and use as supporting utilities for GUI drawing and UI coordinate transforms.
g2 := import('gui-2d')
cam := g2.Camera2D({x:0, y:0, zoom:1})
screen := g2.worldToScreen2D({x:10,y:5}, cam, window)