function draw loop in p5js

Hi Guys,

I have a question about Javascript and function draw (). function draw () plays my animation in the loop at a very high frequency. Is it possible to make this frequency slower?

My animation changes with the help of an input number, which changes so fast! But I dont want the animation to change all the time, so my idea is:

1) I have to make the loop frequency slower so that only every fourth input number for example is considered.

Or 2) I would say that the input number is for example measured for 4 seconds and then an average number is calculated.

I hope you understand my question! I'm not so fit in the programming language yet!

Many greetings Sarah

Answers

  •     function setup() {
                         canvas = createCanvas (1000,1400);
                         canvas.position (450,0);
                         frameRate(1);
                         }
    
        function draw_js(par1, par2, par3, par4, par5) {
                         …
                         }
    

    thanks for your reply! :) I tried to use frameRate(), writing it in setup, but it didn't changed the frequency. Did I missed anything in the code?

  • edited August 2017

    Callback is named draw(), not draw_js(): L-)
    https://p5js.org/reference/#/p5/draw

    As much as possible, create a runnable sample when asking folks for help.
    Even better, host the runnable sample here: *-:)
    https://OpenProcessing.org/sketch/create

  • my code is running perfectly with draw_js! when I change the name it's not :( but probably frameRate() refers to only function draw().

    thanks for your reply! Maybe I have to change my code before I can work with frameRate...

  • edited August 2017 Answer ✓

    @SarahMarlene -- re:

    my code is running perfectly with draw_js! when I change the name it's not but probably frameRate() refers to only function draw().

    That is correct. Unless something else in your code is calling draw_js explicitly, then the code you are putting in draw_js does nothing. Only draw (not functions with the name draw in them, like myDraw, drawIt, draw_something) is the main function in Processing that is called every frame.

  • Answer ✓

    @SarahMarlene - if accurate timing is important then you need to use time-based animation - look it up ;)

    Basically store the time when your sketch starts and each frame (inside draw()) check against current time until the target is met...

Sign In or Register to comment.