Poor use of PGraphics...... Atrocious CPU
in
Programming Questions
•
1 years ago
Hi All sorry about the quote marks <<<
-
- int stRad = 100;
- SoundCircle SC;
- float angle=HALF_PI + PI;
- PGraphics waveForm;
- float seg=0;
- int segalpha;
- void setup() {
- size(800, 800, P2D);
- smooth();
- frameRate(60);
- stroke(250);
- background(0);
- SC= new SoundCircle(width/2,height/2);
- imageMode(CENTER);
- waveForm = createGraphics(width,height, P2D);
- void draw() {
- SC.waveform();
- SC.display();
- }
- class SoundCircle{
- int cx;
- int cy;
- float buffCircle,buffAngle,bbuffAngle,abuffAngle,ax,ay,x,y,bx,by;
- SoundCircle(int tempx, int tempy){
- cx = tempx;
- cy = tempy;
- }
- void waveform(){
- float r = liveamp + 100.00;
- buffCircle = TWO_PI/240.0;
- buffAngle=buffCircle*frameCount;
- bbuffAngle=buffCircle*(frameCount+1);
- abuffAngle=buffCircle*(frameCount-1);
- if (buffAngle <= TWO_PI) {
- ax = cx + stRad * cos(buffAngle);
- ay = cy + stRad * sin(buffAngle);
- x = cx + r * cos(abuffAngle);
- y = cy + r * sin(abuffAngle);
- bx = cx + stRad * cos(bbuffAngle);
- by = cy + stRad * sin(bbuffAngle);
- }
- }
- void display(){
- waveForm.beginDraw();
- waveForm.stroke(250);
- waveForm.beginShape(LINES);
- waveForm.vertex(ax, ay);
- waveForm.vertex(x, y);
- waveForm.vertex(x, y);
- waveForm.vertex(bx, by);
- waveForm.endShape(CLOSE);
- waveForm.endDraw();
- imageMode(CENTER);
- translate(cx,cy);
- rotate(angle);
- image(waveForm, 0,0);
Do you know anyway to lower the CPU usage?
Many Thanks
Miles
1