Why is this not efficient? * solved *
in
Programming Questions
•
11 months ago
Hi all,
I'm trying to get my head around this text-based programming.. why can't it be like max where everything seems to be running side-by-side and living it's own happy life ;)
anyway - i have written a small sketch, trying to learn about OOP.
Whenever you press a key, some circles appear - but on my computer, it takes around 5 - 7 seconds from keyPressed() until I see the circles, and I don't seem to understand why - can you maybe give me a pointer?
(i use the java.util* but I guess this is still the forum, since it is native in processing?)
hope you have the time :)
Lasse
code:
import java.util.*; // Import Java library
NoteCircle[] noteCircle; // declare NoteCircleArray
int patternLength = 16;
int getRingCount = 5;
int currentActiveCircles = 0;
void setup() {
size(600, 600);
smooth(); // anti-aliasing
frameRate(60);
noteCircle = new NoteCircle[patternLength]; //
}
void draw() {
background(0);
for(int i = 0; i < currentActiveCircles; i++) {
noteCircle[i].update();
noteCircle[i].display();
}
}
void keyPressed() {
noteCircle[currentActiveCircles++] = new NoteCircle(getRingCount, currentActiveCircles);
}
class NoteCircle {
color[] palette = {#666666, #607F9C, #E9CCAE, #FFFFF3, #D01312}; // USED MINARD
Integer[] strokeColor = new Integer[palette.length];
float x; // circle x-pos
float y; // circle y-pos
float d; // circle diameter
float angleStart;
float angleMid;
float angleEnd;
float speed;
int ringCount;
int currentActiveCircles;
float strokeAlpha;
// create the CONSTRUCTOR
NoteCircle(int ringCountTemp, int currentActiveCirclesTemp) {
// fill strokeColor with the index numbers of palette. Shuffle strokeColor //
//
for (int i = 0; i < strokeColor.length; i++) { //
strokeColor[i] = i; //
//
} //
//
Collections.shuffle(Arrays.asList(strokeColor)); //
//
// finish shuffling ------------------------------------------------------ //
ringCount = ringCountTemp;
speed = random(.005, .05);
x = random(100, 500);
y = random(100, 500);
angleStart = 0;
angleMid = 0;
angleEnd = PI*2;
}
void update() {
angleMid += speed; // slowly move around. angleMid is = 0, but slowly adds on by speed.
angleMid = constrain(angleMid, 0, angleEnd);
if(angleMid >= 2*PI) {
angleMid = 0;
strokeAlpha = 255; // -(angleMid*40.6); // sets the stroke alpha
}
}
void display() {
strokeWeight(20);
noFill();
for(int i = 1; i < ringCount; i++) { // create ringCount numbers of arcs
// Randomize the stroke's colors
int getPalette; // I have a randomized list of the palette.length index numbers
int getStrokeColor;
getStrokeColor = i; // instead of using the index i, I assign i the corresponding random index
getPalette = strokeColor[getStrokeColor]; // from strokeColor.
stroke(palette[getPalette], strokeAlpha); // I get the random palette, using the index from strokeColor
d = (50*i)+50;
arc(x, y, d, d, angleMid-1, angleMid);
}
}
}
1