175 lines
3.4 KiB
Plaintext
175 lines
3.4 KiB
Plaintext
import static javax.swing.JOptionPane.*;
|
|
|
|
float xmin = -57.0;
|
|
|
|
PrintWriter output, changes;
|
|
|
|
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);
|
|
|
|
float startx = 1;//566.0, 893.0
|
|
float starty = 1;
|
|
|
|
float x = 0.0;
|
|
float y = 0.0;
|
|
|
|
float lastx = 1.0;
|
|
float lasty = 1.0;
|
|
|
|
int frames = 500;
|
|
int angle = 45;
|
|
int startangle = 45;
|
|
|
|
float distance = 20.0;
|
|
int colorNumber = 0;
|
|
|
|
boolean changed = false;
|
|
|
|
PGraphics pg;
|
|
|
|
boolean ranOnce = false;
|
|
|
|
void setup () {
|
|
size(540, 960);
|
|
pg = createGraphics(1080, 1920);
|
|
|
|
|
|
//frameRate(30);
|
|
}
|
|
|
|
void logPath () {
|
|
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('}');
|
|
output.println(',');
|
|
}
|
|
|
|
void logChange(){
|
|
changes.print('{');
|
|
changes.print(colorNumber);
|
|
changes.print('}');
|
|
changes.println(',');
|
|
}
|
|
|
|
void draw () {
|
|
if (!ranOnce) {
|
|
x = startx;
|
|
y = starty;
|
|
angle = startangle;
|
|
print(x);
|
|
print(", ");
|
|
print(y);
|
|
print(" - ");
|
|
println(frames);
|
|
|
|
pg.beginDraw();
|
|
pg.background(0);
|
|
pg.fill(255);
|
|
pg.stroke(255);
|
|
//output = createWriter("log.txt");
|
|
//changes = createWriter("changes.txt");
|
|
|
|
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 {
|
|
pg.ellipse(x, y, 4, 4);
|
|
}
|
|
|
|
pg.point(x, y);
|
|
|
|
lastx = x;
|
|
lasty = y;
|
|
|
|
//logPath();
|
|
|
|
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;
|
|
|
|
//logChange();
|
|
if (changed) {
|
|
colorNumber++;
|
|
}
|
|
}
|
|
pg.ellipse(x, y, 4, 4);
|
|
pg.endDraw();
|
|
image(pg, 0, 0, width, height);
|
|
|
|
/*output.flush(); // Writes the remaining data to the file
|
|
output.close(); // Finishes the file
|
|
changes.flush();
|
|
changes.close();*/
|
|
|
|
//ranOnce = true;
|
|
}
|
|
|
|
startx++;
|
|
if (startx >= 1079.0) {
|
|
startx = 0;
|
|
starty++;
|
|
}
|
|
if (starty >= 1920.0) {
|
|
starty = 0;
|
|
frames++;
|
|
}
|
|
if (angle == startangle && abs(x - startx) < 5 && abs(y - starty ) < 5 ) {
|
|
ranOnce = true;
|
|
}
|
|
}
|
|
|
|
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;
|
|
}
|