Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

added experimental SkylinePlotter and unfinished network graph using the SkylinePlotter

Michael Peter Christen9b91b5270047
diff --git a/source/net/yacy/htroot/NetworkPicture.java b/source/net/yacy/htroot/NetworkPicture.java
index 2f45d1e40..698331c89 100644
--- a/source/net/yacy/htroot/NetworkPicture.java
+++ b/source/net/yacy/htroot/NetworkPicture.java
@@ -110,6 +110,7 @@ public class NetworkPicture {
if ( maxCount > 10000 ) {
maxCount = 10000;
}
+
NetworkGraph.buffer =
new EncodedImage(NetworkGraph.getNetworkPicture(
sb.peers,
@@ -124,6 +125,23 @@ public class NetworkPicture {
env.getConfig("network.unit.description", "unspecified"),
Long.parseLong(bgcolor, 16),
cyc), "png", false);
+
+ /*
+ NetworkGraph.buffer =
+ new EncodedImage(NetworkSkylineGraph.getNetworkSkylinePicture(
+ sb.peers,
+ width,
+ height,
+ passiveLimit,
+ potentialLimit,
+ maxCount,
+ coronaangle,
+ communicationTimeout,
+ env.getConfig(SwitchboardConstants.NETWORK_NAME, "unspecified"),
+ env.getConfig("network.unit.description", "unspecified"),
+ Long.parseLong(bgcolor, 16),
+ cyc), "png", false);
+ */
lastAccessSeconds = System.currentTimeMillis() / 1000;
sync.release();
diff --git a/source/net/yacy/peers/graphics/NetworkSkylineGraph.java b/source/net/yacy/peers/graphics/NetworkSkylineGraph.java
new file mode 100644
index 000000000..cc9def5bc
--- /dev/null
+++ b/source/net/yacy/peers/graphics/NetworkSkylineGraph.java
@@ -0,0 +1,372 @@
+/**
+ * NetworkSkylineGraph
+ * Copyright 2025 by Michael Peter Christen
+ * First released 20.09.2025 at https://yacy.net
+ *
+ * This file is part of YaCy.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.peers.graphics;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import net.yacy.cora.document.encoding.ASCII;
+import net.yacy.cora.document.feed.Hit;
+import net.yacy.cora.document.feed.RSSMessage;
+import net.yacy.cora.federate.yacy.Distribution;
+import net.yacy.cora.util.ConcurrentLog;
+import net.yacy.peers.EventChannel;
+import net.yacy.peers.Seed;
+import net.yacy.peers.SeedDB;
+import net.yacy.visualization.PrintTool;
+import net.yacy.visualization.RasterPlotter;
+import net.yacy.visualization.SkylinePlotter;
+import net.yacy.visualization.SkylinePlotter.SkylineBeam;
+import net.yacy.visualization.SkylinePlotter.SkylineConfig;
+import net.yacy.visualization.SkylinePlotter.SkylineObject;
+
+/**
+ * Alternative skyline themed visualization of the YaCy network state.
+ */
+public final class NetworkSkylineGraph {
+
+ private static final double DOUBLE_LONG_MAX_VALUE = Long.MAX_VALUE;
+
+ private static final long SKYLINE_BACKGROUND = 0x000011L;
+ private static final long GRID_COLOR = 0x00C0FFL;
+
+ private static final long COL_ACTIVE_BUILDING = 0x0066E6L;
+ private static final long COL_PASSIVE_BUILDING = 0x2B4A80L;
+ private static final long COL_POTENTIAL_BUILDING = 0x245C3DL;
+ private static final long COL_SELF = 0xFF3355L;
+ private static final long COL_RUNWAY = 0x103030L;
+
+ private static final long COL_ACTIVE_TEXT = 0x77CCFFL;
+ private static final long COL_PASSIVE_TEXT = 0x9EB8DCL;
+ private static final long COL_POTENTIAL_TEXT = 0x7FD7ABL;
+ private static final long COL_SELF_TEXT = 0xFFD6E0L;
+
+ private static final long COL_BEAM_IN = 0x4CFF88L;
+ private static final long COL_BEAM_OUT = 0xFF7766L;
+
+ private static final int BASE_PASSIVE_LIMIT = 60;
+ private static final int BASE_POTENTIAL_LIMIT = 240;
+
+ private NetworkSkylineGraph() { }
+
+ private static final class Placement {
+ final double x;
+ final double z;
+ final double base;
+ final double height;
+
+ Placement(final double x, final double z, final double base, final double height) {
+ this.x = x;
+ this.z = z;
+ this.base = base;
+ this.height = height;
+ }
+
+ double top() {
+ return this.base + this.height;
+ }
+ }
+
+ private enum PeerTier {
+ ACTIVE(COL_ACTIVE_BUILDING, COL_ACTIVE_TEXT, 0.75d, 0.20d, 6),
+ PASSIVE(COL_PASSIVE_BUILDING, COL_PASSIVE_TEXT, 0.40d, 0.12d, 0),
+ POTENTIAL(COL_POTENTIAL_BUILDING, COL_POTENTIAL_TEXT, 0.25d, 0.08d, 8),
+ SELF(COL_SELF, COL_SELF_TEXT, 0.90d, 0.30d, 0);
+
+ final long color;
+ final long textColor;
+ final double bobFactor;
+ final double pulseFactor;
+ final int patternModulo;
+
+ PeerTier(final long color, final long textColor, final double bobFactor, final double pulseFactor, final int patternModulo) {
+ this.color = color;
+ this.textColor = textColor;
+ this.bobFactor = bobFactor;
+ this.pulseFactor = pulseFactor;
+ this.patternModulo = patternModulo;
+ }
+ }
+
+ public static SkylinePlotter getNetworkSkylinePicture(final SeedDB seedDB,
+ final int width,
+ final int height,
+ final int passiveLimit,
+ final int potentialLimit,
+ final int maxCount,
+ final int coronaAngle,
+ final long communicationTimeout,
+ final String networkName,
+ final String networkTitle,
+ final long backgroundColor,
+ final int cyc) {
+ final SkylineConfig config = new SkylineConfig();
+ config.width = width;
+ config.height = height;
+ config.backgroundColor = backgroundColor != 0 ? backgroundColor : SKYLINE_BACKGROUND;
+ config.gridColor = GRID_COLOR;
+ config.gridIntensity = 40;
+ config.gridPulse = 10;
+ config.gridStepX = 28.0d;
+ config.gridStepZ = 36.0d;
+ config.fieldWidth = 460.0d;
+ config.fieldDepth = 680.0d;
+ config.focalLength = 580.0d;
+ config.cameraDepth = 150.0d;
+ config.groundLevel = 220.0d;
+ config.horizonY = height / 3;
+
+ final SkylinePlotter skyline = new SkylinePlotter(config);
+ skyline.clearScene();
+
+ final Map<String, Placement> placements = new HashMap<String, Placement>();
+ final Set<String> seen = new HashSet<String>();
+ if (seedDB != null && seedDB.mySeed() != null && seedDB.mySeed().hash != null) {
+ seen.add(seedDB.mySeed().hash);
+ }
+
+ // optional runway to anchor the scene
+ skyline.addBox(0.0d, config.fieldDepth - 60.0d,
+ config.fieldWidth * 1.4d,
+ 90.0d,
+ -20.0d,
+ 16.0d,
+ COL_RUNWAY)
+ .edges(RasterPlotter.lighten(COL_RUNWAY, 1.4d))
+ .intensity(55)
+ .dotted(4)
+ .label("DATAPLANE", -30, 22)
+ .labelIntensity(60)
+ .labelColor(RasterPlotter.lighten(COL_RUNWAY, 2.4d));
+
+ int totalCount = 0;
+ if (seedDB != null) {
+ totalCount += plotPeers(skyline, placements, seen,
+ seedDB.seedsConnected(true, false, null, 0.0f),
+ maxCount, PeerTier.ACTIVE, 150.0d, 90.0d, passiveLimit, false);
+
+ totalCount += plotPeers(skyline, placements, seen,
+ seedDB.seedsSortedDisconnected(false, Seed.LASTSEEN),
+ maxCount, PeerTier.PASSIVE, 220.0d, 110.0d, passiveLimit > 0 ? passiveLimit : BASE_PASSIVE_LIMIT, true);
+
+ totalCount += plotPeers(skyline, placements, seen,
+ seedDB.seedsSortedPotential(false, Seed.LASTSEEN),
+ maxCount, PeerTier.POTENTIAL, 310.0d, 130.0d, potentialLimit > 0 ? potentialLimit : BASE_POTENTIAL_LIMIT, true);
+
+ final Seed self = seedDB.mySeed();
+ if (self != null) {
+ final Placement placement = plotSelfPeer(skyline, placements, seen, self);
+ if (placement != null) {
+ totalCount++;
+ }
+ }
+
+ addCommunicationBeams(skyline, placements, seedDB, communicationTimeout);
+ }
+
+ final int frameIndex = (((cyc % 360) + 360) % 360) / 45;
+ skyline.renderFrame(frameIndex);
+
+ final long headlineColor = RasterPlotter.lighten(config.gridColor, 1.2d);
+ skyline.setColor(headlineColor);
+ final String name = networkName == null ? "UNSPECIFIED" : networkName.toUpperCase();
+ final String title = networkTitle == null ? "" : networkTitle.toUpperCase();
+ PrintTool.print(skyline, 2, 6, 0, "YACY SKYLINE '" + name + "'", -1, 100);
+ PrintTool.print(skyline, 2, 14, 0, title, -1, 80);
+ PrintTool.print(skyline, width - 2, 6, 0,
+ "SNAPSHOT " + new Date().toString().toUpperCase(), 1, 80);
+ PrintTool.print(skyline, width - 2, 14, 0,
+ "RENDERED " + totalCount + " PEERS", 1, 80);
+
+ return skyline;
+ }
+
+ private static int plotPeers(final SkylinePlotter skyline,
+ final Map<String, Placement> placements,
+ final Set<String> seen,
+ final Iterator<Seed> iterator,
+ final int maxCount,
+ final PeerTier tier,
+ final double baseZ,
+ final double baseWidth,
+ final int timeLimitMinutes,
+ final boolean limitLastSeen) {
+ if (iterator == null) return 0;
+ int count = 0;
+ while (iterator.hasNext() && count < maxCount) {
+ final Seed seed = iterator.next();
+ if (seed == null) {
+ ConcurrentLog.warn("NetworkSkylineGraph", tier + " seed == null");
+ continue;
+ }
+ final String hash = seed.hash;
+ if (hash == null || hash.length() == 0) continue;
+ if (hash.startsWith("AD")) continue;
+ if (!seen.add(hash)) continue;
+
+ if (limitLastSeen) {
+ final long minutes = Math.abs((System.currentTimeMillis() - seed.getLastSeenUTC()) / 60000L);
+ if (minutes > timeLimitMinutes) continue;
+ }
+
+ final Placement placement = createPlacement(skyline, seed, tier, baseZ, baseWidth);
+ placements.put(hash, placement);
+ count++;
+ }
+ return count;
+ }
+
+ private static Placement createPlacement(final SkylinePlotter skyline,
+ final Seed seed,
+ final PeerTier tier,
+ final double zBase,
+ final double footprint) {
+ final SkylineConfig config = skyline.getConfig();
+ final long hashValue = Distribution.horizontalDHTPosition(ASCII.getBytes(seed.hash));
+ final double normalized = hashValue / DOUBLE_LONG_MAX_VALUE;
+ final double jitter = ((seed.hash.hashCode() & 0x1FF) - 256) * 0.12d;
+ final double x = (normalized - 0.5d) * config.fieldWidth * 0.9d + jitter;
+
+ final double depthJitter = ((seed.hash.hashCode() >> 9) & 0x3F) - 32;
+ final double z = zBase + depthJitter;
+
+ final long links = Math.max(1L, seed.getLinkCount());
+ final double ppm = Math.max(0, seed.getPPM());
+ final double qpm = Math.max(0.0d, seed.getQPM());
+ final double height = computeHeight(links, ppm, qpm, tier);
+ final double baseHeight = Math.max(-4.0d, Math.min(30.0d, Math.log10(links + 1.0d) * 4.0d));
+
+ final long color = tier.color;
+ final long accent = RasterPlotter.lighten(color, 1.35d);
+ final long edges = RasterPlotter.lighten(color, 1.6d);
+ final SkylineObject object = skyline.addBox(x, z, footprint, footprint * 0.7d, baseHeight, height, color);
+ final String name = safePeerName(seed);
+ final int labelOffsetX = -Math.max(10, name.length() * 3);
+ final int labelOffsetY = (int) (-height / 4.0d) - 10;
+ object.accent(accent)
+ .edges(edges)
+ .intensity(80)
+ .bob(Math.min(18.0d, ppm * tier.bobFactor / 18.0d))
+ .pulse(Math.min(16.0d, qpm * tier.pulseFactor))
+ .dotted(tier.patternModulo)
+ .patternPhase(Math.abs(seed.hash.hashCode() % 360))
+ .animationPhase((seed.hash.hashCode() & 0x1FF) % 360)
+ .label(name, labelOffsetX, labelOffsetY)
+ .labelColor(tier.textColor)
+ .labelIntensity(90);
+ return new Placement(x, z, baseHeight, height);
+ }
+
+ private static Placement plotSelfPeer(final SkylinePlotter skyline,
+ final Map<String, Placement> placements,
+ final Set<String> seen,
+ final Seed self) {
+ final String hash = self.hash;
+ if (hash == null || hash.length() == 0) return null;
+ seen.add(hash);
+
+ final SkylineConfig config = skyline.getConfig();
+ final long hashValue = Distribution.horizontalDHTPosition(ASCII.getBytes(hash));
+ final double normalized = hashValue / DOUBLE_LONG_MAX_VALUE;
+ final double x = (normalized - 0.5d) * config.fieldWidth * 0.6d;
+ final double z = 120.0d;
+ final double diameter = 140.0d;
+ final double baseHeight = 8.0d;
+ final SkylineObject sphere = skyline.addSphere(x, z, diameter, baseHeight, COL_SELF);
+ final String name = safePeerName(self);
+ sphere.accent(RasterPlotter.lighten(COL_SELF, 1.4d))
+ .intensity(90)
+ .bob(20.0d)
+ .pulse(14.0d)
+ .animationPhase(180.0d)
+ .label(name, -Math.max(36, name.length() * 3), -30)
+ .labelColor(COL_SELF_TEXT);
+ final Placement placement = new Placement(x, z, baseHeight, diameter);
+ placements.put(hash, placement);
+ return placement;
+ }
+
+ private static void addCommunicationBeams(final SkylinePlotter skyline,
+ final Map<String, Placement> placements,
+ final SeedDB seedDB,
+ final long communicationTimeout) {
+ if (communicationTimeout < 0 || seedDB == null) return;
+ final Seed self = seedDB.mySeed();
+ if (self == null) return;
+ final Placement selfPlacement = placements.get(self.hash);
+ if (selfPlacement == null) return;
+
+ final Date horizon = new Date(System.currentTimeMillis() - communicationTimeout);
+ addChannelBeams(skyline, placements, seedDB, selfPlacement, horizon, EventChannel.DHTRECEIVE, COL_BEAM_IN, false);
+ addChannelBeams(skyline, placements, seedDB, selfPlacement, horizon, EventChannel.DHTSEND, COL_BEAM_OUT, true);
+ }
+
+ private static void addChannelBeams(final SkylinePlotter skyline,
+ final Map<String, Placement> placements,
+ final SeedDB seedDB,
+ final Placement selfPlacement,
+ final Date horizon,
+ final EventChannel channel,
+ final long color,
+ final boolean outgoing) {
+ final Iterable<RSSMessage> events = EventChannel.channels(channel);
+ if (events == null) return;
+ for (final Hit event : events) {
+ if (event == null) continue;
+ if (event.getPubDate() == null || event.getPubDate().before(horizon)) continue;
+ final String link = event.getLink();
+ if (link == null) continue;
+ final Seed other = seedDB.get(link);
+ if (other == null) continue;
+ final Placement otherPlacement = placements.get(other.hash);
+ if (otherPlacement == null) continue;
+ final Placement source = outgoing ? selfPlacement : otherPlacement;
+ final Placement target = outgoing ? otherPlacement : selfPlacement;
+ final SkylineBeam beam = skyline.addBeam(source.x, source.top() + 6.0d, source.z,
+ target.x, target.top() + 6.0d, target.z, color);
+ beam.intensity(88)
+ .pulse(12.0d)
+ .dotted(6)
+ .patternPhase(Math.abs(link.hashCode()) % 360)
+ .animationPhase((link.hashCode() & 0x1FF) % 360);
+ }
+ }
+
+ private static double computeHeight(final long links, final double ppm, final double qpm, final PeerTier tier) {
+ final double linkFactor = Math.min(180.0d, Math.log10(links + 1.0d) * 22.0d);
+ final double crawlFactor = Math.min(60.0d, ppm * tier.bobFactor / 8.0d);
+ final double queryFactor = Math.min(48.0d, qpm * tier.pulseFactor * 1.5d);
+ return 40.0d + linkFactor + crawlFactor + queryFactor;
+ }
+
+ private static String safePeerName(final Seed seed) {
+ if (seed == null) return "UNKNOWN";
+ final String name = seed.getName();
+ if (name == null || name.length() == 0) return "UNKNOWN";
+ return name.toUpperCase();
+ }
+}
diff --git a/source/net/yacy/visualization/RasterPlotter.java b/source/net/yacy/visualization/RasterPlotter.java
index f7756a4ff..c7d102728 100644
--- a/source/net/yacy/visualization/RasterPlotter.java
+++ b/source/net/yacy/visualization/RasterPlotter.java
@@ -38,6 +38,7 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.Arrays;
import java.util.Set;
import java.util.TreeSet;
import java.util.zip.CRC32;
@@ -160,37 +161,111 @@ public class RasterPlotter {
}
}
+ /**
+ * Set the default drawing mode for all following draw operations.
+ * @param drawMode the drawing mode
+ */
public void setDrawMode(final DrawMode drawMode) {
this.defaultMode = drawMode;
}
+ /**
+ * Get the current drawing mode
+ * @return the drawing mode
+ */
public BufferedImage getImage() {
return this.image;
}
+ /**
+ * get the cwidth of the image
+ * @return the width
+ */
public int getWidth() {
return this.width;
}
+ /**
+ * get the height of the image
+ * @return the height
+ */
public int getHeight() {
return this.height;
}
+ /**
+ * test if a color is dark or bright
+ * @param s
+ * @return true if the color is dark, false if it is bright (threshold is 384)
+ */
public static boolean darkColor(final String s) {
return darkColor(Long.parseLong(s, 16));
}
+ /**
+ * test if a color is dark or bright
+ * @param c
+ * @return true if the color is dark, false if it is bright (threshold is 384)
+ */
public static boolean darkColor(final long c) {
final int r = (int) (c >> 16);
final int g = (int) ((c >> 8) & 0xff);
final int b = (int) (c & 0xff);
return r + g + b < 384;
}
+
+ /**
+ * lighten a color by a factor
+ * @param color the color to be lightened
+ * @param factor the factor to lighten (1.0 = no change, 2.0 = double bright, 0.5 = half bright)
+ * @return the lightened color
+ */
+ public static long lighten(final long color, final double factor) {
+ final int r = clampColor((int) Math.round(((color >> 16) & 0xff) * factor));
+ final int g = clampColor((int) Math.round(((color >> 8) & 0xff) * factor));
+ final int b = clampColor((int) Math.round((color & 0xff) * factor));
+ return ((long) r << 16) | ((long) g << 8) | (long) b;
+ }
+
+ /**
+ * darken a color by a factor
+ * @param color the color to be darkened
+ * @param factor the factor to darken (1.0 = no change, 2.0 = double dark, 0.5 = half dark)
+ * @return the darkened color
+ */
+ public static long darken(final long color, final double factor) {
+ final int r = clampColor((int) Math.round(((color >> 16) & 0xff) * factor));
+ final int g = clampColor((int) Math.round(((color >> 8) & 0xff) * factor));
+ final int b = clampColor((int) Math.round((color & 0xff) * factor));
+ return ((long) r << 16) | ((long) g << 8) | (long) b;
+ }
+
+ /**
+ * clamp a color value to the range 0..255
+ * @param value the color value
+ * @return the clamped color value
+ */
+ public static int clampColor(final int value) {
+ return (value < 0) ? 0 : (value > 255) ? 255 : value;
+ }
+ /**
+ * get the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ * @return an array of three integers containing the RGB values of the pixel
+ */
public int[] getPixel(final int x, final int y) {
return getPixel(x, y, new int[3]);
}
+ /**
+ * get the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ * @param c an array of three integers to store the RGB values of the pixel
+ * @return the array c containing the RGB values of the pixel
+ */
public int[] getPixel(final int x, final int y, int[] c) {
if (this.frame == null) return this.grid.getPixel(x, y, c);
int cell = (this.width * y + x) * 3;
@@ -200,6 +275,12 @@ public class RasterPlotter {
return c;
}
+ /**
+ * set the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ * @param c an array of three integers containing the RGB values to set the pixel to
+ */
public void setPixel(final int x, final int y, int[] c) {
if (this.frame == null) {
this.grid.setPixel(x, y, c);
@@ -211,6 +292,14 @@ public class RasterPlotter {
this.frame[cell++] = (byte) c[2];
}
+ /**
+ * set the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ * @param r the red value to set the pixel to
+ * @param g the green value to set the pixel to
+ * @param b the blue value to set the pixel to
+ */
public void setColor(final long c) {
if (this.defaultMode == DrawMode.MODE_SUB) {
final int r = (int) (c >> 16);
@@ -226,10 +315,21 @@ public class RasterPlotter {
}
}
+ /**
+ * set the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ */
public void plot(final int x, final int y) {
plot(x, y, 100);
}
+ /**
+ * set the RGB values of a pixel
+ * @param x the x coordinate of the pixel
+ * @param y the y coordinate of the pixel
+ * @param intensity the intensity of the color to set the pixel to (0..100)
+ */
public void plot(final int x, final int y, final int intensity) {
if ((x < 0) || (x >= this.width)) return;
if ((y < 0) || (y >= this.height)) return;
@@ -289,6 +389,15 @@ public class RasterPlotter {
} // may appear when pixel coordinate is out of bounds
}
+ /**
+ * draw a line using Bresenham's line drawing algorithm.
+ * The line will be plotted without dots on it.
+ * @param Ax
+ * @param Ay
+ * @param Bx
+ * @param By
+ * @param intensity
+ */
public void line(final int Ax, final int Ay, final int Bx, final int By, final int intensity) {
line(Ax, Ay, Bx, By, null, intensity, null, -1, -1, -1, -1, false);
}
@@ -437,6 +546,14 @@ public class RasterPlotter {
line(x3, y3, xt, yt, 100); // right line
}
+ /**
+ * draw a dot (circle) at position x,y with radius
+ * @param x x position of center
+ * @param y y position of center
+ * @param radius radius of dot
+ * @param filled if true: filled circle, else only border
+ * @param intensity the intensity of the color (0..100)
+ */
public void dot(final int x, final int y, final int radius, final boolean filled, final int intensity) {
if (filled) {
for (int r = radius; r >= 0; r--) {
@@ -447,12 +564,29 @@ public class RasterPlotter {
}
}
+ /**
+ * draw a ring (portion of a circle) at position x,y with inner and outer radius
+ * @param x x position of center
+ * @param y y position of center
+ * @param innerRadius inner radius of ring
+ * @param outerRadius outer radius of ring
+ * @param intensity the intensity of the color (0..100)
+ */
public void arc(final int x, final int y, final int innerRadius, final int outerRadius, final int intensity) {
for (int r = innerRadius; r <= outerRadius; r++) {
CircleTool.circle(this, x, y, r, intensity);
}
}
+ /**
+ * draw a portion of a ring (portion of a circle) at position x,y with inner and outer radius
+ * @param x x position of center
+ * @param y y position of center
+ * @param innerRadius inner radius of ring
+ * @param outerRadius outer radius of ring
+ * @param fromArc start angle of arc (0..360)
+ * @param toArc end angle of arc (0..360)
+ */
public void arc(final int x, final int y, final int innerRadius, final int outerRadius, final int fromArc, final int toArc) {
for (int r = innerRadius; r <= outerRadius; r++) {
CircleTool.circle(this, x, y, r, fromArc, toArc);
@@ -556,6 +690,16 @@ public class RasterPlotter {
}
}
+ /**
+ * draw an arc on a circle
+ * @param cx center of circle, x
+ * @param cy center of circle, y
+ * @param arcRadius radius of circle
+ * @param angle position of arc on circle
+ * @param innerRadius inner radius of arc
+ * @param outerRadius outer radius of arc
+ * @param intensity intensity of arc
+ */
public void arcArc(final int cx, final int cy, final int arcRadius, final double angle,
final int innerRadius, final int outerRadius, final int intensity) {
final double a = PI180 * angle;
@@ -564,6 +708,17 @@ public class RasterPlotter {
arc(x, y, innerRadius, outerRadius, intensity);
}
+ /**
+ * draw an arc on a circle
+ * @param cx center of circle, x
+ * @param cy center of circle, y
+ * @param arcRadius radius of circle
+ * @param angle position of arc on circle
+ * @param innerRadius inner radius of arc
+ * @param outerRadius outer radius of arc
+ * @param fromArc start angle of arc
+ * @param toArc end angle of arc
+ */
public void arcArc(final int cx, final int cy, final int arcRadius, final double angle,
final int innerRadius, final int outerRadius, final int fromArc, final int toArc) {
final double a = PI180 * angle;
@@ -572,6 +727,63 @@ public class RasterPlotter {
arc(x, y, innerRadius, outerRadius, fromArc, toArc);
}
+ /**
+ * fills a polygon defined by arrays of x- and y-coordinates
+ * @param xs array of x-coordinates of polygon vertices
+ * @param ys array of y-coordinates of polygon vertices
+ * @param color color of the polygon
+ * @param intensity intensity of the polygon
+ */
+ public void fillPolygon(final int[] xs, final int[] ys, final long color, final int intensity) {
+ if (xs == null || ys == null) return;
+ final int vertexCount = Math.min(xs.length, ys.length);
+ if (vertexCount < 3) return;
+
+ int minY = Integer.MAX_VALUE;
+ int maxY = Integer.MIN_VALUE;
+ for (int i = 0; i < vertexCount; i++) {
+ final int y = ys[i];
+ if (y < minY) minY = y;
+ if (y > maxY) maxY = y;
+ }
+ minY = Math.max(0, minY);
+ maxY = Math.min(getHeight() - 1, maxY);
+ if (minY >= maxY) return;
+
+ setColor(color);
+ final double[] intersections = new double[vertexCount];
+ for (int y = minY; y <= maxY; y++) {
+ int points = 0;
+ for (int i = 0; i < vertexCount; i++) {
+ final int x1 = xs[i];
+ final int y1 = ys[i];
+ final int nextIndex = (i + 1) % vertexCount;
+ final int x2 = xs[nextIndex];
+ final int y2 = ys[nextIndex];
+ if ((y1 <= y && y2 > y) || (y2 <= y && y1 > y)) {
+ final double ratio = (double) (y - y1) / (double) (y2 - y1);
+ intersections[points++] = x1 + ratio * (x2 - x1);
+ }
+ }
+ if (points < 2) continue;
+ Arrays.sort(intersections, 0, points);
+ for (int i = 0; i < points - 1; i += 2) {
+ int x0 = (int) Math.round(intersections[i]);
+ int x1 = (int) Math.round(intersections[i + 1]);
+ if (x1 < x0) {
+ final int tmp = x0;
+ x0 = x1;
+ x1 = tmp;
+ }
+ if (x0 == x1) {
+ plot(x0, y, intensity);
+ } else {
+ line(x0, y, x1, y, intensity);
+ }
+ }
+ }
+ }
+
/**
* inserts image
* @param bitmap bitmap to be inserted
diff --git a/source/net/yacy/visualization/SkylinePlotter.java b/source/net/yacy/visualization/SkylinePlotter.java
new file mode 100644
index 000000000..e7a7c7eb5
--- /dev/null
+++ b/source/net/yacy/visualization/SkylinePlotter.java
@@ -0,0 +1,814 @@
+/**
+ * SkylinePlotter
+ * Retro wireframe skyline renderer for YaCy visualizations.
+ * Copyright 2025 by Michael Peter Christen
+ * First released 20.09.2025 at https://yacy.net
+ *
+ * This file is part of YaCy.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program in the file lgpl21.txt
+ * If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package net.yacy.visualization;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+/**
+ * A painter that renders a perspective wireframe skyline on top of a classic
+ * horizon grid. Objects are placed on a two dimensional field, projected with a
+ * simple pinhole camera model and depth sorted so nearer objects cover the
+ * distant ones. The renderer focuses on the retro aesthetics of early 80s
+ * vector displays while being compatible with the existing {@link RasterPlotter}
+ * infrastructure.
+ */
+public class SkylinePlotter extends RasterPlotter {
+
+ private final SkylineConfig config;
+ private final List<SkylineObject> objects;
+ private final List<SkylineBeam> beams;
+
+ private final int centerX;
+ private final int horizonY;
+
+ /**
+ * Create a new skyline renderer with the supplied configuration.
+ *
+ * @param config the configuration (must not be {@code null})
+ */
+ public SkylinePlotter(final SkylineConfig config) {
+ super(config.width, config.height, DrawMode.MODE_REPLACE, config.backgroundColor);
+ this.config = config.copy();
+ this.objects = new ArrayList<SkylineObject>();
+ this.beams = new ArrayList<SkylineBeam>();
+ this.centerX = getWidth() / 2;
+ this.horizonY = (config.horizonY >= 0) ? config.horizonY : getHeight() / 4;
+ }
+
+ public SkylineConfig getConfig() {
+ return this.config.copy();
+ }
+
+ /**
+ * Remove all currently registered skyline objects.
+ */
+ public void clearScene() {
+ this.objects.clear();
+ this.beams.clear();
+ }
+
+ /**
+ * Types of supported 3D shapes.
+ */
+ public static enum ShapeType {
+ BOX,
+ SPHERE,
+ PYRAMID,
+ POLYLINE
+ }
+
+ /**
+ * Configuration data class. All values are in world units unless stated
+ * otherwise. Public fields are used here for simplicity; callers should
+ * populate them before passing the configuration to the constructor.
+ */
+ public static class SkylineConfig {
+ public int width;
+ public int height;
+ public long backgroundColor;
+ public long gridColor = 0x00ccccL;
+ public int gridIntensity = 35;
+ public int gridPulse = 8;
+ public double gridStepX = 30.0d;
+ public double gridStepZ = 40.0d;
+ public double gridNear = 6.0d;
+ public double fieldWidth = 400.0d;
+ public double fieldDepth = 600.0d;
+ public double focalLength = 520.0d;
+ public double cameraDepth = 160.0d;
+ public double groundLevel = 220.0d;
+ public double nearPlane = 4.0d;
+ public int horizonY = -1;
+
+ private SkylineConfig copy() {
+ final SkylineConfig clone = new SkylineConfig();
+ clone.width = this.width;
+ clone.height = this.height;
+ clone.backgroundColor = this.backgroundColor;
+ clone.gridColor = this.gridColor;
+ clone.gridIntensity = this.gridIntensity;
+ clone.gridPulse = this.gridPulse;
+ clone.gridStepX = this.gridStepX;
+ clone.gridStepZ = this.gridStepZ;
+ clone.gridNear = this.gridNear;
+ clone.fieldWidth = this.fieldWidth;
+ clone.fieldDepth = this.fieldDepth;
+ clone.focalLength = this.focalLength;
+ clone.cameraDepth = this.cameraDepth;
+ clone.groundLevel = this.groundLevel;
+ clone.nearPlane = this.nearPlane;
+ clone.horizonY = this.horizonY;
+ return clone;
+ }
+ }
+
+ /**
+ * A drawable object within the skyline scene. Instances are configured
+ * through fluently chained setters for retro convenience.
+ */
+ public static class SkylineObject {
+ private final ShapeType shape;
+ private final double centerX;
+ private final double centerZ;
+ private final double sizeX;
+ private final double sizeZ;
+ private final double baseHeight;
+ private final double objectHeight;
+ private final long color;
+
+ private Long accentColor;
+ private Long edgeColor;
+ private int intensity = 80;
+ private double bobAmplitude = 0.0d;
+ private double pulseAmplitude = 0.0d;
+ private int patternModulo = 0;
+ private double patternPhase = 0.0d;
+ private String label;
+ private int labelOffsetX = 0;
+ private int labelOffsetY = -12;
+ private int labelIntensity = 100;
+ private Long labelColor;
+ private double animationPhase = 0.0d;
+
+ public SkylineObject(final ShapeType shape,
+ final double centerX,
+ final double centerZ,
+ final double sizeX,
+ final double sizeZ,
+ final double baseHeight,
+ final double objectHeight,
+ final long color) {
+ this.shape = shape;
+ this.centerX = centerX;
+ this.centerZ = centerZ;
+ this.sizeX = sizeX;
+ this.sizeZ = sizeZ;
+ this.baseHeight = baseHeight;
+ this.objectHeight = objectHeight;
+ this.color = color;
+ }
+
+ private double sortKey() {
+ return this.centerZ + this.objectHeight;
+ }
+
+ public SkylineObject accent(final long accentColor) {
+ this.accentColor = Long.valueOf(accentColor);
+ return this;
+ }
+
+ public SkylineObject edges(final long edgeColor) {
+ this.edgeColor = Long.valueOf(edgeColor);
+ return this;
+ }
+
+ public SkylineObject intensity(final int intensity) {
+ this.intensity = intensity;
+ return this;
+ }
+
+ public SkylineObject bob(final double amplitude) {
+ this.bobAmplitude = amplitude;
+ return this;
+ }
+
+ public SkylineObject pulse(final double amplitude) {
+ this.pulseAmplitude = amplitude;
+ return this;
+ }
+
+ public SkylineObject dotted(final int modulo) {
+ this.patternModulo = Math.max(0, modulo);
+ return this;
+ }
+
+ public SkylineObject patternPhase(final double phaseDegrees) {
+ this.patternPhase = phaseDegrees;
+ return this;
+ }
+
+ public SkylineObject animationPhase(final double phaseDegrees) {
+ this.animationPhase = phaseDegrees;
+ return this;
+ }
+
+ public SkylineObject label(final String text) {
+ this.label = text;
+ return this;
+ }
+
+ public SkylineObject label(final String text, final int offsetX, final int offsetY) {
+ this.label = text;
+ this.labelOffsetX = offsetX;
+ this.labelOffsetY = offsetY;
+ return this;
+ }
+
+ public SkylineObject labelColor(final long color) {
+ this.labelColor = Long.valueOf(color);
+ return this;
+ }
+
+ public SkylineObject labelIntensity(final int intensity) {
+ this.labelIntensity = intensity;
+ return this;
+ }
+ }
+
+ /**
+ * A 2D projection of a 3D world coordinate.
+ */
+ public static final class Projection {
+ private final int x;
+ private final int y;
+ private final double depth;
+
+ public Projection(final int x, final int y, final double depth) {
+ this.x = x;
+ this.y = y;
+ this.depth = depth;
+ }
+ }
+
+ /**
+ * Definition of a connector beam between two points in world space.
+ */
+ public static final class SkylineBeam {
+ private final double startX;
+ private final double startY;
+ private final double startZ;
+ private final double endX;
+ private final double endY;
+ private final double endZ;
+ private final long color;
+ private int intensity = 80;
+ private int patternModulo = 0;
+ private double patternPhase = 0.0d;
+ private double animationPhase = 0.0d;
+ private double pulseAmplitude = 0.0d;
+
+ private SkylineBeam(
+ final double startX,
+ final double startY,
+ final double startZ,
+ final double endX,
+ final double endY,
+ final double endZ,
+ final long color
+ ) {
+ this.startX = startX;
+ this.startY = startY;
+ this.startZ = startZ;
+ this.endX = endX;
+ this.endY = endY;
+ this.endZ = endZ;
+ this.color = color;
+ }
+
+ private double sortKey() {
+ return (this.startZ + this.endZ) * 0.5d;
+ }
+
+ public SkylineBeam intensity(final int value) {
+ this.intensity = value;
+ return this;
+ }
+
+ public SkylineBeam dotted(final int modulo) {
+ this.patternModulo = Math.max(0, modulo);
+ return this;
+ }
+
+ public SkylineBeam patternPhase(final double phaseDegrees) {
+ this.patternPhase = phaseDegrees;
+ return this;
+ }
+
+ public SkylineBeam animationPhase(final double phaseDegrees) {
+ this.animationPhase = phaseDegrees;
+ return this;
+ }
+
+ public SkylineBeam pulse(final double amplitude) {
+ this.pulseAmplitude = amplitude;
+ return this;
+ }
+ }
+
+ /**
+ * Add a box shaped object to the scene.
+ *
+ * @param centerX world x coordinate of the box center
+ * @param centerZ world z coordinate (depth) of the box center
+ * @param width width along x axis
+ * @param depth depth along z axis
+ * @param base height of the box bottom above the grid
+ * @param height height of the box itself
+ * @param color primary color
+ * @return the created skyline object for further customization
+ */
+ public SkylineObject addBox(
+ final double centerX,
+ final double centerZ,
+ final double width,
+ final double depth,
+ final double base,
+ final double height,
+ final long color
+ ) {
+ final SkylineObject object = new SkylineObject(ShapeType.BOX, centerX, centerZ, width, depth, base, height, color);
+ this.objects.add(object);
+ return object;
+ }
+
+ /**
+ * Add a sphere to the scene.
+ *
+ * @param centerX world x coordinate of sphere center
+ * @param centerZ world z coordinate of sphere center
+ * @param diameter diameter of the sphere
+ * @param base height of the sphere bottom above the grid
+ * @param color primary color
+ * @return the created skyline object
+ */
+ public SkylineObject addSphere(
+ final double centerX,
+ final double centerZ,
+ final double diameter,
+ final double base,
+ final long color
+ ) {
+ final SkylineObject object = new SkylineObject(ShapeType.SPHERE, centerX, centerZ, diameter, diameter, base, diameter, color);
+ this.objects.add(object);
+ return object;
+ }
+
+ /**
+ * Add a pyramid to the scene.
+ *
+ * @param centerX world x coordinate of pyramid center
+ * @param centerZ world z coordinate of pyramid center
+ * @param width width of the pyramid base along x axis
+ * @param depth depth of the pyramid base along z axis
+ * @param base base height above the grid
+ * @param height height of the pyramid to the apex
+ * @param color primary color
+ * @return the created skyline object
+ */
+ public SkylineObject addPyramid(
+ final double centerX,
+ final double centerZ,
+ final double width,
+ final double depth,
+ final double base,
+ final double height,
+ final long color
+ ) {
+ final SkylineObject object = new SkylineObject(ShapeType.PYRAMID, centerX, centerZ, width, depth, base, height, color);
+ this.objects.add(object);
+ return object;
+ }
+
+ /**
+ * Add a light beam or connector between two points in world coordinates.
+ *
+ * @param startX x coordinate of the beam start
+ * @param startY y coordinate (height above grid) of the beam start
+ * @param startZ z coordinate (depth) of the beam start
+ * @param endX x coordinate of the beam end
+ * @param endY y coordinate (height above grid) of the beam end
+ * @param endZ z coordinate (depth) of the beam end
+ * @param color beam colour
+ * @return newly created beam for additional configuration
+ */
+ public SkylineBeam addBeam(
+ final double startX,
+ final double startY,
+ final double startZ,
+ final double endX,
+ final double endY,
+ final double endZ,
+ final long color
+ ) {
+ final SkylineBeam beam = new SkylineBeam(startX, startY, startZ, endX, endY, endZ, color);
+ this.beams.add(beam);
+ return beam;
+ }
+
+ /**
+ * Render the skyline for a specific animation frame. YaCy uses 8 phase
+ * frames (45 degrees step) for looping animations. The plotter supports that
+ * convention but any integer value is allowed.
+ *
+ * @param animationFrame index of the animation step (0..n)
+ */
+ public void renderFrame(final int animationFrame) {
+ clear();
+ final double animationAngle = (animationFrame % 8) * 45.0d;
+
+ drawHorizonGrid(animationAngle);
+
+ if (!this.objects.isEmpty()) {
+ final List<SkylineObject> sorted = new ArrayList<SkylineObject>(this.objects);
+ Collections.sort(sorted, new Comparator<SkylineObject>() {
+ @Override
+ public int compare(final SkylineObject a, final SkylineObject b) {
+ return Double.compare(b.sortKey(), a.sortKey());
+ }
+ });
+
+ for (final SkylineObject object : sorted) {
+ drawObject(object, animationAngle);
+ }
+ }
+
+ if (!this.beams.isEmpty()) {
+ final List<SkylineBeam> sortedBeams = new ArrayList<SkylineBeam>(this.beams);
+ Collections.sort(sortedBeams, new Comparator<SkylineBeam>() {
+ @Override
+ public int compare(final SkylineBeam a, final SkylineBeam b) {
+ return Double.compare(b.sortKey(), a.sortKey());
+ }
+ });
+ for (final SkylineBeam beam : sortedBeams) {
+ drawBeam(beam, animationAngle);
+ }
+ }
+ }
+
+ private void drawHorizonGrid(final double animationAngle) {
+ setColor(this.config.gridColor);
+ final int baseIntensity = clampIntensity(this.config.gridIntensity);
+ final int modulation = (int) Math.round(Math.sin(Math.toRadians(animationAngle)) * this.config.gridPulse);
+ final int intensity = clampIntensity(baseIntensity + modulation);
+
+ final double halfWidth = this.config.fieldWidth * 0.5d;
+ final double far = this.config.fieldDepth;
+ final double near = Math.max(this.config.nearPlane, this.config.gridNear);
+
+ final double scaleNear = this.config.focalLength / (near + this.config.cameraDepth);
+ final double scaleFar = this.config.focalLength / (far + this.config.cameraDepth);
+
+ final double minXNear = (0 - this.centerX) / scaleNear;
+ final double maxXNear = ((getWidth() - 1) - this.centerX) / scaleNear;
+ final double minXFar = (0 - this.centerX) / scaleFar;
+ final double maxXFar = ((getWidth() - 1) - this.centerX) / scaleFar;
+
+ final double minX = Math.min(Math.min(-halfWidth, minXNear), minXFar);
+ final double maxX = Math.max(Math.max(halfWidth, maxXNear), maxXFar);
+
+ final double startX = Math.floor(minX / this.config.gridStepX) * this.config.gridStepX;
+ final double endX = Math.ceil(maxX / this.config.gridStepX) * this.config.gridStepX;
+
+ for (double x = startX; x <= endX + 0.0001d; x += this.config.gridStepX) {
+ drawLine3D(x, 0.0d, near, x, 0.0d, far, intensity, 0, 0.0d);
+ }
+
+ for (double z = near; z <= far + 0.0001d; z += this.config.gridStepZ) {
+ drawLine3D(startX, 0.0d, z, endX, 0.0d, z, intensity, 0, 0.0d);
+ }
+ }
+
+ private void drawObject(final SkylineObject object, final double animationAngle) {
+ final double angle = (animationAngle + object.animationPhase) % 360.0d;
+ final double bobOffset = (object.bobAmplitude == 0.0d) ? 0.0d : Math.sin(Math.toRadians(angle)) * object.bobAmplitude;
+ final int baseIntensity = clampIntensity(object.intensity + (int) Math.round(Math.sin(Math.toRadians(angle)) * object.pulseAmplitude));
+ final int edgeIntensity = clampIntensity(baseIntensity + 10);
+ final int topIntensity = clampIntensity(baseIntensity + 8);
+ final int sideIntensity = clampIntensity(baseIntensity - 8);
+ final long mainColor = object.color;
+ final long edgeColor = (object.edgeColor != null) ? object.edgeColor.longValue() : lighten(mainColor, 1.4d);
+ final long highlightColor = (object.accentColor != null) ? object.accentColor.longValue() : lighten(mainColor, 1.2d);
+ final long shadowColor = darken(mainColor, 0.75d);
+
+ switch (object.shape) {
+ case BOX:
+ drawBox(object, bobOffset, mainColor, highlightColor, shadowColor, edgeColor, baseIntensity, topIntensity, sideIntensity, edgeIntensity, angle);
+ break;
+ case SPHERE:
+ drawSphere(object, bobOffset, mainColor, highlightColor, edgeColor, baseIntensity, edgeIntensity, angle);
+ break;
+ case PYRAMID:
+ drawPyramid(object, bobOffset, mainColor, highlightColor, shadowColor, edgeColor, baseIntensity, topIntensity, sideIntensity, edgeIntensity, angle);
+ break;
+ default:
+ break;
+ }
+ }
+
+ private void drawBox(
+ final SkylineObject object,
+ final double bobOffset,
+ final long mainColor,
+ final long highlightColor,
+ final long shadowColor,
+ final long edgeColor,
+ final int baseIntensity,
+ final int topIntensity,
+ final int sideIntensity,
+ final int edgeIntensity,
+ final double animationAngle
+ ) {
+ final double cx = object.centerX;
+ final double cz = object.centerZ;
+ final double base = object.baseHeight + bobOffset;
+ final double h = object.objectHeight;
+ final double halfW = object.sizeX * 0.5d;
+ final double halfD = object.sizeZ * 0.5d;
+ final double top = base + h;
+
+ final Projection topNW = project(cx - halfW, top, cz - halfD);
+ final Projection topNE = project(cx + halfW, top, cz - halfD);
+ final Projection topSE = project(cx + halfW, top, cz + halfD);
+ final Projection topSW = project(cx - halfW, top, cz + halfD);
+
+ final Projection baseNW = project(cx - halfW, base, cz - halfD);
+ final Projection baseNE = project(cx + halfW, base, cz - halfD);
+ final Projection baseSE = project(cx + halfW, base, cz + halfD);
+ final Projection baseSW = project(cx - halfW, base, cz + halfD);
+
+ fillPolygon(
+ new int[]{topNW.x, topNE.x, topSE.x, topSW.x},
+ new int[]{topNW.y, topNE.y, topSE.y, topSW.y},
+ highlightColor,
+ topIntensity);
+ fillPolygon(
+ new int[]{baseNW.x, baseNE.x, topNE.x, topNW.x},
+ new int[]{baseNW.y, baseNE.y, topNE.y, topNW.y},
+ mainColor,
+ baseIntensity);
+ fillPolygon(
+ new int[]{baseNE.x, baseSE.x, topSE.x, topNE.x},
+ new int[]{baseNE.y, baseSE.y, topSE.y, topNE.y},
+ shadowColor,
+ sideIntensity);
+
+ final Projection[] outline = new Projection[]{baseNW, baseNE, baseSE, baseSW, baseNW, topNW, topNE, topSE, topSW, topNW, topSW, baseSW};
+ setColor(edgeColor);
+ for (int i = 0; i < outline.length - 1; i++) {
+ drawLineWithPattern(object.patternModulo, object.patternPhase, outline[i], outline[i + 1], edgeIntensity, animationAngle);
+ }
+
+ drawLabel(object, topNE, animationAngle);
+ }
+
+ private void drawSphere(
+ final SkylineObject object,
+ final double bobOffset,
+ final long mainColor,
+ final long highlightColor,
+ final long edgeColor,
+ final int baseIntensity,
+ final int edgeIntensity,
+ final double animationAngle
+ ) {
+ final double radiusWorld = object.objectHeight * 0.5d;
+ final double centerY = object.baseHeight + bobOffset + radiusWorld;
+
+ final Projection center = project(object.centerX, centerY, object.centerZ);
+ final Projection radiusX = project(object.centerX + radiusWorld, centerY, object.centerZ);
+ final int radius = Math.max(1, Math.abs(radiusX.x - center.x));
+
+ setColor(mainColor);
+ dot(center.x, center.y, radius, true, baseIntensity);
+
+ final int highlightRadius = Math.max(1, radius / 2);
+ setColor(highlightColor);
+ dot(center.x - highlightRadius / 2, center.y - highlightRadius / 2, highlightRadius, true, baseIntensity);
+
+ setColor(edgeColor);
+ CircleTool.circle(this, center.x, center.y, radius, edgeIntensity);
+
+ drawLabel(object, new Projection(center.x, center.y - radius - 6, center.depth), animationAngle);
+ }
+
+ private void drawPyramid(
+ final SkylineObject object,
+ final double bobOffset,
+ final long mainColor,
+ final long highlightColor,
+ final long shadowColor,
+ final long edgeColor,
+ final int baseIntensity,
+ final int highlightIntensity,
+ final int shadowIntensity,
+ final int edgeIntensity,
+ final double animationAngle
+ ) {
+ final double cx = object.centerX;
+ final double cz = object.centerZ;
+ final double base = object.baseHeight + bobOffset;
+ final double h = object.objectHeight;
+ final double halfW = object.sizeX * 0.5d;
+ final double halfD = object.sizeZ * 0.5d;
+ final double apexY = base + h;
+
+ final Projection baseNW = project(cx - halfW, base, cz - halfD);
+ final Projection baseNE = project(cx + halfW, base, cz - halfD);
+ final Projection baseSE = project(cx + halfW, base, cz + halfD);
+ final Projection baseSW = project(cx - halfW, base, cz + halfD);
+ final Projection apex = project(cx, apexY, cz);
+
+ fillPolygon(
+ new int[]{baseNW.x, baseNE.x, apex.x},
+ new int[]{baseNW.y, baseNE.y, apex.y},
+ highlightColor,
+ highlightIntensity);
+ fillPolygon(
+ new int[]{baseNE.x, baseSE.x, apex.x},
+ new int[]{baseNE.y, baseSE.y, apex.y},
+ mainColor,
+ baseIntensity);
+ fillPolygon(
+ new int[]{baseSE.x, baseSW.x, apex.x},
+ new int[]{baseSE.y, baseSW.y, apex.y},
+ shadowColor,
+ shadowIntensity);
+
+ setColor(edgeColor);
+ final Projection[] outline = new Projection[]{baseNW, baseNE, baseSE, baseSW, baseNW, apex, baseNE, apex, baseSE, apex, baseSW};
+ for (int i = 0; i < outline.length - 1; i++) {
+ drawLineWithPattern(object.patternModulo, object.patternPhase, outline[i], outline[i + 1], edgeIntensity, animationAngle);
+ }
+
+ drawLabel(object, apex, animationAngle);
+ }
+
+ private void drawLabel(final SkylineObject object, final Projection reference, final double animationAngle) {
+ if (object.label == null || object.label.length() == 0) return;
+ final long labelColor = (object.labelColor != null) ? object.labelColor.longValue()
+ : (object.accentColor != null ? object.accentColor.longValue() : object.color);
+ setColor(labelColor);
+ final int targetX = reference.x + object.labelOffsetX;
+ final int targetY = reference.y + object.labelOffsetY;
+ PrintTool.print(this, targetX, targetY, 0, object.label, -1, clampIntensity(object.labelIntensity));
+ }
+
+ private void drawLineWithPattern(final int patternModulo, final double patternPhase, final Projection start, final Projection end, final int intensity, final double animationAngle) {
+ if (patternModulo <= 1) {
+ line(start.x, start.y, end.x, end.y, intensity);
+ return;
+ }
+ final int steps = Math.max(Math.abs(end.x - start.x), Math.abs(end.y - start.y));
+ if (steps == 0) {
+ plot(start.x, start.y, intensity);
+ return;
+ }
+ final int offset = ((int) Math.round(patternModulo * ((patternPhase + animationAngle) % 360.0d) / 360.0d)) % patternModulo;
+ for (int i = 0; i <= steps; i++) {
+ final int patternIndex = (i + offset) % patternModulo;
+ if (patternIndex < (patternModulo / 2)) {
+ final double t = i / (double) steps;
+ final int x = (int) Math.round(start.x + (end.x - start.x) * t);
+ final int y = (int) Math.round(start.y + (end.y - start.y) * t);
+ plot(x, y, intensity);
+ }
+ }
+ }
+
+ private void drawLine3D(final double x0, final double y0, final double z0, final double x1, final double y1, final double z1, final int intensity, final int patternModulo, final double patternPhase) {
+ final Projection p0 = project(x0, y0, z0);
+ final Projection p1 = project(x1, y1, z1);
+ if (patternModulo <= 1) {
+ line(p0.x, p0.y, p1.x, p1.y, intensity);
+ } else {
+ drawLineWithPattern(patternModulo, patternPhase, p0, p1, intensity, 0.0d);
+ }
+ }
+
+ private void drawBeam(final SkylineBeam beam, final double animationAngle) {
+ final double phaseAngle = (animationAngle + beam.animationPhase) % 360.0d;
+ final int beamIntensity = clampIntensity(beam.intensity + (int) Math.round(Math.sin(Math.toRadians(phaseAngle)) * beam.pulseAmplitude));
+ setColor(beam.color);
+ final Projection start = project(beam.startX, beam.startY, beam.startZ);
+ final Projection end = project(beam.endX, beam.endY, beam.endZ);
+ drawLineWithPattern(beam.patternModulo, beam.patternPhase + phaseAngle, start, end, beamIntensity, phaseAngle);
+ }
+
+ private Projection project(final double x, final double y, final double z) {
+ final double denom = Math.max(this.config.nearPlane, z + this.config.cameraDepth);
+ final double scale = this.config.focalLength / denom;
+ final int sx = this.centerX + (int) Math.round(x * scale);
+ final int sy = this.horizonY + (int) Math.round((this.config.groundLevel - y) * scale);
+ return new Projection(sx, sy, denom);
+ }
+
+ private int clampIntensity(final int value) {
+ return (value < 0) ? 0 : (value > 100) ? 100 : value;
+ }
+
+ /**
+ * Demo entry point generating eight animation frames illustrating the
+ * skyline style. Accepts an optional output directory; defaults to the
+ * current working directory.
+ */
+ public static void main(final String[] args) {
+ System.setProperty("java.awt.headless", "true");
+
+ final File targetDir = (args.length > 0) ? new File(args[0]) : new File(".");
+ if (!targetDir.exists()) {
+ if (!targetDir.mkdirs()) {
+ throw new IllegalStateException("Cannot create output directory " + targetDir.getAbsolutePath());
+ }
+ } else if (!targetDir.isDirectory()) {
+ throw new IllegalArgumentException("Output path is not a directory: " + targetDir.getAbsolutePath());
+ }
+
+ final SkylineConfig config = new SkylineConfig();
+ config.width = 640;
+ config.height = 360;
+ config.backgroundColor = 0x000011L;
+ config.gridColor = 0x00FFFFL;
+ config.gridIntensity = 36;
+ config.gridPulse = 12;
+ config.gridStepX = 26.0d;
+ config.gridStepZ = 36.0d;
+ config.fieldWidth = 420.0d;
+ config.fieldDepth = 640.0d;
+ config.focalLength = 560.0d;
+ config.cameraDepth = 140.0d;
+ config.groundLevel = 210.0d;
+ config.horizonY = 110;
+
+ final SkylinePlotter skyline = new SkylinePlotter(config);
+
+ skyline.addBox(-160, 220, 120, 110, 10, 130, 0x0077FFL)
+ .accent(0x55FFFFL)
+ .edges(0xFFFFFFL)
+ .intensity(85)
+ .bob(14.0d)
+ .pulse(14.0d)
+ .dotted(6)
+ .patternPhase(90.0d)
+ .label("DATA CORE", -40, -18);
+
+ skyline.addBox(150, 260, 90, 90, 0, 80, 0x3A00AAL)
+ .accent(0xAA66FFL)
+ .edges(0xFFD6FFL)
+ .intensity(75)
+ .bob(6.0d)
+ .pulse(10.0d)
+ .dotted(8)
+ .patternPhase(0.0d)
+ .label("NODE CLUSTER", -44, -14);
+
+ skyline.addSphere(40, 320, 120, 6, 0xFF3366L)
+ .accent(0xFF88AAL)
+ .intensity(70)
+ .bob(18.0d)
+ .pulse(16.0d)
+ .animationPhase(180.0d)
+ .label("ORBITAL CACHE", -52, -22);
+
+ skyline.addPyramid(-20, 420, 150, 150, 0, 160, 0xFFAA33L)
+ .accent(0xFFD27FL)
+ .edges(0xFFE0A0L)
+ .intensity(82)
+ .pulse(8.0d)
+ .animationPhase(45.0d)
+ .label("SIGNAL SPIRE", -48, -20);
+
+ skyline.addBox(0, 540, 420, 60, -18, 12, 0x004455L)
+ .edges(0x33AADDL)
+ .intensity(52)
+ .dotted(4)
+ .label("RUNWAY 12", -32, 18)
+ .labelIntensity(70);
+
+ for (int frame = 0; frame < 8; frame++) {
+ skyline.renderFrame(frame);
+ final File outFile = new File(targetDir, String.format("skyline_demo_%02d.png", frame));
+ try {
+ skyline.save(outFile, "png");
+ } catch (final IOException e) {
+ throw new RuntimeException("Failed to write demo frame " + outFile.getAbsolutePath(), e);
+ }
+ }
+ }
+}