xxxxxxxxxx
35
var reflist = [ // print it and have the links in console clickable
'https://discourse.processing.org/t/create-input-accept-numbers-only/9624',
'https://p5js.org/reference/#/p5/input',
'https://p5js.org/reference/#/p5/int',
'https://www.w3schools.com/jsref/jsref_isnan.asp' ]
var aint = 0;
// Open your console to see the output
function setup() {
createCanvas(500, 150);
for (var t=0; t< reflist.length;t++) print(reflist[t]);
var inp = createInput('');
inp.position(width/2, height-30);
inp.input(myInputEvent);
}
function myInputEvent() {
console.log('you are typing: ', this.value());
var test = int(this.value());
if (!isNaN(test)) {
aint = test; // overwrite if ( begin with ) "Good Int Number" only
fill(random(127, 200), random(127, 200), random(127, 200));
} else {
console.log('ERROR: not start with number');
}
}
function draw() {
background(0, 0, 80);
textSize(80);
stroke(200, 0, 0);
strokeWeight(7);
text(aint, 10, 80);
}