Continuous Line Problem

I am creating a seismograph but the continuous line I am graphing starts to slow down as the table holding the sum of the acceleration vectors increases. How can I stop this slowing FPS?

-- Seismograph

-- Use this function to perform your initial setup
function setup()
    x = {}
    c  =-2
    setback=0
    l=0
     
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 255, 127, 255)
    l = l + 1
    -- This sets the line thickness
    strokeWidth(5)
    stroke(0, 0, 0, 255)
   
 -- Do your drawing here
    if(l%3==0)then
      e=UserAcceleration.x+UserAcceleration.y+UserAcceleration.z
 -- print(e*700)
        
        
          c = c + 1
        
        table.remove(x,0)
      x[c]=e*700+HEIGHT/2
    
    end
    
    
        for i=0,c do 
        
        if(c>120)then
            setback = setback -.02
             
            --table.remove(x,0)
            
           -- print(d)

                
        end
        line(i*9+setback,x[i-1],(i+1)*9+setback,x[i])
    end
    strokeWidth(1)
    stroke(255, 255, 255, 255)
    line(0,HEIGHT/2,WIDTH,HEIGHT/2)
  
    
     
end


draw directly onto an image.

How would I go about doing that?

I’m not sure drawing onto an image would help, it looks as though you need to remove points as they disappear off the left of the screen. I did a similar line recently to measure frame speed, see here

https://gist.github.com/dermotbalson/d9b4e35c7d6167b4980c

why not? just create 3 images and reposition and redraw them (one img is always invisible as they move along). its more efficient than collecting hundred verts…

setting the context to an image, drawing on it, closing the context, then drawing the image(s), is not necessarily faster

@austinmccoy I made some minor changes to your code.


--# Main

-- Seismograph

function setup()
    parameter.watch("#x")
    parameter.watch("1/DeltaTime")
    x = {}
    size=WIDTH-50
end

function draw()
    background(0, 255, 127, 255)
    strokeWidth(2)
    stroke(0, 0, 0, 255)
    e=UserAcceleration.x+UserAcceleration.y+UserAcceleration.z
    table.insert(x,e*700+HEIGHT/2)
    if #x>size+1 then
        count=0
        for z=#x-size,#x do
            count=count+1
            line(count,x[z-1],count+1,x[z])
        end
        table.remove(x,1)
    else
        for z=2,#x do
            line(z-1,x[z-1],z,x[z])
        end
    end   
    strokeWidth(1)
    stroke(255, 255, 255, 255)
    line(0,HEIGHT/2,WIDTH,HEIGHT/2)
end