2021-07-26 00:34:13 +00:00
|
|
|
import static javax.swing.JOptionPane.*;
|
2021-07-26 14:58:49 +00:00
|
|
|
JSONObject json;
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
float xmin = -57.0;
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
PrintWriter output, changes, hits;
|
|
|
|
|
|
|
|
String[] colors = {
|
|
|
|
"{190, 0, 255}",
|
|
|
|
"{0, 254, 255}",
|
|
|
|
"{255, 131, 0}",
|
|
|
|
"{0, 38, 255}",
|
|
|
|
"{255, 250, 1}",
|
|
|
|
"{255, 38, 0}",
|
|
|
|
"{255, 0, 139}",
|
|
|
|
"{37, 255, 1}"
|
|
|
|
};
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
float xmax = 57.0;
|
|
|
|
|
|
|
|
float ymin = -145.75;
|
|
|
|
float ymax = 145.75;
|
|
|
|
|
|
|
|
float xscale = 1080.0 / (xmax * 2.0);
|
|
|
|
float yscale = 1920.0 / (ymax * 2.0);
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
float startx = 74.2428944942589;
|
|
|
|
float starty = 995.9830098644366;
|
|
|
|
float startangle = 225;
|
|
|
|
|
|
|
|
int startframes = 1645; //30 * 7;
|
|
|
|
int endframes = 30 * 30;
|
2021-07-26 00:34:13 +00:00
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
int frames = startframes;
|
2021-07-26 00:34:13 +00:00
|
|
|
float x = 0.0;
|
|
|
|
float y = 0.0;
|
2021-07-26 14:58:49 +00:00
|
|
|
float angle = 225;
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
float lastx = 1.0;
|
|
|
|
float lasty = 1.0;
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
int searchInc = 200;
|
|
|
|
int searchHit = 1000;
|
2021-07-26 00:34:13 +00:00
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
float distance = 15.0;
|
2021-07-26 00:34:13 +00:00
|
|
|
int colorNumber = 0;
|
|
|
|
|
|
|
|
boolean changed = false;
|
|
|
|
|
|
|
|
PGraphics pg;
|
|
|
|
|
|
|
|
boolean ranOnce = false;
|
2021-07-26 14:58:49 +00:00
|
|
|
boolean searching = false;
|
|
|
|
|
|
|
|
int endD = 8;
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
void setup () {
|
2021-07-26 14:58:49 +00:00
|
|
|
json = loadJSONObject("../candidate.json");
|
2021-07-26 00:34:13 +00:00
|
|
|
size(540, 960);
|
|
|
|
pg = createGraphics(1080, 1920);
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
readJson();
|
2021-07-26 00:34:13 +00:00
|
|
|
//frameRate(30);
|
|
|
|
}
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
void readJson () {
|
|
|
|
if (json == null) return;
|
|
|
|
if (!json.isNull("startx")) {
|
|
|
|
startx = json.getFloat("startx");
|
|
|
|
println("startx = " + startx);
|
|
|
|
}
|
|
|
|
if (!json.isNull("starty")) {
|
|
|
|
starty = json.getFloat("starty");
|
|
|
|
println("starty = " + starty);
|
|
|
|
}
|
|
|
|
if (!json.isNull("startangle")) {
|
|
|
|
startangle = json.getFloat("startangle");
|
|
|
|
angle = startangle;
|
|
|
|
println("startangle = " + startangle);
|
|
|
|
}
|
|
|
|
if (!json.isNull("startframes")) {
|
|
|
|
startframes = json.getInt("startframes");
|
|
|
|
frames = startframes;
|
|
|
|
println("startframes = " + startframes);
|
|
|
|
}
|
|
|
|
if (!json.isNull("distance")) {
|
|
|
|
distance = json.getFloat("distance");
|
|
|
|
println("distance = " + distance);
|
|
|
|
}
|
|
|
|
searchHit = 10;
|
|
|
|
searchInc = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void logPath (boolean last) {
|
2021-07-26 00:34:13 +00:00
|
|
|
output.print('{');
|
|
|
|
output.print(map(x, 0.0, 1080.0, xmin, xmax));
|
|
|
|
output.print(',');
|
|
|
|
output.print(map(y, 0.0, 1920.0, ymin, ymax));
|
|
|
|
output.print('}');
|
2021-07-26 14:58:49 +00:00
|
|
|
if ( !last ) {
|
|
|
|
output.println(',');
|
|
|
|
} else {
|
|
|
|
output.println("");
|
|
|
|
}
|
2021-07-26 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
void logChange(boolean last){
|
2021-07-26 00:34:13 +00:00
|
|
|
changes.print(colorNumber);
|
2021-07-26 14:58:49 +00:00
|
|
|
if (!last) {
|
|
|
|
changes.print(',');
|
|
|
|
}
|
|
|
|
changes.println("");
|
|
|
|
}
|
|
|
|
|
|
|
|
void generateColors () {
|
|
|
|
String firstColor = colors[floor(random(0, colors.length))];
|
|
|
|
int totalColors = colorNumber + 1;
|
|
|
|
changes.println(" ");
|
|
|
|
changes.println("#declare LogoColors = array[" + totalColors + "][3]{");
|
|
|
|
changes.println(firstColor + ",");
|
|
|
|
for (int i = 1; i < totalColors - 1; i++) {
|
|
|
|
changes.println( colors[floor(random(0, colors.length))] + "," );
|
|
|
|
}
|
|
|
|
changes.println(firstColor);
|
|
|
|
changes.println("}");
|
|
|
|
}
|
|
|
|
|
|
|
|
void logHit(){
|
|
|
|
hits.print("{ \"startx\" : ");
|
|
|
|
hits.print(startx);
|
|
|
|
hits.print(", \"starty\" : ");
|
|
|
|
hits.print(starty);
|
|
|
|
hits.print(", \"startangle\" : ");
|
|
|
|
hits.print(startangle);
|
|
|
|
hits.print(", \"frames\" : ");
|
|
|
|
hits.print(frames);
|
|
|
|
hits.print(", \"searchInc\" : ");
|
|
|
|
hits.print(searchInc);
|
|
|
|
hits.print(", \"searchHit\" : ");
|
|
|
|
hits.print(searchHit);
|
|
|
|
hits.print('}');
|
|
|
|
hits.println(',');
|
2021-07-26 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void draw () {
|
|
|
|
if (!ranOnce) {
|
|
|
|
x = startx;
|
|
|
|
y = starty;
|
|
|
|
angle = startangle;
|
2021-07-26 14:58:49 +00:00
|
|
|
colorNumber = 0;
|
|
|
|
if (!searching) {
|
|
|
|
print(x);
|
|
|
|
print(", ");
|
|
|
|
print(y);
|
|
|
|
print(" - ");
|
|
|
|
println(frames);
|
|
|
|
}
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
pg.beginDraw();
|
2021-07-26 14:58:49 +00:00
|
|
|
pg.ellipseMode(CENTER);
|
2021-07-26 00:34:13 +00:00
|
|
|
pg.background(0);
|
|
|
|
pg.fill(255);
|
|
|
|
pg.stroke(255);
|
2021-07-26 14:58:49 +00:00
|
|
|
if (!searching) {
|
|
|
|
output = createWriter("path.inc");
|
|
|
|
changes = createWriter("changes.inc");
|
|
|
|
|
|
|
|
changes.println("#declare Changes = array[" + frames + "] {");
|
|
|
|
output.println("#declare Path = array[" + frames + "][2]{");
|
|
|
|
}
|
|
|
|
hits = createWriter("hits.txt");
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < frames; i++) {
|
|
|
|
changed = false;
|
|
|
|
|
|
|
|
if (i > 0) {
|
|
|
|
pg.stroke(255, 0, 0);
|
|
|
|
pg.line(lastx, lasty, x, y);
|
|
|
|
pg.stroke(255, 255, 255);
|
|
|
|
} else {
|
2021-07-26 14:58:49 +00:00
|
|
|
pg.ellipse(x, y, endD, endD);
|
2021-07-26 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
pg.ellipse(x, y, 2, 2);
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
lastx = x;
|
|
|
|
lasty = y;
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
if (!searching) logPath(i == frames - 1);
|
2021-07-26 00:34:13 +00:00
|
|
|
|
|
|
|
x = x + distance * cos((float) angle * PI / 180.0);
|
|
|
|
y = y + distance * sin((float) angle * PI / 180.0);
|
|
|
|
|
|
|
|
if (x >= 1080.0 || x <= 0.0) {
|
|
|
|
angle = 180 - angle;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (x >= 1080.0) x = 1080.0;
|
|
|
|
if (x <= 0.0) x = 0.0;
|
|
|
|
if (y >= 1920.0 || y <= 0.0) {
|
|
|
|
angle = 360 - angle;
|
|
|
|
changed = true;
|
|
|
|
}
|
|
|
|
if (y >= 1920.0) y = 1920.0;
|
|
|
|
if (y <= 0.0) y = 0.0;
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
if (!searching) logChange(i == frames - 1);
|
2021-07-26 00:34:13 +00:00
|
|
|
if (changed) {
|
|
|
|
colorNumber++;
|
|
|
|
}
|
|
|
|
}
|
2021-07-26 14:58:49 +00:00
|
|
|
pg.ellipse(x, y, endD, endD);
|
2021-07-26 00:34:13 +00:00
|
|
|
pg.endDraw();
|
|
|
|
image(pg, 0, 0, width, height);
|
|
|
|
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
if (!searching) {
|
|
|
|
changes.println("}");
|
|
|
|
output.println("}");
|
|
|
|
|
|
|
|
generateColors();
|
|
|
|
|
|
|
|
output.flush(); // Writes the remaining data to the file
|
|
|
|
output.close(); // Finishes the file
|
|
|
|
|
|
|
|
changes.flush();
|
|
|
|
changes.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!searching) ranOnce = true;
|
|
|
|
//println(x);
|
|
|
|
//println(y);
|
|
|
|
//exit();
|
2021-07-26 00:34:13 +00:00
|
|
|
}
|
|
|
|
|
2021-07-26 14:58:49 +00:00
|
|
|
if (searching) {
|
|
|
|
if (!ranOnce && angle == startangle && abs(x - startx) < searchHit && abs(y - starty ) < searchHit ) {
|
|
|
|
println(x + " vs " + startx);
|
|
|
|
println(y + " vs " + starty);
|
|
|
|
println("xdiff = " + abs(x-startx) + " ydiff = " + abs(y-starty));
|
|
|
|
println("startangle = " + startangle);
|
|
|
|
println("startframes = " + startframes);
|
|
|
|
//delay(10000);
|
|
|
|
if (searchInc > 1) {
|
|
|
|
logHit();
|
|
|
|
|
|
|
|
startx = floor(x - (searchHit * 2));
|
|
|
|
starty = floor(y - (searchHit * 2));
|
|
|
|
startframes = frames - searchHit;
|
|
|
|
|
|
|
|
if (startx < 0) startx = 0;
|
|
|
|
if (starty < 0) starty = 0;
|
|
|
|
if (startframes < 30*7) startframes = 30 * 7;
|
|
|
|
|
|
|
|
searchHit = floor(searchHit / 2.0);
|
|
|
|
searchInc = floor(searchInc / 2.0);
|
|
|
|
if (searchInc == 0) searchInc = 1;
|
|
|
|
} else {
|
|
|
|
searching = false;
|
|
|
|
hits.flush();
|
|
|
|
hits.close();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (frames >= endframes && startangle == 45) {
|
|
|
|
frames = startframes;
|
|
|
|
startx += searchInc;
|
|
|
|
if (startx >= 1080.0) {
|
|
|
|
startx = 0;
|
|
|
|
starty += searchInc;
|
|
|
|
}
|
|
|
|
if (starty >= 1920.0) {
|
|
|
|
starty = 0;
|
|
|
|
searchInc = floor(searchInc / 2.0);
|
|
|
|
if (searchInc == 0) searchInc = 1;
|
|
|
|
}
|
|
|
|
} else if (frames >= endframes) {
|
|
|
|
|
|
|
|
}
|
|
|
|
frames += searchInc < 100 ? searchInc : 100;
|
|
|
|
}
|
2021-07-26 00:34:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void keyPressed () {
|
|
|
|
if (keyCode == UP) {
|
|
|
|
starty--;
|
|
|
|
if (starty < 0) starty = 0;
|
|
|
|
ranOnce = false;
|
|
|
|
} else if (keyCode == DOWN) {
|
|
|
|
starty++;
|
|
|
|
if (starty > 1920.0) starty = 1920.0;
|
|
|
|
ranOnce = false;
|
|
|
|
} else if (keyCode == LEFT) {
|
|
|
|
startx--;
|
|
|
|
if (startx < 0) startx = 0;
|
|
|
|
ranOnce = false;
|
|
|
|
} else if (keyCode == RIGHT) {
|
|
|
|
startx++;
|
|
|
|
if (startx > 1080.0) startx = 1080.0;
|
|
|
|
ranOnce = false;
|
|
|
|
} else if (key == 'f') {
|
|
|
|
String framesStr = showInputDialog("frames?");
|
|
|
|
if (framesStr != null) {
|
|
|
|
frames = parseInt(framesStr);
|
|
|
|
ranOnce = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void mousePressed() {
|
|
|
|
startx = floor(map(mouseX, 0.0, width, 0.0, 1080.0));
|
|
|
|
starty = floor(map(mouseY, 0.0, height, 0.0, 1920.0));
|
|
|
|
ranOnce = false;
|
|
|
|
}
|