xxxxxxxxxx
103
let input_mode = false
let input_string = ""
let tm = null
let reading = false
let userinfo = null
let last_input_time = null
function isASCII(str) {
return /^[\x00-\x7F]*$/.test(str);
}
function you_are(){
input_string = ""
alert("you are.... " + userinfo.results[0].name.first + " " + userinfo.results[0].name.last)
}
function grab_user(seed){
console.log(seed)
let url = "https://randomuser.me/api/?seed=" + seed
$.ajax({
url: url,
dataType: 'json',
success: function(data) {
userinfo = data
you_are();
}
});
}
function setup() {
createCanvas(400, 400);
button = createButton('start');
button.position(100, 300);
button.mousePressed(input_start);
}
function keyPressed() {
if(!input_mode) return
console.log("I STRING " + input_string)
loop_grab()
background('yellow');
text(`${key} ${keyCode}`, 10, 40);
print(key, ' ', keyCode);
if(!isNaN(key)) input_string += key
return false; // prevent default
}
function loop_grab(){
if(last_input_time == null){
reading = true
tm = setTimeout(check_if_done, 250)
}
last_input_time = new Date()
}
function addMinutes(date, minutes) {
return new Date(date.getTime() + minutes*60000);
}
function check_if_done(){
let sec_ago = addMinutes(new Date(), (0.25)/(60.0))
if(sec_ago > last_input_time){
clearTimeout(tm)
tm = null
last_input_time = null
reading = false
launch()
}
}
function launch(){
console.log(input_string)
grab_user(input_string)
}
function draw(){
if(!reading) {
background("white")
return
}
fill("red")
rect(0, 0,200, 200)
}
function input_start(){
button.html("reading....")
input_mode = true
input_string = ""
}
function getAleign