Skip to content

Implement print function can work in draw method#76

Open
ckski wants to merge 2 commits intomainfrom
print-in-draw-method
Open

Implement print function can work in draw method#76
ckski wants to merge 2 commits intomainfrom
print-in-draw-method

Conversation

@ckski
Copy link
Contributor

@ckski ckski commented Nov 16, 2020

The print output for each frame is accumulated and drawn only once per frame overriding the output from the previous frame. If the output is identical to the previous frame then no update happens (this prevents flickering).

The print output for each frame is accumulated and drawn only once per frame overriding the output from the previous frame. If the output is identical to the previous frame then no update happens (this prevents flickering).
@AlphaRLee
Copy link
Member

I found one weird edge case - if a user defines their own variable frame_count and tries to re-assign it, then the print buffer will revert to its old behaviour. I stumbled into this because I forgot that frame_count was a private variable and I was tryign to set a value on it as a public variable.

%%ignite

# Reset frame_count to 0 when it reaches 50

frame_count = 0

def setup():
    size(300, 300)
    background("aqua")
    
def draw():
    global frame_count
    
    if frame_count > 50:
        frame_count = 50
    print(frame_count)

image

@AlphaRLee
Copy link
Member

I think the bug I found (see above) doesn't need to be fixed right now, but we still need docs on the frame_count variable before this PR can be merged in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants