Created
October 12, 2017 15:13
-
-
Save grkvlt/2b7744d3c4797f070b449d501bdea5b1 to your computer and use it in GitHub Desktop.
Exploring Iterated Function Systems
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
// Transform unit square to view space | |
double x0 = centre.getX() - (size.getWidth() / 2d / scale); | |
double y0 = centre.getY() - (size.getHeight() / 2d / scale); | |
AffineTransform view = AffineTransform.getScaleInstance(scale, scale); | |
view.translate(-x0, -y0); | |
// Calculate grid position | |
double spacing = config.getMaxGrid() / scale; | |
double mx = centre.getX() - (size.getWidth() / 2d / scale) - (size.getWidth() / 2d); | |
double my = centre.getY() - (size.getHeight() / 2d / scale) - (size.getHeight() / 2d); | |
double rx = Math.IEEEremainder(mx, spacing); | |
double ry = Math.IEEEremainder(my, spacing); | |
double sx = mx - rx + (size.getWidth() / 2d); | |
double sy = my - ry + (size.getHeight() / 2d); | |
int xn = (int) ((sx - x0) / spacing); | |
int yn = (int) ((sy - y0) / spacing); | |
double x1 = sx + (xn - 2) * spacing; | |
double y1 = sy + (yn - 2) * spacing; | |
int n = (size.width / config.getMaxGrid()) + 4; | |
// Draw grid lines | |
g.setStroke(DASHED_LINE_1); | |
for (int i = 0; i < n; i++) { | |
double x = x1 + i * spacing; | |
if (DoubleMath.fuzzyEquals(x, size.getWidth() / 2d, spacing / 100d)) { | |
g.setPaint(alpha(config.getRender().getForeground(), 128)); | |
} else { | |
g.setPaint(alpha(config.getRender().getForeground(), 64)); | |
} | |
double pts[] = { x, y1, x, y1 + n * spacing }; | |
view.transform(pts, 0, pts, 0, 2); | |
if (pts[0] > 0d && pts[0] < size.getWidth()) { | |
Line2D line = new Line2D.Double(pts[0], pts[1], pts[2], pts[3]); | |
g.draw(line); | |
} | |
} | |
for (int i = 0; i < n; i++) { | |
double y = y1 + i * spacing; | |
if (DoubleMath.fuzzyEquals(y, size.getHeight() / 2d, spacing / 100d)) { | |
g.setPaint(alpha(config.getRender().getForeground(), 128)); | |
} else { | |
g.setPaint(alpha(config.getRender().getForeground(), 64)); | |
} | |
double pts[] = { x1, y, x1 + n * spacing, y }; | |
view.transform(pts, 0, pts, 0, 2); | |
if (pts[1] > 0d && pts[1] < size.getWidth()) { | |
Line2D line = new Line2D.Double(pts[0], pts[1], pts[2], pts[3]); | |
g.draw(line); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment