(p5, fn, lifecycles)
| 8 | // import { Vector } from '../math/p5.Vector'; |
| 9 | |
| 10 | function environment(p5, fn, lifecycles){ |
| 11 | const standardCursors = [C.ARROW, C.CROSS, C.HAND, C.MOVE, C.TEXT, C.WAIT]; |
| 12 | const isBrowser = typeof window !== 'undefined' && typeof document !== 'undefined'; |
| 13 | |
| 14 | fn._frameRate = 0; |
| 15 | fn._lastFrameTime = globalThis.performance.now(); |
| 16 | fn._targetFrameRate = 60; |
| 17 | |
| 18 | const windowPrint = isBrowser ? window.print : null; |
| 19 | let windowPrintDisabled = false; |
| 20 | |
| 21 | lifecycles.presetup = function(){ |
| 22 | const events = [ |
| 23 | 'resize' |
| 24 | ]; |
| 25 | |
| 26 | if(isBrowser){ |
| 27 | for(const event of events){ |
| 28 | window.addEventListener(event, this[`_on${event}`].bind(this), { |
| 29 | passive: false, |
| 30 | signal: this._removeSignal |
| 31 | }); |
| 32 | } |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | /** |
| 37 | * Displays text in the web browser's console. |
| 38 | * |
| 39 | * `print()` is helpful for printing values while debugging. Each call to |
| 40 | * `print()` creates a new line of text. |
| 41 | * |
| 42 | * Note: Call `print('\n')` to print a blank line. Calling `print()` without |
| 43 | * an argument opens the browser's dialog for printing documents. |
| 44 | * |
| 45 | * @method print |
| 46 | * @param {Any} contents content to print to the console. |
| 47 | * @example |
| 48 | * // META:norender |
| 49 | * function setup() { |
| 50 | * // Prints "hello, world" to the console. |
| 51 | * print('hello, world'); |
| 52 | * } |
| 53 | * |
| 54 | * @example |
| 55 | * // META:norender |
| 56 | * function setup() { |
| 57 | * let name = 'ada'; |
| 58 | * // Prints "hello, ada" to the console. |
| 59 | * print(`hello, ${name}`); |
| 60 | * } |
| 61 | */ |
| 62 | fn.print = function(...args) { |
| 63 | if (!args.length && windowPrint !== null) { |
| 64 | if (!windowPrintDisabled) { |
| 65 | windowPrint(); |
| 66 | if ( |
| 67 | window.confirm( |
no test coverage detected