Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

PShape() - significant performance issues

$
0
0
I've implemented a class called drums, which receives an array of values (via OSC) from Max. The values are extracted and used to resize one of 8 corresponding ellipses a few times a second.

When drawing the shapes via the standard ellispe(x,y,x1,y1); method, frame rate performance is pretty stable and more or less acceptable (occasional spikes down, but they're not significant). When implementing the PShape() method and drawing the shapes with shape(); performance takes a massive hit. I've benchmarked the phenomenon using a 5 minute benchmark in FRAPS. The graph is attached below.

Is this a known issue with PShape() or am I implementing it wrong? The code in its entirety is below. The PShape code is commented out and the standard code is working. 

  1. public class Drums{    
  2.     int[] array = new int[8];
  3.     boolean running = false;
  4.     
  5.     PShape kick;
  6.     float kickx = 60;
  7.     float kicky = 60;
  8.     
  9.     PShape snare;
  10.     float snarex = 60;
  11.     float snarey = 60;
  12.     
  13.     PShape oHat;
  14.     float oHatx = 60;
  15.     float oHaty = 60;
  16.     
  17.     PShape cHat;
  18.     float cHatx = 60;
  19.     float cHaty = 60;
  20.     
  21.     PShape clap;
  22.     float clapx = 60;
  23.     float clapy = 60;
  24.     
  25.     PShape rim;
  26.     float rimx = 60;
  27.     float rimy = 60;
  28.     
  29.     PShape cow;
  30.     float cowx = 60;
  31.     float cowy = 60;
  32.     
  33.     PShape shake;
  34.     float shakex = 60;
  35.     float shakey = 60;
  36.      
  37.     float centerx = width/2;
  38.     float centery = height/2;
  39.     
  40.     public void run(){
  41.       if(running){
  42.         display();
  43.         shrink();
  44.       }
  45.     }

  46.     public void display(){
  47.         stroke(255);
  48.         fill(255,255,255);
  49.         
  50.         /*
  51.         kick = createShape(ELLIPSE, centerx, centery, kickx, kicky);
  52.         snare = createShape(ELLIPSE, centerx-200, centery, snarex, snarey);
  53.         oHat = createShape(ELLIPSE, centerx+200, centery, oHatx, oHaty);
  54.         cHat = createShape(ELLIPSE, centerx+200, centery, cHatx, cHaty);
  55.         clap = createShape(ELLIPSE, centerx, centery+200, clapx, clapy); 
  56.         rim = createShape(ELLIPSE, centerx+200, centery-200, rimx, rimy);
  57.         cow = createShape(ELLIPSE, centerx+200, centery+200, cowx, cowy);
  58.         shake = createShape(ELLIPSE, centerx-200, centery-200, shakex, shakey);
  59.         
  60.         shape(kick);
  61.         shape(snare);
  62.         shape(oHat);
  63.         shape(cHat);
  64.         shape(clap);
  65.         shape(rim);
  66.         shape(cow);
  67.         shape(shake);
  68.         */
  69.         ellipse(centerx, centery, kickx, kicky);
  70.         ellipse(centerx-200, centery, snarex, snarey);
  71.         ellipse(centerx+200, centery, oHatx, oHaty);
  72.         ellipse(centerx+200, centery, cHatx, cHaty);
  73.         ellipse(centerx, centery+200, clapx, clapy);
  74.         ellipse(centerx+200, centery-200, rimx, rimy);
  75.         ellipse(centerx+200, centery+200, cowx, cowy);
  76.         ellipse(centerx-200, centery-200, shakex, shakey);
  77.     }

  78.     public void shrink(){    
  79.       
  80.       if (kickx <= height/2 && kicky <= height/2 && kickx > 0 && kicky > 0){
  81.             kickx -= height/100;
  82.             kicky -= height/100;
  83.         } 
  84.         
  85.         if (snarex <= 100 && snarey <= 100 && snarex > 0 && snarey > 0){
  86.             snarex -= 2;
  87.             snarey -= 2;
  88.         }
  89.         
  90.         if (cHatx <= 100 && cHaty <= 100 && cHatx > 0 && cHaty > 0){
  91.             cHatx -= 2;
  92.             cHaty -= 2;
  93.         }
  94.         
  95.         if (oHatx <= 100 && oHaty <= 100 && oHatx > 0 && oHaty > 0){
  96.             oHatx -= 2;
  97.             oHaty -= 2;
  98.         }
  99.         
  100.         if (clapx <= 100 && clapy <= 100 && clapx > 0 && clapy > 0){
  101.             clapx -= 2;
  102.             clapy -= 2;
  103.         }
  104.         
  105.         if (rimx <= 100 && rimy <= 100 && rimx > 0 && rimy > 0){
  106.             rimx -= 2;
  107.             rimy -= 2;
  108.         }
  109.         
  110.         if (cowx <= 100 && cowy <= 100 && cowx > 0 && cowy > 0){
  111.             cowx -= 2;
  112.             cowy -= 2;
  113.         }
  114.         
  115.         if (shakex <= 100 && shakey <= 100 && shakex > 0 && shakey > 0){
  116.             shakex -= 2;
  117.             shakey -= 2;
  118.         }
  119.     }

  120.     public void running(int[] _array){
  121.        array = _array;
  122.        running = true;
  123.        
  124.        if(array[0] == 1){
  125.          kickx = height/2;
  126.          kicky = height/2;
  127.        }        
  128.        if(array[1] == 1){
  129.          snarex = 100;
  130.          snarey = 100;
  131.        }   
  132.        if(array[2] == 1){
  133.          cHatx = 100;
  134.          cHaty = 100;
  135.        }
  136.        if(array[3] == 1){
  137.          oHatx = 100;
  138.          oHaty = 100;
  139.        }
  140.        if(array[4] == 1){
  141.          clapx = 100;
  142.          clapy = 100;
  143.        }
  144.        if(array[5] == 1){
  145.          rimx = 100;
  146.          rimy = 100;
  147.        }
  148.        if(array[6] == 1){
  149.          cowx = 100;
  150.          cowy = 100;
  151.        }
  152.        if(array[7] == 1){
  153.          shakex = 100;
  154.          shakey = 100;
  155.        }
  156.     }


Viewing all articles
Browse latest Browse all 1768

Trending Articles