Last active
June 26, 2023 22:50
-
-
Save timyates/b200bec96902ca10fac7 to your computer and use it in GitHub Desktop.
Groovy version of Frege-stairs doodle
This file contains 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
import java.awt.Color | |
import java.awt.Graphics2D | |
import static java.awt.RenderingHints.* | |
import java.awt.image.BufferedImage | |
import groovy.transform.Immutable | |
@Immutable class Point { double x, y } | |
@Immutable class Trail { Point first, second, third, last } | |
Closure<Point> bearing = { Point start, Point over -> | |
new Point((over.x - start.x) * 1.05 + start.x, (over.y - start.y) * 1.05 + start.y) | |
} | |
Closure<Trail> step = { Trail param -> | |
new Trail(bearing(param.first, param.last), param.first, param.second, param.third) | |
} | |
Trail start = new Trail(new Point(-10, 10), new Point(-10, -10), new Point(10, -10), new Point(9.5, 9.5)) | |
new BufferedImage(600, 600, BufferedImage.TYPE_INT_RGB).with { img -> | |
createGraphics().with { g -> | |
paint = Color.WHITE | |
fillRect 0, 0, 600, 600 | |
translate 300, 300 | |
setRenderingHint KEY_ANTIALIASING, VALUE_ANTIALIAS_ON | |
paint = Color.BLACK | |
Closure<Trail> connect = { Trail trail -> | |
drawLine((int)trail.second.x, (int)trail.second.y, (int)trail.first.x, (int)trail.first.y) | |
trail | |
} | |
// Main loop | |
(1..500).inject(start) { curr, _ -> connect step(curr) } | |
dispose() | |
} | |
img | |
} |
I love it. Thanks for the credits!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just for fun...
Original here: http://dierk.github.io/FregeGoodness/html/index.html#lists_as_streams_and_iterators
Run in the GroovyConsole to get the image shown in the output window ;-)