Skip to content

Instantly share code, notes, and snippets.

@timyates
Last active June 26, 2023 22:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timyates/b200bec96902ca10fac7 to your computer and use it in GitHub Desktop.
Save timyates/b200bec96902ca10fac7 to your computer and use it in GitHub Desktop.
Groovy version of Frege-stairs doodle
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
}
@timyates
Copy link
Author

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 ;-)

@Dierk
Copy link

Dierk commented Jun 26, 2023

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