This commit is contained in:
Dan Macbook 2020-08-13 06:01:06 -04:00
parent 6c014e25b5
commit 93866dc466

View File

@ -4,12 +4,15 @@ import java.awt.Color;
import java.awt.EventQueue; import java.awt.EventQueue;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Graphics2D; import java.awt.Graphics2D;
import java.util.concurrent.locks.ReentrantLock;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JPanel; import javax.swing.JPanel;
import com.volmit.iris.noise.CNG; import com.volmit.iris.noise.CNG;
import com.volmit.iris.object.NoiseStyle; import com.volmit.iris.object.NoiseStyle;
import com.volmit.iris.util.Form;
import com.volmit.iris.util.GroupedExecutor;
import com.volmit.iris.util.M; import com.volmit.iris.util.M;
import com.volmit.iris.util.PrecisionStopwatch; import com.volmit.iris.util.PrecisionStopwatch;
import com.volmit.iris.util.RNG; import com.volmit.iris.util.RNG;
@ -19,8 +22,14 @@ public class NoiseView extends JPanel {
private static final long serialVersionUID = 2094606939770332040L; private static final long serialVersionUID = 2094606939770332040L;
RollingSequence r = new RollingSequence(60); RollingSequence r = new RollingSequence(256);
CNG cng = NoiseStyle.CELLULAR_IRIS_DOUBLE.create(new RNG(RNG.r.nextLong())).scale(0.25); CNG cng = NoiseStyle.CELLULAR_IRIS_DOUBLE.create(new RNG(RNG.r.nextLong())).scale(0.25);
GroupedExecutor gx = new GroupedExecutor(Runtime.getRuntime().availableProcessors(), Thread.MAX_PRIORITY,
"Iris Renderer");
ReentrantLock l = new ReentrantLock();
int[][] co;
int w = 0;
int h = 0;
public NoiseView() { public NoiseView() {
for (int i = 0; i < 60; i++) { for (int i = 0; i < 60; i++) {
@ -32,26 +41,26 @@ public class NoiseView extends JPanel {
public void paint(Graphics g) { public void paint(Graphics g) {
super.paint(g); super.paint(g);
PrecisionStopwatch p = PrecisionStopwatch.start(); PrecisionStopwatch p = PrecisionStopwatch.start();
int accuracy = M.clip(r.getAverage() / 32D, 1D, 128D).intValue(); int accuracy = M.clip(r.getAverage() / 13D, 1D, 128D).intValue();
int dock = 0;
if (g instanceof Graphics2D) { if (g instanceof Graphics2D) {
Graphics2D gg = (Graphics2D) g; Graphics2D gg = (Graphics2D) g;
int x = 0; // current position; x if (getParent().getWidth() != w || getParent().getHeight() != h) {
int y = 0; // current position; y w = getParent().getWidth();
int d = 0; // current direction; 0=RIGHT, 1=DOWN, 2=LEFT, 3=UP h = getParent().getHeight();
int c = 0; // counter co = null;
int s = 1; // chain size }
// starting point if (co == null) {
x = ((int) Math.floor(getParent().getWidth() / 2.0)) - 1; co = new int[getParent().getWidth()][getParent().getHeight()];
y = ((int) Math.floor(getParent().getHeight() / 2.0)) - 1; }
for (int k = 1; k <= (getParent().getWidth() - 1); k++) { for (int x = 0; x < getParent().getWidth(); x += accuracy) {
for (int j = 0; j < (k < (getParent().getHeight() - 1) ? 2 : 3); j++) { int xx = x;
for (int i = 0; i < s; i++) { gx.queue("a", () -> {
double n = cng.noise(x, Math.sin((double) M.ms() / 10000D) * 400D, y); for (int z = 0; z < getParent().getHeight(); z += accuracy) {
double n = cng.noise(xx, Math.sin((double) M.ms() / 10000D) * 400D, z);
if (n > 1 || n < 0) { if (n > 1 || n < 0) {
System.out.println("EXCEEDED " + n); System.out.println("EXCEEDED " + n);
@ -60,34 +69,25 @@ public class NoiseView extends JPanel {
Color color = Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n), Color color = Color.getHSBColor((float) (n), 1f - (float) (n * n * n * n * n * n),
1f - (float) n); 1f - (float) n);
gg.setColor(color); int rgb = color.getRGB();
gg.fillRect(x, y, accuracy, accuracy); co[xx][z] = rgb;
}
});
}
c++; gx.waitFor("a");
switch (d) { for (int x = 0; x < getParent().getWidth(); x += accuracy) {
case 0: for (int z = 0; z < getParent().getHeight(); z += accuracy) {
y = y + 1; gg.setColor(new Color(co[x][z]));
break; gg.fillRect(x, z, accuracy, accuracy);
case 1:
x = x + 1;
break;
case 2:
y = y - 1;
break;
case 3:
x = x - 1;
break;
} }
} }
d = (d + 1) % 4;
}
s = s + 1;
}
} }
p.end(); p.end();
r.put(p.getMilliseconds()); r.put(p.getMilliseconds());
System.out.println("Accuracy: " + accuracy + " MS: " + Form.duration(r.getAverage(), 2));
EventQueue.invokeLater(() -> { EventQueue.invokeLater(() -> {
repaint(); repaint();