Last active
June 14, 2021 18:53
p5js Typewriter - uses the text() function but could easily use createElement() and html().
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = "This is a sentence!"; | |
var data2 = "This is a second sentence"; | |
function setup() { | |
createCanvas(400,400); | |
typeWriter(data, 0, 20, 30, 100); | |
typeWriter(data2, 0, 20, 50, 500); | |
} | |
function draw() { | |
} | |
function typeWriter(sentence, n, x, y, speed) { | |
if (n < (sentence.length)) { | |
text(sentence.substring(0, n+1), x, y); | |
n++; | |
setTimeout(function() { | |
typeWriter(sentence, n, x, y, speed) | |
}, speed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great thanks! that's useful!!