Using json data to change colour

Welcome, @fleshcircuit

Yes – every circle is drawn over the last one. You only see the final circle drawn on each frame.

You want to draw one circle per frame; you’re drawing several each frame. I don’t know what your JSON data looks like, so I’ve created some placeholder dictionary values. I’m using a modulo operation with the frameCount to pick row values:

def setup():
    frameRate(3) # slow down frame rate to see what's happening
    
    size(720,480)
    global jsondata, heart
    heart = [
      {'value': {'bpm': 0}},
      {'value': {'bpm': 100}},
      {'value': {'bpm': 200}},
    ]
    
def draw():
    background(255, 255, 255)  # clear previous frame
    heart_total = len(heart)  # total entries in heart data
    heart_row = frameCount % heart_total  # pick a row
    
    bpm = heart[heart_row]['value']['bpm']
    print(bpm)
    fill(bpm, 0, 0)
    circle(width/2, height/2, 200)

The heart_row is equal to 1 on the first frame, 2 on the second. Then it ‘wraps back around’ to 0 again for the third frame, and so on.

3 Likes