about random
int(random(1, 3))
probably doesn’t do what you think it does. You can only get 1 or 2, never 3. Because random(1, 3)
gives you a number between 1 and up to 3, but not including 3.
You can replace it by int(random(1, 4))
or maybe more clear round(random(1, 3))
about angles
Angles are specified in radians. 360 degrees is about 6.28 radians (two pi). That’s one full turn.
You specified values like 300 and 100. 300 radians is almost 50 full turns And even if it’s many turns, it may actually end up pointing in the same direction as 0. See, looking towards the North is the same even if you did one full turn or 50 full turns.
Two solutions: either specify smaller values between 0 and TWO_PI, or use radians(300)
to do the conversion from degrees to radians. If you want three cameras in this shape 🟀, you could do
Rotation rot1 = new Rotation(RotationOrder.XYZ, 0, radians(0), 0);
Vector3D center1 = Vector3D.zero;
double distancee1 = 200; // from this far away
Rotation rot2 = new Rotation(RotationOrder.XYZ, 0, radians(120), 0);
Vector3D center2 = Vector3D.zero;
double distancee2 = 200; // from this far away
Rotation rot3 = new Rotation(RotationOrder.XYZ, 0, radians(240), 0);
Vector3D center3 = Vector3D.zero;
double distancee3 =200; // from this far away
so they are 120 degrees apart.
jittery camera
It’s your task to wait for 2 seconds before setting a new camera target. As it is currently, on every frame it’s deciding between 2 targets, jumping back and forth.
That’s easy to do:
long nextEvent = 0; // in milliseconds
// then inside draw
if (millis() >= nextEvent) {
// <change your camera here>
nextEvent = millis() + 2000; // schedule next event in 2 seconds
// you could even have a random duration instead of always 2 seconds :)
}
updated code
import peasy.PeasyCam;
import peasy.org.apache.commons.math.geometry.*;
import peasy.*;
PeasyCam cam;
//Initializing the cameraStates
Rotation rot1 = new Rotation(RotationOrder.XYZ, radians(30), radians(240), 0);
Vector3D center1 = Vector3D.zero;
double distancee1 = 500; // from this far away
Rotation rot2 = new Rotation(RotationOrder.XYZ, 0, radians(120), radians(30));
Vector3D center2 = Vector3D.zero;
double distancee2 = 500; // from this far away
Rotation rot3 = new Rotation(RotationOrder.XYZ, 0, 0, 0);
Vector3D center3 = Vector3D.zero;
double distancee3 =500; // from this far away
CameraState state1 = new CameraState(rot1, center1, distancee1);
CameraState state2 = new CameraState(rot2, center2, distancee2);
CameraState state3 = new CameraState(rot3, center3, distancee3);
int r ;
ArrayList<PVector> points = new ArrayList<PVector>();
float x =0.01;
float y =0;
float z =0;
float dx;
float dy;
float dz;
float a = 10;
float b = 28;
float c = 8.0/3.0;
float dt = 0.01;
float hu =0;
boolean coloreado = true;
float h;
float largoDeLineas;
boolean pointsOrLine = true;
long nextEvent = 0;
void setup() {
size (1000, 1000, P3D);
colorMode(HSB);
cam = new PeasyCam(this, width/2, height/2, 0, 400);
cam.setMinimumDistance(10);
//Posición random inicial para la camara
r= int(random(0, 3));
}
void draw() {
background(0);
pushMatrix();
//translate(width/2, height/2);
scale(6);
box(0, 0, 0);
dx = (a * (y - x))*dt;
x = x+dx;
dy = ((x *(b-z))-y)*dt;
y = y+dy;
dz = (x*y- c*z)*dt;
z = dz+z;
//Setea dibujar lineas o puntos
//true hace puntos, false hace una linea
pointsOrLine = true;
//Setea cuan largas son las lineas que se dibujan
largoDeLineas = 500;
//Indica si las lineas son monocromaticas(true) o tienen una gama de colores
//Por default esta en gama de color
//true = gama de color false = monocromatico
coloreado = true ;
if ( coloreado) {
h = 0.01;
} else {
h = 0;
}
strokeWeight(1);
noFill();
points.add(new PVector(x, y, z));
hu =0;
// El valor que se le pasa a la funcion indica cuantas lineas
//se van a dibujar
cuantosDibujo(10);
stroke(255);
//Como se mueve la camara
if (millis() >= nextEvent) {
// avanza 1 o 2 cámaras
r += int(random(1, 3));
// Si nos pasamos del máx, retrocede una "página"
if(r > 2) {
r -= 3;
}
if (r == 0) {
cam.setState(state1, 2000);
} else if (r == 1) {
cam.setState(state2, 2000);
} else if (r == 2) {
cam.setState(state3, 2000);
}
nextEvent = millis() + 2000;
println(r, cam.getState());
}
box(width);
popMatrix();
}
void dibujar(float mm) {
if (pointsOrLine == false) {
beginShape();
for (int i =0; i<points.size()-1; i++) {
PVector p = points.get(i);
stroke(hu, 255, 255);
vertex(p.x*mm, p.y, p.z);
hu+=h;
if (hu>255) {
hu = 0;
}
if (points.size()>largoDeLineas) {
points.remove(0);
}
}
endShape();
} else if (pointsOrLine == true) {
for (int i =0; i<points.size()-1; i++) {
PVector p = points.get(i);
stroke(hu, 255, 255);
point(p.x*mm, p.y, p.z);
hu+=h;
if (hu>255) {
hu = 0;
}
if (points.size()>largoDeLineas) {
points.remove(0);
}
}
}
}
void cuantosDibujo(float a) {
for (int i = 0; i <a; i++) {
dibujar(i/3);
dibujar(-i/3);
}
}