array.pop / push?
in
Programming Questions
•
2 years ago
Does processing not provide a array.pop() / push() function?
i want to store values coming from the motion sensor of my phone in an array and draw a graph of points based on this array.
When the length of the array reaches a certain value (800 in my case) i want to shift all values 1 position to the left and add a new value at position 799.
A new graph should be drawn based on this.
To conclude: if the graph reaches the end of the square the graph should move to the left. For some reason this doesnt happen with my code... i'm left with some flickering stars :(
- import peasy.*;
- import shapes3d.utils.*;
- import shapes3d.animation.*;
- import shapes3d.*;
- import controlP5.*;
- import rwmidi.*;
- import processing.opengl.*;
- import oscP5.*;
- import netP5.*;
- NetAddress myRemoteLocation;
- OscP5 oscP5;
- Graph myGraph;
- //global rotation parameters
- float rx, ry, rz;
- void setup() {
- smooth();
- size(900, 500, OPENGL);
- background(0);
- lights();
- oscP5 = new OscP5(this, 12000);
- myRemoteLocation = new NetAddress("192.168.1.17", 12000);
- myGraph = new Graph(100,100,800,200,-10,10);
- }
- void draw() {
- rx = random(-10,10);
- myGraph.storePoints();
- myGraph.display();
- if (frameCount > 799){
- myGraph.movePoints();
- }
- }
- class Graph {
- //fields
- int xPos, yPos, wd, ht, rgL, rgH, c;
- PVector[] pointArray = new PVector[800];
- //constructor
- Graph(int _xPos, int _yPos, int _wd, int _ht, int _rgL, int _rgH ) { //xpos, ypos, width, height, min_point, max_point
- xPos = _xPos;
- yPos = _yPos;
- wd = _wd;
- ht = _ht;
- rgL = _rgL;
- rgH = _rgH;
- for (int i = 0; i < pointArray.length; i++) {
- pointArray[i] = new PVector();
- }
- }
- //methods
- void display () {
- for (int i = 0; i < pointArray.length; i++) {
- noFill();
- rect(xPos, yPos, wd, ht);
- stroke(255);
- point(xPos + pointArray[i].x, yPos + pointArray[i].y);
- }
- }
- void movePoints () {
- for (int i = 1; i < pointArray.length; i++) {
- pointArray[i-1] = pointArray[i];
- println("i:" + i);
- }
- }
- //get rotation value and store as y-component of vector
- void storePoints () {
- if (frameCount < 800) {
- pointArray[c].y = map(rx, -10, 10, 0, ht);
- pointArray[c].x = frameCount;
- }
- else {
- pointArray[798].y = map(rx, -10, 10, 0, ht);
- pointArray[798].x = xPos + wd;
- }
- }
- }
Thanks!
1