* @module Environment * @submodule Environment * @for p5
(p5, fn)
| 5 | */ |
| 6 | |
| 7 | function textOutput(p5, fn){ |
| 8 | //the functions in this file support updating the text output |
| 9 | |
| 10 | //updates textOutput |
| 11 | fn._updateTextOutput = function(idT) { |
| 12 | if (this._renderer && this._renderer.isP3D) { |
| 13 | if (!this._didOutputTextWebGLMessage) { |
| 14 | this._didOutputTextWebGLMessage = true; |
| 15 | console.error('textOutput() does not yet work in WebGL mode.'); |
| 16 | } |
| 17 | return; |
| 18 | } |
| 19 | //if html structure is not there yet |
| 20 | if (!this.dummyDOM.querySelector(`#${idT}_summary`)) { |
| 21 | return; |
| 22 | } |
| 23 | let current = this._accessibleOutputs[idT]; |
| 24 | //create shape list |
| 25 | let innerList = _shapeList(idT, this.ingredients.shapes); |
| 26 | //create output summary |
| 27 | let innerSummary = _textSummary( |
| 28 | innerList.numShapes, |
| 29 | this.ingredients.colors.background, |
| 30 | this.width, |
| 31 | this.height |
| 32 | ); |
| 33 | //create shape details |
| 34 | let innerShapeDetails = _shapeDetails(idT, this.ingredients.shapes); |
| 35 | //if it is different from current summary |
| 36 | if (innerSummary !== current.summary.innerHTML) { |
| 37 | //update |
| 38 | current.summary.innerHTML = innerSummary; |
| 39 | } |
| 40 | //if it is different from current shape list |
| 41 | if (innerList.listShapes !== current.list.innerHTML) { |
| 42 | //update |
| 43 | current.list.innerHTML = innerList.listShapes; |
| 44 | } |
| 45 | //if it is different from current shape details |
| 46 | if (innerShapeDetails !== current.shapeDetails.innerHTML) { |
| 47 | //update |
| 48 | current.shapeDetails.innerHTML = innerShapeDetails; |
| 49 | } |
| 50 | this._accessibleOutputs[idT] = current; |
| 51 | }; |
| 52 | |
| 53 | //Builds textOutput summary |
| 54 | function _textSummary(numShapes, background, width, height) { |
| 55 | let text = `Your output is a, ${width} by ${height} pixels, ${background} canvas containing the following`; |
| 56 | if (numShapes === 1) { |
| 57 | text = `${text} shape:`; |
| 58 | } else { |
| 59 | text = `${text} ${numShapes} shapes:`; |
| 60 | } |
| 61 | return text; |
| 62 | } |
| 63 | |
| 64 | //Builds textOutput table with shape details |
no test coverage detected