Urgent & Probably Simple Help Needed, RE Ellipse Trails.
in
Contributed Library Questions
•
2 years ago
Hi All
I have this piece of code, ive never really used arrays before and ive been quite stuck on this, im using color tracking to move an array of ellipses around (16 of them), but it just continually draws more ellipses, if anyone can show me how to correct this so it is just an trail of 16 i would be greatly appreciative
heres the code:
- int colorX = 0; // X-coordinate of the closest in color video pixel
- int colorY = 0; // Y-coordinate of the closest in color video pixel
- int activetoggle = 0;
- import oscP5.*;
- import netP5.*;
- boolean active = false;
- OscP5 oscP5;
- NetAddress myRemoteLocation;
- import processing.video.*;
- Capture video;
- int g = 0;
- int ay = 0;
- int ax = 0;
- int[] trail_x;
- int[] trail_y;
- int tindex = 0;
- int ellipsearrayY;
- void setup(){
- size(600,600);
- background (0);
- video = new Capture(this, width, height, 30);
- smooth();
- println(Capture.list());
- /* Frame rate is 30 */
- /* The fill color is set to black (0) for the boundaries (drawn as a quad) */
- oscP5 = new OscP5(this,7474);
- myRemoteLocation = new NetAddress("127.0.0.1",7474);
- frameRate(30);
- trail_x = new int[16];
- trail_y = new int[16];
- }
- void draw(){
- if (video.available()) {
- video.read();
- video.loadPixels();
- int index = 0;
- for (int ay = 0; ay < video.height; ay++) {
- for (int ax = 0; ax < video.width; ax++) {
- // Get the color stored in the pixel
- color argb = video.pixels[index];
- int a = (argb >> 24) & 0xFF;
- int r = (argb >> 16) & 0xFF;
- int g = (argb >> 8) & 0xFF;
- int b = argb & 0xFF;
- if (g>200){
- active = true;
- colorY = ay;
- colorX = ax;
- activetoggle = 1;
- }
- index++;
- }
- }
- color activetest = video.pixels[colorY*width+colorX];
- if (((activetest >> 8) & 0xFF)<200){
- active = false;
- activetoggle = 0;
- }
- }
- if (active ==true){
- trail_x[tindex] = colorX;
- trail_y[tindex] = colorY;
- tindex++;
- if (tindex >= trail_x.length) tindex = 0;
- for (int i=0; i < trail_x.length; i++) {
- // always end with the last mouse position to avoid the "jumping"
- // effect
- int pos = (tindex+i) % trail_x.length;
- //int pos = i;
- // we can use the counter for color and size
- ellipse(trail_x[pos], trail_y[pos], 50, 50);
- int ellipsearrayY = trail_y[pos];
- }
- }
- OscMessage myMessage = new OscMessage("/test");
- myMessage.add((int)ellipsearrayY);
- myMessage.add((int)colorY);
- myMessage.add((int)activetoggle);
- myMessage.add((int)g);
- /* send the message */
- oscP5.send(myMessage, myRemoteLocation);
- }
Miles
1