Skip to content

Instantly share code, notes, and snippets.

@lucasepe
Last active January 1, 2021 22:23
Show Gist options
  • Select an option

  • Save lucasepe/4425a0db2c474b95fd15de4a1f79a6ec to your computer and use it in GitHub Desktop.

Select an option

Save lucasepe/4425a0db2c474b95fd15de4a1f79a6ec to your computer and use it in GitHub Desktop.
Geometric Art: g2D Tiled Lines
// Drawing size
size(1024)
// White background
fillColor(255, 255, 255)
clear()
// Smaller size
s := min(WIDTH, HEIGHT)
// Segment lenght
step := 0.05 * s
// Stroke thickness
strokeWeight(0.2*step)
// Custom function to draw segments
draw := fn(x, y, w, h) {
if randi(10) >= 5 {
moveTo(x, y)
lineTo(x + w, y + h)
} else {
moveTo(x + w, y)
lineTo(x, y + h)
}
strokeColor(randi(255), randi(255), randi(255))
stroke()
}
// Iterate along X-axis ...
x := 0
while(x < s) {
// ...and Y-axis
y := 0
while(y < s) {
draw(x, y, step, step)
y = y + step
}
x = x + step
}
// Save the drawing
snapshot("tiled-lines.png")
@lucasepe
Copy link
Author

lucasepe commented Jan 1, 2021

How to execute the above code?

Install g2d (https://github.com/lucasepe/g2d)

$ go get -u github.com/lucasepe/g2d

Ready-To-Use Releases

Here you can find g2d already compiled for:

  • MacOS
  • Linux
  • Windows

Run the above snippet with this command:

$ g2d eval tiled-lines.g2d

...and here the output...

tiled-lines

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment