xxxxxxxxxx
50
// This is a work-around code for the issue of WebBluetooth not working on Sketch mode of P5js Web Editor.
// Please set sketch id including URL.
const sketchId = 'XVHWppZaJ'
// Do NOT touch the code below.
const presentModeUrl = 'https://preview.p5js.org/tetunori/present/' + sketchId;
// Evacuate original setup function
const orgSetupFunction = setup;
// Override setup function
setup = () => {
// call original setup function;
orgSetupFunction();
// get current URL
// Please be aware that URL in the sketch mode is not expected one
// because this sketch is workikng on iframe.
// URL works correctly in case of present mode.
const url = getURL();
if( !url.includes('present') ){
// Now we are in sketch mode.
// console.log('sketch mode');
// Override mouseClicked function
mouseClicked = () => {
// Move on to the present mode
window.open( presentModeUrl );
}
// Override draw function to show some text.
draw = () => {
background(220);
textSize(20);
const textEng = "p5.toio does NOT work on current Sketch mode.\nClick HERE to move on to Present mode.\n";
const textJp = "p5.toioは現在のSketchモードでは動きません。\nここをクリックしてPresentモードへ移動してください。\n";
// Show text.
text( textEng + "\n" + textJp, 20, 80);
}
}
}