Exploding Lines
in
Programming Questions
•
2 years ago
Hello,
Total beginner here, working from Jose's video tutorials if you can't tell. I'm trying to do the following: a bunch of lines of different random colors and lengths erupting from the middle of the screen ad infinitum. I've pasted the code below which gets me lines of different lengths erupting from the middle of the screen in random directions, but I do not know how to get this process moving in time. I want lines erupting from the middle of the screen at very brief but random intervals, and I want a lot of them, but I need this to keep going. I also need these lines to "die" or do something similar once they get off screen. I do not anticipate a problem with the random stroke color.
Finally I'm doing this with Toxic Libs Vec3D class. If there is an eminently better way to do this please let me know.
Thanks,
Speank
//tab1
import toxi.geom.*;
ArrayList tomeCollection;
float speed = 15;
void setup()
{
frameRate(30);
size(1280, 720);
smooth();
//INITIALIZE
tomeCollection = new ArrayList();
for (int i = 0; i < 100; i++)
{
Vec3D angle = new Vec3D (random(-2000, 2000), random(-2000, 2000), 0);
Vec3D plop = angle.copy();
float len = random(15, 300);
Tome myTome = new Tome(angle, plop, len);
tomeCollection.add(myTome);
};
}
void draw()
{
translate(640, 360);
background(230, 89, 40);
for (int i = 0; i < 100; i++)
{
Tome mt = (Tome) tomeCollection.get(i);
mt.run();
}
}
//tab2
class Tome {
//GLOBAL VARIABLES
Vec3D vec2 = new Vec3D(0, 0, 0);
Vec3D vec1 = new Vec3D(0, 0, 0);
float k = 0.1;
float u = 0.1;
float len;
//CONSTRUCTOR
Tome(Vec3D _vec2, Vec3D _vec1, float _len) {
vec2 = _vec2;
vec1 = _vec1;
len = _len;
}
//FUNCTIONS
void run() {
trod();
display();
}
void trod() {
vec2.normalizeTo(k);
vec1.normalizeTo(u);
k += speed;
if(k > len) {
u += speed; }
}
void display() {
stroke(255);
strokeWeight(10);
line(vec1.x, vec1.y, vec2.x, vec2.y);
stroke(255, 0, 10);
stroke(0);
strokeWeight(40);
point(vec2.x, vec2.y);
}
}
Total beginner here, working from Jose's video tutorials if you can't tell. I'm trying to do the following: a bunch of lines of different random colors and lengths erupting from the middle of the screen ad infinitum. I've pasted the code below which gets me lines of different lengths erupting from the middle of the screen in random directions, but I do not know how to get this process moving in time. I want lines erupting from the middle of the screen at very brief but random intervals, and I want a lot of them, but I need this to keep going. I also need these lines to "die" or do something similar once they get off screen. I do not anticipate a problem with the random stroke color.
Finally I'm doing this with Toxic Libs Vec3D class. If there is an eminently better way to do this please let me know.
Thanks,
Speank
//tab1
import toxi.geom.*;
ArrayList tomeCollection;
float speed = 15;
void setup()
{
frameRate(30);
size(1280, 720);
smooth();
//INITIALIZE
tomeCollection = new ArrayList();
for (int i = 0; i < 100; i++)
{
Vec3D angle = new Vec3D (random(-2000, 2000), random(-2000, 2000), 0);
Vec3D plop = angle.copy();
float len = random(15, 300);
Tome myTome = new Tome(angle, plop, len);
tomeCollection.add(myTome);
};
}
void draw()
{
translate(640, 360);
background(230, 89, 40);
for (int i = 0; i < 100; i++)
{
Tome mt = (Tome) tomeCollection.get(i);
mt.run();
}
}
//tab2
class Tome {
//GLOBAL VARIABLES
Vec3D vec2 = new Vec3D(0, 0, 0);
Vec3D vec1 = new Vec3D(0, 0, 0);
float k = 0.1;
float u = 0.1;
float len;
//CONSTRUCTOR
Tome(Vec3D _vec2, Vec3D _vec1, float _len) {
vec2 = _vec2;
vec1 = _vec1;
len = _len;
}
//FUNCTIONS
void run() {
trod();
display();
}
void trod() {
vec2.normalizeTo(k);
vec1.normalizeTo(u);
k += speed;
if(k > len) {
u += speed; }
}
void display() {
stroke(255);
strokeWeight(10);
line(vec1.x, vec1.y, vec2.x, vec2.y);
stroke(255, 0, 10);
stroke(0);
strokeWeight(40);
point(vec2.x, vec2.y);
}
}
1