Visual glitch? (Garbage Collection)
in
Programming Questions
•
2 years ago
Hi all,
I'm finding this happens with most of my sketches.
There is a sort of "dragging" effect, every few seconds, where the points appear to skip back for a frame.
I've put together this simple sketch to demonstrate what I mean.
If my code is causing it, i'd be keen to know why, but it seems to happen more when there is less going on, like it's the opposite to slowdown. Can anyone explain it? perhaps it's just my system but I don;t think so...
Thanks in advance
Dave
int offset = 60;
int numberOfComponents = 14;
int speed = 5;
Component[] pointComponents = new Component[numberOfComponents];
int[] yValues = {
10, 20, 50, 150, 150, 30, 90, 150, 30, 70, 150, 30, 90, 90
};
void setup() {
size(800, 180);
frameRate(30);
for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i] = new Component(i*offset, yValues[i]);
}
}
void draw() {
background(0);
for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i].run();
}
}
class Component {
PImage componentGraphic;
int x, y;
String a;
Component(int offsetX_, int yPos_) {
x = offsetX_;
y = yPos_;
}
void run() {
display();
move();
cycle();
}
void display() {
stroke(255);
point(x, y);
}
void cycle() {
if (x == -60) {
x=width;
}
}
void move() {
x=x-speed;
}
void listen() {
}
}
int numberOfComponents = 14;
int speed = 5;
Component[] pointComponents = new Component[numberOfComponents];
int[] yValues = {
10, 20, 50, 150, 150, 30, 90, 150, 30, 70, 150, 30, 90, 90
};
void setup() {
size(800, 180);
frameRate(30);
for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i] = new Component(i*offset, yValues[i]);
}
}
void draw() {
background(0);
for (int i = 0; i < pointComponents.length; i++) {
pointComponents[i].run();
}
}
class Component {
PImage componentGraphic;
int x, y;
String a;
Component(int offsetX_, int yPos_) {
x = offsetX_;
y = yPos_;
}
void run() {
display();
move();
cycle();
}
void display() {
stroke(255);
point(x, y);
}
void cycle() {
if (x == -60) {
x=width;
}
}
void move() {
x=x-speed;
}
void listen() {
}
}
1