let img; let img_size = 32; let x_pos, y_pos; let last_frame; const frame_dur = 800; const animation = [[0, 3], [1, 3]]; let frame_i; function preload() { img = loadImage("data/toto.png"); } function setup() { createCanvas(400, 400); imageMode(CENTER); x_pos = width/2; y_pos = height-4*img_size; last_frame = millis(); frame_i = 0; } function draw() { background(255); if (millis() - last_frame >= frame_dur) { frame_i += 1; last_frame = millis(); if (frame_i >= animation.length) { frame_i = 0; } } image(img, x_pos, y_pos, img_size*4, img_size*4, img_size*animation[frame_i][0], img_size*animation[frame_i][1], img_size, img_size); }