G2d
Craft beautiful geometric art using code.
Install / Use
/learn @lucasepe/G2dREADME

g2D - Geometry art built coding
Use the code basics like loops, control flow and specialized functions to generate your geometry artworks.
Examples of g2D Geometry Art
- source code in _examples folder


Installation
Go get
$ go get -u github.com/lucasepe/g2d
Ready-To-Use Releases
Here you can find g2d already compiled for:
- MacOS
- Linux
- Windows
How to use
To execute a local g2d script:
$ g2d /path/to/my-script.g2d
To execute a g2d script stored somewhere on the web:
$ g2d http://my-cool-site.com/remote/path/to/my-script.g2d
Use the --directory (or the shorter -d) flag to specify a destination folder for the generated PNG images.
The g2D Programming Language Syntax
Example-programs can be found beneath examples/ which demonstrate these things, as well as parts of the standard-library.
Types
g2D has the following data types: bool, int, float, str, array, and fn.
Type | Syntax | Notes |
--------- | ----------------------------------------- | ----------------------------------------------- |
bool | true false | |
int | 0 42 1234 -5 | is a signed 64-bit integer |
float | 0.5 4.2 1.234 -5.5 | is a 64-bit double-precision floating point |
str | "" "foo" "\"quotes\" and a\nline break" | are immutable arrays of bytes |
array | [] [1, 2] [1, 2, 3] | grow-able arrays (use the append() builtin) |
fn | fn(a, b) { ... } | defines a custom function |
Bindings
Variables are bounded using the := operator.
a := 3
b := 1.2
Variables may be integers, floats, strings, or arrays/hashes.
To update a variable you can simply specify the equals = operator:
a := 3 // Binding
a = a + 5 // Updating
Arithmetic operations
g2D supports all the basic arithmetic operation of int and float types.
a := 5
b := 3
c := a + b
d := c / 2
e := d * d
Builtin containers
g2d has one builtin containers: array.
Arrays
An array is a list which organizes items by linear sequence. Arrays can hold multiple types.
a := [1, 2.3, "hello!"]
b := [false, true, "Hello World", 3, 3.13]
Adding to an array is done via the push builtin function:
a = append(a, "another")
You can iterate over the contents of an array like so:
i := 0
while( i < len(a) ) {
print( "Array index ", i, " contains ", a[i], "\n")
i = i + 1
}
With the definition we included that produces this output:
Array index 0 contains 1
Array index 1 contains 2.3
Array index 2 contains hello!
Array index 3 contains another
Functions
g2D uses fn to define a function which will be assigned to a variable for naming/invocation purposes:
sum := fn(a, b) { return a + b }
print(sum(5,3), "\n") // Outputs: 8
print(sum(2.5,7.5), "\n") // Outputs: 10
Functions can be passed as values to others functions:
addTwo := fn(a, b, f) {
return 2 + f(a, b)
}
tot := addTwo(68, 1, sum)
print(tot, "\n") // Outputs: 71
Functions inside functions
multiplier := fn(q) {
return fn(x) {
return x*q
}
}
multThree := multiplier(3)
print(multThree(2), "\n") // Outputs: 6
print(multThree(3), "\n") // Outputs: 9
print(multThree(4), "\n") // Outputs: 12
If-else statements
g2D supports if-else statements.
max := fn(a, b) {
if (a > b) {
return a;
} else {
return b;
}
}
print( max(1, 2) ) // Outputs: 2
Switch Statements
g2D supports the switch and case expressions:
switch n := randi(10) {
case n % 2 == 0 {
print(n, " is even", "\n")
}
default {
print(n, " is odd", "\n")
}
}
While Loops
g2D supports only one looping construct, the while loop:
i := 30
while (i > 0) {
print(i, " ")
i = i - 10
}
// 30 20 10
Builtin functions
Core
Function | Description
---------------------- | -------------------------------------------------------------------------- |
exit([status]) | exits the program immediately with the optional status or 0 |
input([prompt] | reads a line from standard input optionally printing the specified prompt |
print(...) | output a string to stdout |
printf(pattern, ...) | output a string to stdout (formatted according the specified pattern) |
sprintf(pattern, ...)| like printf(...) but returns a string |
bool(val) | converts value to a bool |
float(val) | converts decimal value str to float - if val is invalid returns null |
int(val) | converts decimal value str to int - if val is invalid returns null |
str(val) | returns the string representation of val |
len(iterable) | returns the length of the iterable (string or array) |
append(array, val) | returns a new array with value pushed onto the end of array |
Calculation
Function | Description
----------------------- | -------------------------------------------------------------------------- |
abs(x) | returns the absolute value of x |
atan(x) | returns the arc tangent, in radians, of x |
atan2(x, y) | returns the arc tangent of y/x |
cos(x) | returns the cosine of the radian argument x |
degrees(angle) | converts radians into degrees |
hypot(p, q) | returns sqrt(p*p + q*q) |
lerp(start, stop, amt)| calculates a number between two numbers at a specific increment |
map(v, b1, e1, b2, e2)| re-maps a number from one range to another |
max(v1....vn) | returns the largest value in a sequence of numbers |
min(v1....vn) | returns the smallest value in a sequence of numbers |
pow(x, y) | returns x**y, the base x exponential of y |
sin(x) | returns the sine of the radian argument x |
sqrt(x) | returns the square root of x |
radians(angle) | converts a degree measurement to its corresponding value in radians |
randf([min], [max]) | returns a random float between min and max - by default min=0.0 and max=1.0|
randi([min], [max]) | returns a random int between min and max |
Basic graphic functions
Function | Description
------------------------------------- | ------------------------------------------------------------------------------------- |
size(w,[h]) | sets the size of the drawing; when both w and h are specified creates a rectangular image otherwise creates a squared one |
viewport(xMin, xMax, yMin, yMax, xOffset, yOffset) | sets up user-defined coordinate system; performs a screen reset (drawings are cleared)|
clear() | fills the entire image with the current color; clear all drawings |
fillColor(hexcolor) | sets the fill color to the specified hexcolor; example fillColor("#ff0000") |
fillColor(r, g, b, [a]) | sets the fill color to r,g,b,a values - should be between 0 and 255, inclusive |
strokeColor(hexcolor) | sets the stroke color to the specified hexcolor; example strokeColor("#ff0000") |
strokeColor(r, g, b, [a]) | sets the stroke color to r,g,b,a values - should be between 0 and 255, inclusive |
strokeWeight(weight) | sets the stroke thickness to the specified width |
dashes([s1, s2, ...sn]) | sets the current dash pattern to use (call with zero arguments to disable dashes) |
stroke() | strokes the current path with the current stroek color and line width the path is cleared after this operation |
fill() | fills the current path with the current fill color; open subpaths are implicity closed.<br/> The path is cleared after this operation |
fillAndStroke() | fills the current path with the current fill color and strokes it with the current stroke color; the path is cleared after this operation |
push() | saves the curren
Related Skills
node-connect
337.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
337.4kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
83.2kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
337.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
