Last active
January 1, 2021 22:23
-
-
Save lucasepe/4425a0db2c474b95fd15de4a1f79a6ec to your computer and use it in GitHub Desktop.
Geometric Art: g2D Tiled Lines
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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") |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to execute the above code?
Install
g2d(https://github.com/lucasepe/g2d)Ready-To-Use Releases
Here you can find
g2dalready compiled for:Run the above snippet with this command:
$ g2d eval tiled-lines.g2d...and here the output...