             x+w/2, y-h/2, //c
             x+w/2, y+h/2  //d
         ]
+        let currentVertextBuffer = vertexBuffers[vertexBufferIndex]
         let arraySize = sizeofArray(vertexData)
-        let bufferPointer = vertexBuffer.contents() + arraySize * index
+        let bufferPointer = currentVertextBuffer.contents() + arraySize * index
         memcpy(bufferPointer, vertexData, arraySize)
-        vertexBuffer.didModifyRange(NSMakeRange(arraySize * index, sizeofArray(vertexData)))
+        currentVertextBuffer.didModifyRange(NSMakeRange(arraySize * index, sizeofArray(vertexData)))
     }
 
     func screenpos(_ p: (x: Double, y: Double)) -> (x: Float, y: Float)

    var pipelineState: MTLRenderPipelineState!
    
    var uniformsBuffer: MTLBuffer!
    var vertexBuffer: MTLBuffer!
    var textureCoordBuffer: MTLBuffer!
    var textures: [MTLTexture]!
   
    var displayLink: CVDisplayLink?

    var animation: Animation!


        let encoder = commandBuffer.makeRenderCommandEncoder(descriptor: descriptor)
        encoder.setRenderPipelineState(pipelineState)
        encoder.setVertexBuffer(vertexBuffers[vertexBufferIndex], offset: 0, at: 0)
        encoder.setVertexBuffer(textureCoordBuffer, offset: 0, at: 1)
        encoder.setVertexBuffer(uniformsBuffer, offset: 0, at: 2)
        for (index, texture) in textures.enumerated() {
