millis on different machines
in
Contributed Library Questions
•
2 years ago
Hi,
I've playing around with one of the Toxiclibs examples, and added some animation code.
The thing I'm really stumped about; is that on any computer other than the one it was created on, the below code acts very randomly (eg the millis conditional does not appear to be working).
It's very strange, and would welcome any insight into what's happening.. .
______________________
www.systemarray.com
I've playing around with one of the Toxiclibs examples, and added some animation code.
The thing I'm really stumped about; is that on any computer other than the one it was created on, the below code acts very randomly (eg the millis conditional does not appear to be working).
It's very strange, and would welcome any insight into what's happening.. .
- import java.util.Random;
import processing.opengl.*;
import toxi.processing.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
TriangleMesh mesh;
boolean isFilled = true;
float move = 0.1;
boolean choose;
Random choice = new Random();
Vec3D offset = new Vec3D(); // NEW
ToxiclibsSupport gfx; // See PRocessing / P5 lib docs for this. Or google :)
void setup() {
size(680, 382, P3D); // can use OPENGL here :) imported already
gfx = new ToxiclibsSupport(this);
// create a mesh from the axis-aligned bounding box (AABB)
mesh = (TriangleMesh)new AABB(new Vec3D(), 100).toMesh();
// get first face/triangle of mesh
Face f = mesh.faces.get(0);
// extrude along positive Z axis and shrink to 25% of original size
// shrinking is done by moving vertices towards centroid of the face
// before extruding
float shrink=0.25;
Vec3D centroid = new Triangle3D(f.a, f.b, f.c).computeCentroid();
Vec3D extrude = new Vec3D(0, 0, 30);
Vec3D a = f.a.interpolateTo(centroid, 1-shrink).add(extrude);
Vec3D b = f.b.interpolateTo(centroid, 1-shrink).add(extrude);
Vec3D c = f.c.interpolateTo(centroid, 1-shrink).add(extrude);
// begin by adding new side faces:
// side A
mesh.addFace(f.a, a, f.c);
mesh.addFace(a, c, f.c);
// side B
mesh.addFace(f.a, b, a);
mesh.addFace(f.a, f.b, b);
// side C
mesh.addFace(f.c, c, f.b);
mesh.addFace(c, b, f.b);
// remove original face
mesh.faces.remove(0);
// add new face as cap
mesh.addFace(a, b, c);
// update normals (for shading)
mesh.computeVertexNormals();
}
void draw() {
float m = millis();
background(255);
camera(width / 2 - mouseX, height / 2 - mouseY, 400, 0, 0, 0, 0, 1, 0);
lights();
if (!isFilled) {
noFill();
stroke(0);
gfx.mesh(mesh, true, 10);
}
else {
fill(192,192,192);
noStroke();
gfx.mesh(mesh, true, 10);
}
if (m % 1000 == 0){
choose = choice.nextBoolean();
}
if (choose){
offset.x = move;
}
else {
offset.x = -move;
// println(m);
}
if (m % 5000 == 0){
move = 0.001;
}
move += 0.002;
println(move);
Face f = mesh.faces.get(mesh.faces.size() - 1);
translateFace(f, offset);
}
void translateFace(Face f, Vec3D offset) {
f.a.addSelf(offset);
f.b.addSelf(offset);
f.c.addSelf(offset);
mesh.computeFaceNormals();
mesh.computeVertexNormals();
}
______________________
www.systemarray.com
1