diff --git a/src/accessibility/color_namer.js b/src/accessibility/color_namer.js index 4509280e5b..bfe1c96a58 100644 --- a/src/accessibility/color_namer.js +++ b/src/accessibility/color_namer.js @@ -5,711 +5,716 @@ * @requires core */ -import p5 from '../core/main'; import color_conversion from '../color/color_conversion'; -//stores the original hsb values -let originalHSB; +function colorNamer(p5, fn){ + //stores the original hsb values + let originalHSB; -//stores values for color name exceptions -const colorExceptions = [ - { - h: 0, - s: 0, - b: 0.8275, - name: 'gray' - }, - { - h: 0, - s: 0, - b: 0.8627, - name: 'gray' - }, - { - h: 0, - s: 0, - b: 0.7529, - name: 'gray' - }, - { - h: 0.0167, - s: 0.1176, - b: 1, - name: 'light pink' - } -]; - -//stores values for color names -const colorLookUp = [ - { - h: 0, - s: 0, - b: 0, - name: 'black' - }, - { - h: 0, - s: 0, - b: 0.5, - name: 'gray' - }, - { - h: 0, - s: 0, - b: 1, - name: 'white' - }, - { - h: 0, - s: 0.5, - b: 0.5, - name: 'dark maroon' - }, - { - h: 0, - s: 0.5, - b: 1, - name: 'salmon pink' - }, - { - h: 0, - s: 1, - b: 0, - name: 'black' - }, - { - h: 0, - s: 1, - b: 0.5, - name: 'dark red' - }, - { - h: 0, - s: 1, - b: 1, - name: 'red' - }, - { - h: 5, - s: 0, - b: 1, - name: 'very light peach' - }, - { - h: 5, - s: 0.5, - b: 0.5, - name: 'brown' - }, - { - h: 5, - s: 0.5, - b: 1, - name: 'peach' - }, - { - h: 5, - s: 1, - b: 0.5, - name: 'brick red' - }, - { - h: 5, - s: 1, - b: 1, - name: 'crimson' - }, - { - h: 10, - s: 0, - b: 1, - name: 'light peach' - }, - { - h: 10, - s: 0.5, - b: 0.5, - name: 'brown' - }, - { - h: 10, - s: 0.5, - b: 1, - name: 'light orange' - }, - { - h: 10, - s: 1, - b: 0.5, - name: 'brown' - }, - { - h: 10, - s: 1, - b: 1, - name: 'orange' - }, - { - h: 15, - s: 0, - b: 1, - name: 'very light yellow' - }, - { - h: 15, - s: 0.5, - b: 0.5, - name: 'olive green' - }, - { - h: 15, - s: 0.5, - b: 1, - name: 'light yellow' - }, - { - h: 15, - s: 1, - b: 0, - name: 'dark olive green' - }, - { - h: 15, - s: 1, - b: 0.5, - name: 'olive green' - }, - { - h: 15, - s: 1, - b: 1, - name: 'yellow' - }, - { - h: 20, - s: 0, - b: 1, - name: 'very light yellow' - }, - { - h: 20, - s: 0.5, - b: 0.5, - name: 'olive green' - }, - { - h: 20, - s: 0.5, - b: 1, - name: 'light yellow green' - }, - { - h: 20, - s: 1, - b: 0, - name: 'dark olive green' - }, - { - h: 20, - s: 1, - b: 0.5, - name: 'dark yellow green' - }, - { - h: 20, - s: 1, - b: 1, - name: 'yellow green' - }, - { - h: 25, - s: 0.5, - b: 0.5, - name: 'dark yellow green' - }, - { - h: 25, - s: 0.5, - b: 1, - name: 'light green' - }, - { - h: 25, - s: 1, - b: 0.5, - name: 'dark green' - }, - { - h: 25, - s: 1, - b: 1, - name: 'green' - }, - { - h: 30, - s: 0.5, - b: 1, - name: 'light green' - }, - { - h: 30, - s: 1, - b: 0.5, - name: 'dark green' - }, - { - h: 30, - s: 1, - b: 1, - name: 'green' - }, - { - h: 35, - s: 0, - b: 0.5, - name: 'light green' - }, - { - h: 35, - s: 0, - b: 1, - name: 'very light green' - }, - { - h: 35, - s: 0.5, - b: 0.5, - name: 'dark green' - }, - { - h: 35, - s: 0.5, - b: 1, - name: 'light green' - }, - { - h: 35, - s: 1, - b: 0, - name: 'very dark green' - }, - { - h: 35, - s: 1, - b: 0.5, - name: 'dark green' - }, - { - h: 35, - s: 1, - b: 1, - name: 'green' - }, - { - h: 40, - s: 0, - b: 1, - name: 'very light green' - }, - { - h: 40, - s: 0.5, - b: 0.5, - name: 'dark green' - }, - { - h: 40, - s: 0.5, - b: 1, - name: 'light green' - }, - { - h: 40, - s: 1, - b: 0.5, - name: 'dark green' - }, - { - h: 40, - s: 1, - b: 1, - name: 'green' - }, - { - h: 45, - s: 0.5, - b: 1, - name: 'light turquoise' - }, - { - h: 45, - s: 1, - b: 0.5, - name: 'dark turquoise' - }, - { - h: 45, - s: 1, - b: 1, - name: 'turquoise' - }, - { - h: 50, - s: 0, - b: 1, - name: 'light sky blue' - }, - { - h: 50, - s: 0.5, - b: 0.5, - name: 'dark cyan' - }, - { - h: 50, - s: 0.5, - b: 1, - name: 'light cyan' - }, - { - h: 50, - s: 1, - b: 0.5, - name: 'dark cyan' - }, - { - h: 50, - s: 1, - b: 1, - name: 'cyan' - }, - { - h: 55, - s: 0, - b: 1, - name: 'light sky blue' - }, - { - h: 55, - s: 0.5, - b: 1, - name: 'light sky blue' - }, - { - h: 55, - s: 1, - b: 0.5, - name: 'dark blue' - }, - { - h: 55, - s: 1, - b: 1, - name: 'sky blue' - }, - { - h: 60, - s: 0, - b: 0.5, - name: 'gray' - }, - { - h: 60, - s: 0, - b: 1, - name: 'very light blue' - }, - { - h: 60, - s: 0.5, - b: 0.5, - name: 'blue' - }, - { - h: 60, - s: 0.5, - b: 1, - name: 'light blue' - }, - { - h: 60, - s: 1, - b: 0.5, - name: 'navy blue' - }, - { - h: 60, - s: 1, - b: 1, - name: 'blue' - }, - { - h: 65, - s: 0, - b: 1, - name: 'lavender' - }, - { - h: 65, - s: 0.5, - b: 0.5, - name: 'navy blue' - }, - { - h: 65, - s: 0.5, - b: 1, - name: 'light purple' - }, - { - h: 65, - s: 1, - b: 0.5, - name: 'dark navy blue' - }, - { - h: 65, - s: 1, - b: 1, - name: 'blue' - }, - { - h: 70, - s: 0, - b: 1, - name: 'lavender' - }, - { - h: 70, - s: 0.5, - b: 0.5, - name: 'navy blue' - }, - { - h: 70, - s: 0.5, - b: 1, - name: 'lavender blue' - }, - { - h: 70, - s: 1, - b: 0.5, - name: 'dark navy blue' - }, - { - h: 70, - s: 1, - b: 1, - name: 'blue' - }, - { - h: 75, - s: 0.5, - b: 1, - name: 'lavender' - }, - { - h: 75, - s: 1, - b: 0.5, - name: 'dark purple' - }, - { - h: 75, - s: 1, - b: 1, - name: 'purple' - }, - { - h: 80, - s: 0.5, - b: 1, - name: 'pinkish purple' - }, - { - h: 80, - s: 1, - b: 0.5, - name: 'dark purple' - }, - { - h: 80, - s: 1, - b: 1, - name: 'purple' - }, - { - h: 85, - s: 0, - b: 1, - name: 'light pink' - }, - { - h: 85, - s: 0.5, - b: 0.5, - name: 'purple' - }, - { - h: 85, - s: 0.5, - b: 1, - name: 'light fuchsia' - }, - { - h: 85, - s: 1, - b: 0.5, - name: 'dark fuchsia' - }, - { - h: 85, - s: 1, - b: 1, - name: 'fuchsia' - }, - { - h: 90, - s: 0.5, - b: 0.5, - name: 'dark fuchsia' - }, - { - h: 90, - s: 0.5, - b: 1, - name: 'hot pink' - }, - { - h: 90, - s: 1, - b: 0.5, - name: 'dark fuchsia' - }, - { - h: 90, - s: 1, - b: 1, - name: 'fuchsia' - }, - { - h: 95, - s: 0, - b: 1, - name: 'pink' - }, - { - h: 95, - s: 0.5, - b: 1, - name: 'light pink' - }, - { - h: 95, - s: 1, - b: 0.5, - name: 'dark magenta' - }, - { - h: 95, - s: 1, - b: 1, - name: 'magenta' - } -]; + //stores values for color name exceptions + const colorExceptions = [ + { + h: 0, + s: 0, + b: 0.8275, + name: 'gray' + }, + { + h: 0, + s: 0, + b: 0.8627, + name: 'gray' + }, + { + h: 0, + s: 0, + b: 0.7529, + name: 'gray' + }, + { + h: 0.0167, + s: 0.1176, + b: 1, + name: 'light pink' + } + ]; -//returns text with color name -function _calculateColor(hsb) { - let colortext; - //round hue - if (hsb[0] !== 0) { - hsb[0] = Math.round(hsb[0] * 100); - let hue = hsb[0].toString().split(''); - const last = hue.length - 1; - hue[last] = parseInt(hue[last]); - //if last digit of hue is < 2.5 make it 0 - if (hue[last] < 2.5) { - hue[last] = 0; - //if last digit of hue is >= 2.5 and less than 7.5 make it 5 - } else if (hue[last] >= 2.5 && hue[last] < 7.5) { - hue[last] = 5; + //stores values for color names + const colorLookUp = [ + { + h: 0, + s: 0, + b: 0, + name: 'black' + }, + { + h: 0, + s: 0, + b: 0.5, + name: 'gray' + }, + { + h: 0, + s: 0, + b: 1, + name: 'white' + }, + { + h: 0, + s: 0.5, + b: 0.5, + name: 'dark maroon' + }, + { + h: 0, + s: 0.5, + b: 1, + name: 'salmon pink' + }, + { + h: 0, + s: 1, + b: 0, + name: 'black' + }, + { + h: 0, + s: 1, + b: 0.5, + name: 'dark red' + }, + { + h: 0, + s: 1, + b: 1, + name: 'red' + }, + { + h: 5, + s: 0, + b: 1, + name: 'very light peach' + }, + { + h: 5, + s: 0.5, + b: 0.5, + name: 'brown' + }, + { + h: 5, + s: 0.5, + b: 1, + name: 'peach' + }, + { + h: 5, + s: 1, + b: 0.5, + name: 'brick red' + }, + { + h: 5, + s: 1, + b: 1, + name: 'crimson' + }, + { + h: 10, + s: 0, + b: 1, + name: 'light peach' + }, + { + h: 10, + s: 0.5, + b: 0.5, + name: 'brown' + }, + { + h: 10, + s: 0.5, + b: 1, + name: 'light orange' + }, + { + h: 10, + s: 1, + b: 0.5, + name: 'brown' + }, + { + h: 10, + s: 1, + b: 1, + name: 'orange' + }, + { + h: 15, + s: 0, + b: 1, + name: 'very light yellow' + }, + { + h: 15, + s: 0.5, + b: 0.5, + name: 'olive green' + }, + { + h: 15, + s: 0.5, + b: 1, + name: 'light yellow' + }, + { + h: 15, + s: 1, + b: 0, + name: 'dark olive green' + }, + { + h: 15, + s: 1, + b: 0.5, + name: 'olive green' + }, + { + h: 15, + s: 1, + b: 1, + name: 'yellow' + }, + { + h: 20, + s: 0, + b: 1, + name: 'very light yellow' + }, + { + h: 20, + s: 0.5, + b: 0.5, + name: 'olive green' + }, + { + h: 20, + s: 0.5, + b: 1, + name: 'light yellow green' + }, + { + h: 20, + s: 1, + b: 0, + name: 'dark olive green' + }, + { + h: 20, + s: 1, + b: 0.5, + name: 'dark yellow green' + }, + { + h: 20, + s: 1, + b: 1, + name: 'yellow green' + }, + { + h: 25, + s: 0.5, + b: 0.5, + name: 'dark yellow green' + }, + { + h: 25, + s: 0.5, + b: 1, + name: 'light green' + }, + { + h: 25, + s: 1, + b: 0.5, + name: 'dark green' + }, + { + h: 25, + s: 1, + b: 1, + name: 'green' + }, + { + h: 30, + s: 0.5, + b: 1, + name: 'light green' + }, + { + h: 30, + s: 1, + b: 0.5, + name: 'dark green' + }, + { + h: 30, + s: 1, + b: 1, + name: 'green' + }, + { + h: 35, + s: 0, + b: 0.5, + name: 'light green' + }, + { + h: 35, + s: 0, + b: 1, + name: 'very light green' + }, + { + h: 35, + s: 0.5, + b: 0.5, + name: 'dark green' + }, + { + h: 35, + s: 0.5, + b: 1, + name: 'light green' + }, + { + h: 35, + s: 1, + b: 0, + name: 'very dark green' + }, + { + h: 35, + s: 1, + b: 0.5, + name: 'dark green' + }, + { + h: 35, + s: 1, + b: 1, + name: 'green' + }, + { + h: 40, + s: 0, + b: 1, + name: 'very light green' + }, + { + h: 40, + s: 0.5, + b: 0.5, + name: 'dark green' + }, + { + h: 40, + s: 0.5, + b: 1, + name: 'light green' + }, + { + h: 40, + s: 1, + b: 0.5, + name: 'dark green' + }, + { + h: 40, + s: 1, + b: 1, + name: 'green' + }, + { + h: 45, + s: 0.5, + b: 1, + name: 'light turquoise' + }, + { + h: 45, + s: 1, + b: 0.5, + name: 'dark turquoise' + }, + { + h: 45, + s: 1, + b: 1, + name: 'turquoise' + }, + { + h: 50, + s: 0, + b: 1, + name: 'light sky blue' + }, + { + h: 50, + s: 0.5, + b: 0.5, + name: 'dark cyan' + }, + { + h: 50, + s: 0.5, + b: 1, + name: 'light cyan' + }, + { + h: 50, + s: 1, + b: 0.5, + name: 'dark cyan' + }, + { + h: 50, + s: 1, + b: 1, + name: 'cyan' + }, + { + h: 55, + s: 0, + b: 1, + name: 'light sky blue' + }, + { + h: 55, + s: 0.5, + b: 1, + name: 'light sky blue' + }, + { + h: 55, + s: 1, + b: 0.5, + name: 'dark blue' + }, + { + h: 55, + s: 1, + b: 1, + name: 'sky blue' + }, + { + h: 60, + s: 0, + b: 0.5, + name: 'gray' + }, + { + h: 60, + s: 0, + b: 1, + name: 'very light blue' + }, + { + h: 60, + s: 0.5, + b: 0.5, + name: 'blue' + }, + { + h: 60, + s: 0.5, + b: 1, + name: 'light blue' + }, + { + h: 60, + s: 1, + b: 0.5, + name: 'navy blue' + }, + { + h: 60, + s: 1, + b: 1, + name: 'blue' + }, + { + h: 65, + s: 0, + b: 1, + name: 'lavender' + }, + { + h: 65, + s: 0.5, + b: 0.5, + name: 'navy blue' + }, + { + h: 65, + s: 0.5, + b: 1, + name: 'light purple' + }, + { + h: 65, + s: 1, + b: 0.5, + name: 'dark navy blue' + }, + { + h: 65, + s: 1, + b: 1, + name: 'blue' + }, + { + h: 70, + s: 0, + b: 1, + name: 'lavender' + }, + { + h: 70, + s: 0.5, + b: 0.5, + name: 'navy blue' + }, + { + h: 70, + s: 0.5, + b: 1, + name: 'lavender blue' + }, + { + h: 70, + s: 1, + b: 0.5, + name: 'dark navy blue' + }, + { + h: 70, + s: 1, + b: 1, + name: 'blue' + }, + { + h: 75, + s: 0.5, + b: 1, + name: 'lavender' + }, + { + h: 75, + s: 1, + b: 0.5, + name: 'dark purple' + }, + { + h: 75, + s: 1, + b: 1, + name: 'purple' + }, + { + h: 80, + s: 0.5, + b: 1, + name: 'pinkish purple' + }, + { + h: 80, + s: 1, + b: 0.5, + name: 'dark purple' + }, + { + h: 80, + s: 1, + b: 1, + name: 'purple' + }, + { + h: 85, + s: 0, + b: 1, + name: 'light pink' + }, + { + h: 85, + s: 0.5, + b: 0.5, + name: 'purple' + }, + { + h: 85, + s: 0.5, + b: 1, + name: 'light fuchsia' + }, + { + h: 85, + s: 1, + b: 0.5, + name: 'dark fuchsia' + }, + { + h: 85, + s: 1, + b: 1, + name: 'fuchsia' + }, + { + h: 90, + s: 0.5, + b: 0.5, + name: 'dark fuchsia' + }, + { + h: 90, + s: 0.5, + b: 1, + name: 'hot pink' + }, + { + h: 90, + s: 1, + b: 0.5, + name: 'dark fuchsia' + }, + { + h: 90, + s: 1, + b: 1, + name: 'fuchsia' + }, + { + h: 95, + s: 0, + b: 1, + name: 'pink' + }, + { + h: 95, + s: 0.5, + b: 1, + name: 'light pink' + }, + { + h: 95, + s: 1, + b: 0.5, + name: 'dark magenta' + }, + { + h: 95, + s: 1, + b: 1, + name: 'magenta' } - //if hue only has two digits - if (hue.length === 2) { - hue[0] = parseInt(hue[0]); - //if last is greater than 7.5 - if (hue[last] >= 7.5) { - //add one to the tens + ]; + + //returns text with color name + function _calculateColor(hsb) { + let colortext; + //round hue + if (hsb[0] !== 0) { + hsb[0] = Math.round(hsb[0] * 100); + let hue = hsb[0].toString().split(''); + const last = hue.length - 1; + hue[last] = parseInt(hue[last]); + //if last digit of hue is < 2.5 make it 0 + if (hue[last] < 2.5) { hue[last] = 0; - hue[0] = hue[0] + 1; + //if last digit of hue is >= 2.5 and less than 7.5 make it 5 + } else if (hue[last] >= 2.5 && hue[last] < 7.5) { + hue[last] = 5; } - hsb[0] = hue[0] * 10 + hue[1]; - } else { - if (hue[last] >= 7.5) { - hsb[0] = 10; + //if hue only has two digits + if (hue.length === 2) { + hue[0] = parseInt(hue[0]); + //if last is greater than 7.5 + if (hue[last] >= 7.5) { + //add one to the tens + hue[last] = 0; + hue[0] = hue[0] + 1; + } + hsb[0] = hue[0] * 10 + hue[1]; } else { - hsb[0] = hue[last]; + if (hue[last] >= 7.5) { + hsb[0] = 10; + } else { + hsb[0] = hue[last]; + } } } - } - //map brightness from 0 to 1 - hsb[2] = hsb[2] / 255; - //round saturation and brightness - for (let i = hsb.length - 1; i >= 1; i--) { - if (hsb[i] <= 0.25) { - hsb[i] = 0; - } else if (hsb[i] > 0.25 && hsb[i] < 0.75) { - hsb[i] = 0.5; - } else { - hsb[i] = 1; - } - } - //after rounding, if the values are hue 0, saturation 0 and brightness 1 - //look at color exceptions which includes several tones from white to gray - if (hsb[0] === 0 && hsb[1] === 0 && hsb[2] === 1) { - //round original hsb values - for (let i = 2; i >= 0; i--) { - originalHSB[i] = Math.round(originalHSB[i] * 10000) / 10000; - } - //compare with the values in the colorExceptions array - for (let e = 0; e < colorExceptions.length; e++) { - if ( - colorExceptions[e].h === originalHSB[0] && - colorExceptions[e].s === originalHSB[1] && - colorExceptions[e].b === originalHSB[2] - ) { - colortext = colorExceptions[e].name; - break; + //map brightness from 0 to 1 + hsb[2] = hsb[2] / 255; + //round saturation and brightness + for (let i = hsb.length - 1; i >= 1; i--) { + if (hsb[i] <= 0.25) { + hsb[i] = 0; + } else if (hsb[i] > 0.25 && hsb[i] < 0.75) { + hsb[i] = 0.5; } else { - //if there is no match return white - colortext = 'white'; + hsb[i] = 1; } } - } else { - //otherwise, compare with values in colorLookUp - for (let i = 0; i < colorLookUp.length; i++) { - if ( - colorLookUp[i].h === hsb[0] && - colorLookUp[i].s === hsb[1] && - colorLookUp[i].b === hsb[2] - ) { - colortext = colorLookUp[i].name; - break; + //after rounding, if the values are hue 0, saturation 0 and brightness 1 + //look at color exceptions which includes several tones from white to gray + if (hsb[0] === 0 && hsb[1] === 0 && hsb[2] === 1) { + //round original hsb values + for (let i = 2; i >= 0; i--) { + originalHSB[i] = Math.round(originalHSB[i] * 10000) / 10000; + } + //compare with the values in the colorExceptions array + for (let e = 0; e < colorExceptions.length; e++) { + if ( + colorExceptions[e].h === originalHSB[0] && + colorExceptions[e].s === originalHSB[1] && + colorExceptions[e].b === originalHSB[2] + ) { + colortext = colorExceptions[e].name; + break; + } else { + //if there is no match return white + colortext = 'white'; + } + } + } else { + //otherwise, compare with values in colorLookUp + for (let i = 0; i < colorLookUp.length; i++) { + if ( + colorLookUp[i].h === hsb[0] && + colorLookUp[i].s === hsb[1] && + colorLookUp[i].b === hsb[2] + ) { + colortext = colorLookUp[i].name; + break; + } } } + return colortext; } - return colortext; + + //gets rgba and returs a color name + fn._rgbColorName = function(arg) { + //conversts rgba to hsb + let hsb = color_conversion._rgbaToHSBA(arg); + //stores hsb in global variable + originalHSB = hsb; + //calculate color name + return _calculateColor([hsb[0], hsb[1], hsb[2]]); + }; } -//gets rgba and returs a color name -p5.prototype._rgbColorName = function(arg) { - //conversts rgba to hsb - let hsb = color_conversion._rgbaToHSBA(arg); - //stores hsb in global variable - originalHSB = hsb; - //calculate color name - return _calculateColor([hsb[0], hsb[1], hsb[2]]); -}; +export default colorNamer; -export default p5; +if(typeof p5 !== 'undefined'){ + colorNamer(p5, p5.prototype); +} diff --git a/src/accessibility/describe.js b/src/accessibility/describe.js index 8037a0f39d..5173a101de 100644 --- a/src/accessibility/describe.js +++ b/src/accessibility/describe.js @@ -5,497 +5,502 @@ * @requires core */ -import p5 from '../core/main'; -const descContainer = '_Description'; //Fallback container -const fallbackDescId = '_fallbackDesc'; //Fallback description -const fallbackTableId = '_fallbackTable'; //Fallback Table -const fallbackTableElId = '_fte_'; //Fallback Table Element -const labelContainer = '_Label'; //Label container -const labelDescId = '_labelDesc'; //Label description -const labelTableId = '_labelTable'; //Label Table -const labelTableElId = '_lte_'; //Label Table Element +function describe(p5, fn){ + const descContainer = '_Description'; //Fallback container + const fallbackDescId = '_fallbackDesc'; //Fallback description + const fallbackTableId = '_fallbackTable'; //Fallback Table + const fallbackTableElId = '_fte_'; //Fallback Table Element + const labelContainer = '_Label'; //Label container + const labelDescId = '_labelDesc'; //Label description + const labelTableId = '_labelTable'; //Label Table + const labelTableElId = '_lte_'; //Label Table Element -/** - * Creates a screen reader-accessible description of the canvas. - * - * The first parameter, `text`, is the description of the canvas. - * - * The second parameter, `display`, is optional. It determines how the - * description is displayed. If `LABEL` is passed, as in - * `describe('A description.', LABEL)`, the description will be visible in - * a div element next to the canvas. If `FALLBACK` is passed, as in - * `describe('A description.', FALLBACK)`, the description will only be - * visible to screen readers. This is the default mode. - * - * Read - * Writing accessible canvas descriptions - * to learn more about making sketches accessible. - * - * @method describe - * @param {String} text description of the canvas. - * @param {(FALLBACK|LABEL)} [display] either LABEL or FALLBACK. - * - * @example - *
- * function setup() {
- * background('pink');
- *
- * // Draw a heart.
- * fill('red');
- * noStroke();
- * circle(67, 67, 20);
- * circle(83, 67, 20);
- * triangle(91, 73, 75, 95, 59, 73);
- *
- * // Add a general description of the canvas.
- * describe('A pink square with a red heart in the bottom-right corner.');
- * }
- *
- *
- * function setup() {
- * background('pink');
- *
- * // Draw a heart.
- * fill('red');
- * noStroke();
- * circle(67, 67, 20);
- * circle(83, 67, 20);
- * triangle(91, 73, 75, 95, 59, 73);
- *
- * // Add a general description of the canvas
- * // and display it for debugging.
- * describe('A pink square with a red heart in the bottom-right corner.', LABEL);
- * }
- *
- *
- * function draw() {
- * background(200);
- *
- * // The expression
- * // frameCount % 100
- * // causes x to increase from 0
- * // to 99, then restart from 0.
- * let x = frameCount % 100;
- *
- * // Draw the circle.
- * fill(0, 255, 0);
- * circle(x, 50, 40);
- *
- * // Add a general description of the canvas.
- * describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`);
- * }
- *
- *
- * function draw() {
- * background(200);
- *
- * // The expression
- * // frameCount % 100
- * // causes x to increase from 0
- * // to 99, then restart from 0.
- * let x = frameCount % 100;
- *
- * // Draw the circle.
- * fill(0, 255, 0);
- * circle(x, 50, 40);
- *
- * // Add a general description of the canvas
- * // and display it for debugging.
- * describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`, LABEL);
- * }
- *
- *
+ * function setup() {
+ * background('pink');
+ *
+ * // Draw a heart.
+ * fill('red');
+ * noStroke();
+ * circle(67, 67, 20);
+ * circle(83, 67, 20);
+ * triangle(91, 73, 75, 95, 59, 73);
+ *
+ * // Add a general description of the canvas.
+ * describe('A pink square with a red heart in the bottom-right corner.');
+ * }
+ *
+ *
+ * function setup() {
+ * background('pink');
+ *
+ * // Draw a heart.
+ * fill('red');
+ * noStroke();
+ * circle(67, 67, 20);
+ * circle(83, 67, 20);
+ * triangle(91, 73, 75, 95, 59, 73);
+ *
+ * // Add a general description of the canvas
+ * // and display it for debugging.
+ * describe('A pink square with a red heart in the bottom-right corner.', LABEL);
+ * }
+ *
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // The expression
+ * // frameCount % 100
+ * // causes x to increase from 0
+ * // to 99, then restart from 0.
+ * let x = frameCount % 100;
+ *
+ * // Draw the circle.
+ * fill(0, 255, 0);
+ * circle(x, 50, 40);
+ *
+ * // Add a general description of the canvas.
+ * describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`);
+ * }
+ *
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // The expression
+ * // frameCount % 100
+ * // causes x to increase from 0
+ * // to 99, then restart from 0.
+ * let x = frameCount % 100;
+ *
+ * // Draw the circle.
+ * fill(0, 255, 0);
+ * circle(x, 50, 40);
+ *
+ * // Add a general description of the canvas
+ * // and display it for debugging.
+ * describe(`A green circle at (${x}, 50) moves from left to right on a gray square.`, LABEL);
+ * }
+ *
+ *
- * function setup() {
- * background('pink');
- *
- * // Describe the first element
- * // and draw it.
- * describeElement('Circle', 'A yellow circle in the top-left corner.');
- * noStroke();
- * fill('yellow');
- * circle(25, 25, 40);
- *
- * // Describe the second element
- * // and draw it.
- * describeElement('Heart', 'A red heart in the bottom-right corner.');
- * fill('red');
- * circle(66.6, 66.6, 20);
- * circle(83.2, 66.6, 20);
- * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
- *
- * // Add a general description of the canvas.
- * describe('A red heart and yellow circle over a pink background.');
- * }
- *
- *
- * function setup() {
- * background('pink');
- *
- * // Describe the first element
- * // and draw it. Display the
- * // description for debugging.
- * describeElement('Circle', 'A yellow circle in the top-left corner.', LABEL);
- * noStroke();
- * fill('yellow');
- * circle(25, 25, 40);
- *
- * // Describe the second element
- * // and draw it. Display the
- * // description for debugging.
- * describeElement('Heart', 'A red heart in the bottom-right corner.', LABEL);
- * fill('red');
- * circle(66.6, 66.6, 20);
- * circle(83.2, 66.6, 20);
- * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
- *
- * // Add a general description of the canvas.
- * describe('A red heart and yellow circle over a pink background.');
- * }
- *
- *
+ * function setup() {
+ * background('pink');
+ *
+ * // Describe the first element
+ * // and draw it.
+ * describeElement('Circle', 'A yellow circle in the top-left corner.');
+ * noStroke();
+ * fill('yellow');
+ * circle(25, 25, 40);
+ *
+ * // Describe the second element
+ * // and draw it.
+ * describeElement('Heart', 'A red heart in the bottom-right corner.');
+ * fill('red');
+ * circle(66.6, 66.6, 20);
+ * circle(83.2, 66.6, 20);
+ * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red heart and yellow circle over a pink background.');
+ * }
+ *
+ *
+ * function setup() {
+ * background('pink');
+ *
+ * // Describe the first element
+ * // and draw it. Display the
+ * // description for debugging.
+ * describeElement('Circle', 'A yellow circle in the top-left corner.', LABEL);
+ * noStroke();
+ * fill('yellow');
+ * circle(25, 25, 40);
+ *
+ * // Describe the second element
+ * // and draw it. Display the
+ * // description for debugging.
+ * describeElement('Heart', 'A red heart in the bottom-right corner.', LABEL);
+ * fill('red');
+ * circle(66.6, 66.6, 20);
+ * circle(83.2, 66.6, 20);
+ * triangle(91.2, 72.6, 75, 95, 58.6, 72.6);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red heart and yellow circle over a pink background.');
+ * }
+ *
+ * for fallback description - this.dummyDOM.querySelector(`#${cnvId}`).innerHTML = html; + //creates HTML structure for canvas descriptions + fn._describeHTML = function(type, text) { + const cnvId = this.canvas.id; + if (type === 'fallback') { + //if there is no description container + if (!this.dummyDOM.querySelector(`#${cnvId + descContainer}`)) { + //if there are no accessible outputs (see textOutput() and gridOutput()) + let html = `
for fallback description + this.dummyDOM.querySelector(`#${cnvId}`).innerHTML = html; + } else { + //create description container +
for fallback description before outputs + this.dummyDOM + .querySelector(`#${cnvId}accessibleOutput`) + .insertAdjacentHTML('beforebegin', html); + } } else { - //create description container +
for fallback description before outputs + //if describeElement() has already created the container and added a table of elements + //create fallback description
before the table this.dummyDOM - .querySelector(`#${cnvId}accessibleOutput`) - .insertAdjacentHTML('beforebegin', html); + .querySelector('#' + cnvId + fallbackTableId) + .insertAdjacentHTML( + 'beforebegin', + `
` + ); } - } else { - //if describeElement() has already created the container and added a table of elements - //create fallback descriptionbefore the table - this.dummyDOM - .querySelector('#' + cnvId + fallbackTableId) - .insertAdjacentHTML( - 'beforebegin', - `
` - ); - } - //if the container for the description exists - this.descriptions.fallback = this.dummyDOM.querySelector( - `#${cnvId}${fallbackDescId}` - ); - this.descriptions.fallback.innerHTML = text; - return; - } else if (type === 'label') { - //if there is no label container - if (!this.dummyDOM.querySelector(`#${cnvId + labelContainer}`)) { - let html = `for label description - this.dummyDOM - .querySelector('#' + cnvId) - .insertAdjacentHTML('afterend', html); - } else { - //create label container +
for label description before outputs + //if the container for the description exists + this.descriptions.fallback = this.dummyDOM.querySelector( + `#${cnvId}${fallbackDescId}` + ); + this.descriptions.fallback.innerHTML = text; + return; + } else if (type === 'label') { + //if there is no label container + if (!this.dummyDOM.querySelector(`#${cnvId + labelContainer}`)) { + let html = `
for label description + this.dummyDOM + .querySelector('#' + cnvId) + .insertAdjacentHTML('afterend', html); + } else { + //create label container +
for label description before outputs + this.dummyDOM + .querySelector(`#${cnvId}accessibleOutputLabel`) + .insertAdjacentHTML('beforebegin', html); + } + } else if (this.dummyDOM.querySelector(`#${cnvId + labelTableId}`)) { + //if describeElement() has already created the container and added a table of elements + //create label description
before the table this.dummyDOM - .querySelector(`#${cnvId}accessibleOutputLabel`) - .insertAdjacentHTML('beforebegin', html); + .querySelector(`#${cnvId + labelTableId}`) + .insertAdjacentHTML( + 'beforebegin', + `
` + ); } - } else if (this.dummyDOM.querySelector(`#${cnvId + labelTableId}`)) { - //if describeElement() has already created the container and added a table of elements - //create label descriptionbefore the table - this.dummyDOM - .querySelector(`#${cnvId + labelTableId}`) - .insertAdjacentHTML( - 'beforebegin', - `
` - ); + this.descriptions.label = this.dummyDOM.querySelector( + '#' + cnvId + labelDescId + ); + this.descriptions.label.innerHTML = text; + return; } - this.descriptions.label = this.dummyDOM.querySelector( - '#' + cnvId + labelDescId - ); - this.descriptions.label.innerHTML = text; - return; - } -}; + }; -/* - * Helper functions for describeElement(). - */ + /* + * Helper functions for describeElement(). + */ -//check that name is not LABEL or FALLBACK and ensure text ends with colon -function _elementName(name) { - if (name === 'label' || name === 'fallback') { - throw new Error('element name should not be LABEL or FALLBACK'); - } - //check if last character of string n is '.', ';', or ',' - if (name.endsWith('.') || name.endsWith(';') || name.endsWith(',')) { - //replace last character with ':' - name = name.replace(/.$/, ':'); - } else if (!name.endsWith(':')) { - //if string n does not end with ':' - //add ':'' at the end of string - name = name + ':'; + //check that name is not LABEL or FALLBACK and ensure text ends with colon + function _elementName(name) { + if (name === 'label' || name === 'fallback') { + throw new Error('element name should not be LABEL or FALLBACK'); + } + //check if last character of string n is '.', ';', or ',' + if (name.endsWith('.') || name.endsWith(';') || name.endsWith(',')) { + //replace last character with ':' + name = name.replace(/.$/, ':'); + } else if (!name.endsWith(':')) { + //if string n does not end with ':' + //add ':'' at the end of string + name = name + ':'; + } + return name; } - return name; -} -//creates HTML structure for element descriptions -p5.prototype._describeElementHTML = function(type, name, text) { - const cnvId = this.canvas.id; - if (type === 'fallback') { - //if there is no description container - if (!this.dummyDOM.querySelector(`#${cnvId + descContainer}`)) { - //if there are no accessible outputs (see textOutput() and gridOutput()) - let html = `
+ * function setup() {
+ * // Add the text description.
+ * textOutput();
+ *
+ * // Draw a couple of shapes.
+ * background(200);
+ * fill(255, 0, 0);
+ * circle(20, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle and a blue square on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * // Add the text description and
+ * // display it for debugging.
+ * textOutput(LABEL);
+ *
+ * // Draw a couple of shapes.
+ * background(200);
+ * fill(255, 0, 0);
+ * circle(20, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle and a blue square on a gray background.');
+ * }
+ *
+ *
+ * function draw() {
+ * // Add the text description.
+ * textOutput();
+ *
+ * // Draw a moving circle.
+ * background(200);
+ * let x = frameCount * 0.1;
+ * fill(255, 0, 0);
+ * circle(x, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle moves from left to right above a blue square.');
+ * }
+ *
+ *
+ * function draw() {
+ * // Add the text description and
+ * // display it for debugging.
+ * textOutput(LABEL);
+ *
+ * // Draw a moving circle.
+ * background(200);
+ * let x = frameCount * 0.1;
+ * fill(255, 0, 0);
+ * circle(x, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle moves from left to right above a blue square.');
+ * }
+ *
+ *
- * function setup() {
- * // Add the text description.
- * textOutput();
- *
- * // Draw a couple of shapes.
- * background(200);
- * fill(255, 0, 0);
- * circle(20, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle and a blue square on a gray background.');
- * }
- *
- *
- * function setup() {
- * // Add the text description and
- * // display it for debugging.
- * textOutput(LABEL);
- *
- * // Draw a couple of shapes.
- * background(200);
- * fill(255, 0, 0);
- * circle(20, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle and a blue square on a gray background.');
- * }
- *
- *
- * function draw() {
- * // Add the text description.
- * textOutput();
- *
- * // Draw a moving circle.
- * background(200);
- * let x = frameCount * 0.1;
- * fill(255, 0, 0);
- * circle(x, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle moves from left to right above a blue square.');
- * }
- *
- *
- * function draw() {
- * // Add the text description and
- * // display it for debugging.
- * textOutput(LABEL);
- *
- * // Draw a moving circle.
- * background(200);
- * let x = frameCount * 0.1;
- * fill(255, 0, 0);
- * circle(x, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle moves from left to right above a blue square.');
- * }
- *
- *
- * function setup() {
- * // Add the grid description.
- * gridOutput();
- *
- * // Draw a couple of shapes.
- * background(200);
- * fill(255, 0, 0);
- * circle(20, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle and a blue square on a gray background.');
- * }
- *
- *
- * function setup() {
- * // Add the grid description and
- * // display it for debugging.
- * gridOutput(LABEL);
- *
- * // Draw a couple of shapes.
- * background(200);
- * fill(255, 0, 0);
- * circle(20, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle and a blue square on a gray background.');
- * }
- *
- *
- * function draw() {
- * // Add the grid description.
- * gridOutput();
- *
- * // Draw a moving circle.
- * background(200);
- * let x = frameCount * 0.1;
- * fill(255, 0, 0);
- * circle(x, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle moves from left to right above a blue square.');
- * }
- *
- *
- * function draw() {
- * // Add the grid description and
- * // display it for debugging.
- * gridOutput(LABEL);
- *
- * // Draw a moving circle.
- * background(200);
- * let x = frameCount * 0.1;
- * fill(255, 0, 0);
- * circle(x, 20, 20);
- * fill(0, 0, 255);
- * square(50, 50, 50);
- *
- * // Add a general description of the canvas.
- * describe('A red circle moves from left to right above a blue square.');
- * }
- *
- *
+ * function setup() {
+ * // Add the grid description.
+ * gridOutput();
+ *
+ * // Draw a couple of shapes.
+ * background(200);
+ * fill(255, 0, 0);
+ * circle(20, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle and a blue square on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * // Add the grid description and
+ * // display it for debugging.
+ * gridOutput(LABEL);
+ *
+ * // Draw a couple of shapes.
+ * background(200);
+ * fill(255, 0, 0);
+ * circle(20, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle and a blue square on a gray background.');
+ * }
+ *
+ *
+ * function draw() {
+ * // Add the grid description.
+ * gridOutput();
+ *
+ * // Draw a moving circle.
+ * background(200);
+ * let x = frameCount * 0.1;
+ * fill(255, 0, 0);
+ * circle(x, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle moves from left to right above a blue square.');
+ * }
+ *
+ *
+ * function draw() {
+ * // Add the grid description and
+ * // display it for debugging.
+ * gridOutput(LABEL);
+ *
+ * // Draw a moving circle.
+ * background(200);
+ * let x = frameCount * 0.1;
+ * fill(255, 0, 0);
+ * circle(x, 20, 20);
+ * fill(0, 0, 255);
+ * square(50, 50, 50);
+ *
+ * // Add a general description of the canvas.
+ * describe('A red circle moves from left to right above a blue square.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(0, 126, 255, 102);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'alphaValue' to 102.
- * let alphaValue = alpha(c);
- *
- * // Draw the right rectangle.
- * fill(alphaValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a color array.
- * let c = [0, 126, 255, 102];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'alphaValue' to 102.
- * let alphaValue = alpha(c);
- *
- * // Draw the left rectangle.
- * fill(alphaValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a CSS color string.
- * let c = 'rgba(0, 126, 255, 0.4)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'alphaValue' to 102.
- * let alphaValue = alpha(c);
- *
- * // Draw the right rectangle.
- * fill(alphaValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 126, 255, 102);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'alphaValue' to 102.
+ * let alphaValue = alpha(c);
+ *
+ * // Draw the right rectangle.
+ * fill(alphaValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a color array.
+ * let c = [0, 126, 255, 102];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'alphaValue' to 102.
+ * let alphaValue = alpha(c);
+ *
+ * // Draw the left rectangle.
+ * fill(alphaValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgba(0, 126, 255, 0.4)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'alphaValue' to 102.
+ * let alphaValue = alpha(c);
+ *
+ * // Draw the right rectangle.
+ * fill(alphaValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light blue and the right one is charcoal gray.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using RGB values.
- * let c = color(175, 100, 220);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'blueValue' to 220.
- * let blueValue = blue(c);
- *
- * // Draw the right rectangle.
- * fill(0, 0, blueValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a color array.
- * let c = [175, 100, 220];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'blueValue' to 220.
- * let blueValue = blue(c);
- *
- * // Draw the right rectangle.
- * fill(0, 0, blueValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a CSS color string.
- * let c = 'rgb(175, 100, 220)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'blueValue' to 220.
- * let blueValue = blue(c);
- *
- * // Draw the right rectangle.
- * fill(0, 0, blueValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use RGB color with values in the range 0-100.
- * colorMode(RGB, 100);
- *
- * // Create a p5.Color object using RGB values.
- * let c = color(69, 39, 86);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'blueValue' to 86.
- * let blueValue = blue(c);
- *
- * // Draw the right rectangle.
- * fill(0, 0, blueValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c = color(175, 100, 220);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'blueValue' to 220.
+ * let blueValue = blue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, 0, blueValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a color array.
+ * let c = [175, 100, 220];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'blueValue' to 220.
+ * let blueValue = blue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, 0, blueValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(175, 100, 220)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'blueValue' to 220.
+ * let blueValue = blue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, 0, blueValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use RGB color with values in the range 0-100.
+ * colorMode(RGB, 100);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c = color(69, 39, 86);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'blueValue' to 86.
+ * let blueValue = blue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, 0, blueValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is royal blue.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a p5.Color object.
- * let c = color(0, 50, 100);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'brightValue' to 100.
- * let brightValue = brightness(c);
- *
- * // Draw the right rectangle.
- * fill(brightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a color array.
- * let c = [0, 50, 100];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'brightValue' to 100.
- * let brightValue = brightness(c);
- *
- * // Draw the right rectangle.
- * fill(brightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a CSS color string.
- * let c = 'rgb(255, 128, 128)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'brightValue' to 100.
- * let brightValue = brightness(c);
- *
- * // Draw the right rectangle.
- * fill(brightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color with values in the range 0-255.
- * colorMode(HSB, 255);
- *
- * // Create a p5.Color object.
- * let c = color(0, 127, 255);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'brightValue' to 255.
- * let brightValue = brightness(c);
- *
- * // Draw the right rectangle.
- * fill(brightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 50, 100);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'brightValue' to 100.
+ * let brightValue = brightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(brightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a color array.
+ * let c = [0, 50, 100];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'brightValue' to 100.
+ * let brightValue = brightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(brightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(255, 128, 128)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'brightValue' to 100.
+ * let brightValue = brightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(brightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color with values in the range 0-255.
+ * colorMode(HSB, 255);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 127, 255);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'brightValue' to 255.
+ * let brightValue = brightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(brightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using RGB values.
- * let c = color(255, 204, 0);
- *
- * // Draw the square.
- * fill(c);
- * noStroke();
- * square(30, 20, 55);
- *
- * describe('A yellow square on a gray canvas.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using RGB values.
- * let c1 = color(255, 204, 0);
- *
- * // Draw the left circle.
- * fill(c1);
- * noStroke();
- * circle(25, 25, 80);
- *
- * // Create a p5.Color object using a grayscale value.
- * let c2 = color(65);
- *
- * // Draw the right circle.
- * fill(c2);
- * circle(75, 75, 80);
- *
- * describe(
- * 'Two circles on a gray canvas. The circle in the top-left corner is yellow and the one at the bottom-right is gray.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using a named color.
- * let c = color('magenta');
- *
- * // Draw the square.
- * fill(c);
- * noStroke();
- * square(20, 20, 60);
- *
- * describe('A magenta square on a gray canvas.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using a hex color code.
- * let c1 = color('#0f0');
- *
- * // Draw the left rectangle.
- * fill(c1);
- * noStroke();
- * rect(0, 10, 45, 80);
- *
- * // Create a p5.Color object using a hex color code.
- * let c2 = color('#00ff00');
- *
- * // Draw the right rectangle.
- * fill(c2);
- * rect(55, 10, 45, 80);
- *
- * describe('Two bright green rectangles on a gray canvas.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using a RGB color string.
- * let c1 = color('rgb(0, 0, 255)');
- *
- * // Draw the top-left square.
- * fill(c1);
- * square(10, 10, 35);
- *
- * // Create a p5.Color object using a RGB color string.
- * let c2 = color('rgb(0%, 0%, 100%)');
- *
- * // Draw the top-right square.
- * fill(c2);
- * square(55, 10, 35);
- *
- * // Create a p5.Color object using a RGBA color string.
- * let c3 = color('rgba(0, 0, 255, 1)');
- *
- * // Draw the bottom-left square.
- * fill(c3);
- * square(10, 55, 35);
- *
- * // Create a p5.Color object using a RGBA color string.
- * let c4 = color('rgba(0%, 0%, 100%, 1)');
- *
- * // Draw the bottom-right square.
- * fill(c4);
- * square(55, 55, 35);
- *
- * describe('Four blue squares in the corners of a gray canvas.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using a HSL color string.
- * let c1 = color('hsl(160, 100%, 50%)');
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c1);
- * rect(0, 10, 45, 80);
- *
- * // Create a p5.Color object using a HSLA color string.
- * let c2 = color('hsla(160, 100%, 50%, 0.5)');
- *
- * // Draw the right rectangle.
- * fill(c2);
- * rect(55, 10, 45, 80);
- *
- * describe('Two sea green rectangles. A darker rectangle on the left and a brighter one on the right.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using a HSB color string.
- * let c1 = color('hsb(160, 100%, 50%)');
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c1);
- * rect(0, 10, 45, 80);
- *
- * // Create a p5.Color object using a HSBA color string.
- * let c2 = color('hsba(160, 100%, 50%, 0.5)');
- *
- * // Draw the right rectangle.
- * fill(c2);
- * rect(55, 10, 45, 80);
- *
- * describe('Two green rectangles. A darker rectangle on the left and a brighter one on the right.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object using RGB values.
- * let c1 = color(50, 55, 100);
- *
- * // Draw the left rectangle.
- * fill(c1);
- * rect(0, 10, 45, 80);
- *
- * // Switch the color mode to HSB.
- * colorMode(HSB, 100);
- *
- * // Create a p5.Color object using HSB values.
- * let c2 = color(50, 55, 100);
- *
- * // Draw the right rectangle.
- * fill(c2);
- * rect(55, 10, 45, 80);
- *
- * describe('Two blue rectangles. A darker rectangle on the left and a brighter one on the right.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c = color(255, 204, 0);
+ *
+ * // Draw the square.
+ * fill(c);
+ * noStroke();
+ * square(30, 20, 55);
+ *
+ * describe('A yellow square on a gray canvas.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c1 = color(255, 204, 0);
+ *
+ * // Draw the left circle.
+ * fill(c1);
+ * noStroke();
+ * circle(25, 25, 80);
+ *
+ * // Create a p5.Color object using a grayscale value.
+ * let c2 = color(65);
+ *
+ * // Draw the right circle.
+ * fill(c2);
+ * circle(75, 75, 80);
+ *
+ * describe(
+ * 'Two circles on a gray canvas. The circle in the top-left corner is yellow and the one at the bottom-right is gray.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using a named color.
+ * let c = color('magenta');
+ *
+ * // Draw the square.
+ * fill(c);
+ * noStroke();
+ * square(20, 20, 60);
+ *
+ * describe('A magenta square on a gray canvas.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using a hex color code.
+ * let c1 = color('#0f0');
+ *
+ * // Draw the left rectangle.
+ * fill(c1);
+ * noStroke();
+ * rect(0, 10, 45, 80);
+ *
+ * // Create a p5.Color object using a hex color code.
+ * let c2 = color('#00ff00');
+ *
+ * // Draw the right rectangle.
+ * fill(c2);
+ * rect(55, 10, 45, 80);
+ *
+ * describe('Two bright green rectangles on a gray canvas.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using a RGB color string.
+ * let c1 = color('rgb(0, 0, 255)');
+ *
+ * // Draw the top-left square.
+ * fill(c1);
+ * square(10, 10, 35);
+ *
+ * // Create a p5.Color object using a RGB color string.
+ * let c2 = color('rgb(0%, 0%, 100%)');
+ *
+ * // Draw the top-right square.
+ * fill(c2);
+ * square(55, 10, 35);
+ *
+ * // Create a p5.Color object using a RGBA color string.
+ * let c3 = color('rgba(0, 0, 255, 1)');
+ *
+ * // Draw the bottom-left square.
+ * fill(c3);
+ * square(10, 55, 35);
+ *
+ * // Create a p5.Color object using a RGBA color string.
+ * let c4 = color('rgba(0%, 0%, 100%, 1)');
+ *
+ * // Draw the bottom-right square.
+ * fill(c4);
+ * square(55, 55, 35);
+ *
+ * describe('Four blue squares in the corners of a gray canvas.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using a HSL color string.
+ * let c1 = color('hsl(160, 100%, 50%)');
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c1);
+ * rect(0, 10, 45, 80);
+ *
+ * // Create a p5.Color object using a HSLA color string.
+ * let c2 = color('hsla(160, 100%, 50%, 0.5)');
+ *
+ * // Draw the right rectangle.
+ * fill(c2);
+ * rect(55, 10, 45, 80);
+ *
+ * describe('Two sea green rectangles. A darker rectangle on the left and a brighter one on the right.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using a HSB color string.
+ * let c1 = color('hsb(160, 100%, 50%)');
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c1);
+ * rect(0, 10, 45, 80);
+ *
+ * // Create a p5.Color object using a HSBA color string.
+ * let c2 = color('hsba(160, 100%, 50%, 0.5)');
+ *
+ * // Draw the right rectangle.
+ * fill(c2);
+ * rect(55, 10, 45, 80);
+ *
+ * describe('Two green rectangles. A darker rectangle on the left and a brighter one on the right.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c1 = color(50, 55, 100);
+ *
+ * // Draw the left rectangle.
+ * fill(c1);
+ * rect(0, 10, 45, 80);
+ *
+ * // Switch the color mode to HSB.
+ * colorMode(HSB, 100);
+ *
+ * // Create a p5.Color object using HSB values.
+ * let c2 = color(50, 55, 100);
+ *
+ * // Draw the right rectangle.
+ * fill(c2);
+ * rect(55, 10, 45, 80);
+ *
+ * describe('Two blue rectangles. A darker rectangle on the left and a brighter one on the right.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(175, 100, 220);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'greenValue' to 100.
- * let greenValue = green(c);
- *
- * // Draw the right rectangle.
- * fill(0, greenValue, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is dark green.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a color array.
- * let c = [175, 100, 220];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'greenValue' to 100.
- * let greenValue = green(c);
- *
- * // Draw the right rectangle.
- * fill(0, greenValue, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is dark green.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a CSS color string.
- * let c = 'rgb(175, 100, 220)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'greenValue' to 100.
- * let greenValue = green(c);
- *
- * // Draw the right rectangle.
- * fill(0, greenValue, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is dark green.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use RGB color with values in the range 0-100.
- * colorMode(RGB, 100);
- *
- * // Create a p5.Color object using RGB values.
- * let c = color(69, 39, 86);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'greenValue' to 39.
- * let greenValue = green(c);
- *
- * // Draw the right rectangle.
- * fill(0, greenValue, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is dark green.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(175, 100, 220);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'greenValue' to 100.
+ * let greenValue = green(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, greenValue, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is dark green.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a color array.
+ * let c = [175, 100, 220];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'greenValue' to 100.
+ * let greenValue = green(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, greenValue, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is dark green.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(175, 100, 220)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'greenValue' to 100.
+ * let greenValue = green(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, greenValue, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is dark green.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use RGB color with values in the range 0-100.
+ * colorMode(RGB, 100);
+ *
+ * // Create a p5.Color object using RGB values.
+ * let c = color(69, 39, 86);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'greenValue' to 39.
+ * let greenValue = green(c);
+ *
+ * // Draw the right rectangle.
+ * fill(0, greenValue, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is dark green.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a p5.Color object.
- * let c = color(0, 50, 100);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Set 'hueValue' to 0.
- * let hueValue = hue(c);
- *
- * // Draw the right rectangle.
- * fill(hueValue);
- * rect(50, 20, 35, 60);
- *
- * describe(
- * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a color array.
- * let c = [0, 50, 100];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Set 'hueValue' to 0.
- * let hueValue = hue(c);
- *
- * // Draw the right rectangle.
- * fill(hueValue);
- * rect(50, 20, 35, 60);
- *
- * describe(
- * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a CSS color string.
- * let c = 'rgb(255, 128, 128)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Set 'hueValue' to 0.
- * let hueValue = hue(c);
- *
- * // Draw the right rectangle.
- * fill(hueValue);
- * rect(50, 20, 35, 60);
- *
- * describe(
- * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 50, 100);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Set 'hueValue' to 0.
+ * let hueValue = hue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(hueValue);
+ * rect(50, 20, 35, 60);
+ *
+ * describe(
+ * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a color array.
+ * let c = [0, 50, 100];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Set 'hueValue' to 0.
+ * let hueValue = hue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(hueValue);
+ * rect(50, 20, 35, 60);
+ *
+ * describe(
+ * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(255, 128, 128)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Set 'hueValue' to 0.
+ * let hueValue = hue(c);
+ *
+ * // Draw the right rectangle.
+ * fill(hueValue);
+ * rect(50, 20, 35, 60);
+ *
+ * describe(
+ * 'Two rectangles. The rectangle on the left is salmon pink and the one on the right is black.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create p5.Color objects to interpolate between.
- * let from = color(218, 165, 32);
- * let to = color(72, 61, 139);
- *
- * // Create intermediate colors.
- * let interA = lerpColor(from, to, 0.33);
- * let interB = lerpColor(from, to, 0.66);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(from);
- * rect(10, 20, 20, 60);
- *
- * // Draw the left-center rectangle.
- * fill(interA);
- * rect(30, 20, 20, 60);
- *
- * // Draw the right-center rectangle.
- * fill(interB);
- * rect(50, 20, 20, 60);
- *
- * // Draw the right rectangle.
- * fill(to);
- * rect(70, 20, 20, 60);
- *
- * describe(
- * 'Four rectangles. From left to right, the rectangles are tan, brown, brownish purple, and purple.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create p5.Color objects to interpolate between.
+ * let from = color(218, 165, 32);
+ * let to = color(72, 61, 139);
+ *
+ * // Create intermediate colors.
+ * let interA = lerpColor(from, to, 0.33);
+ * let interB = lerpColor(from, to, 0.66);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(from);
+ * rect(10, 20, 20, 60);
+ *
+ * // Draw the left-center rectangle.
+ * fill(interA);
+ * rect(30, 20, 20, 60);
+ *
+ * // Draw the right-center rectangle.
+ * fill(interB);
+ * rect(50, 20, 20, 60);
+ *
+ * // Draw the right rectangle.
+ * fill(to);
+ * rect(70, 20, 20, 60);
+ *
+ * describe(
+ * 'Four rectangles. From left to right, the rectangles are tan, brown, brownish purple, and purple.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a p5.Color object using HSL values.
- * let c = color(0, 100, 75);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'lightValue' to 75.
- * let lightValue = lightness(c);
- *
- * // Draw the right rectangle.
- * fill(lightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a color array.
- * let c = [0, 100, 75];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'lightValue' to 75.
- * let lightValue = lightness(c);
- *
- * // Draw the right rectangle.
- * fill(lightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a CSS color string.
- * let c = 'rgb(255, 128, 128)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'lightValue' to 75.
- * let lightValue = lightness(c);
- *
- * // Draw the right rectangle.
- * fill(lightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color with values in the range 0-255.
- * colorMode(HSL, 255);
- *
- * // Create a p5.Color object using HSL values.
- * let c = color(0, 255, 191.5);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'lightValue' to 191.5.
- * let lightValue = lightness(c);
- *
- * // Draw the right rectangle.
- * fill(lightValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a p5.Color object using HSL values.
+ * let c = color(0, 100, 75);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'lightValue' to 75.
+ * let lightValue = lightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(lightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a color array.
+ * let c = [0, 100, 75];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'lightValue' to 75.
+ * let lightValue = lightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(lightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(255, 128, 128)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'lightValue' to 75.
+ * let lightValue = lightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(lightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color with values in the range 0-255.
+ * colorMode(HSL, 255);
+ *
+ * // Create a p5.Color object using HSL values.
+ * let c = color(0, 255, 191.5);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'lightValue' to 191.5.
+ * let lightValue = lightness(c);
+ *
+ * // Draw the right rectangle.
+ * fill(lightValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(175, 100, 220);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'redValue' to 175.
- * let redValue = red(c);
- *
- * // Draw the right rectangle.
- * fill(redValue, 0, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is red.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a color array.
- * let c = [175, 100, 220];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'redValue' to 175.
- * let redValue = red(c);
- *
- * // Draw the right rectangle.
- * fill(redValue, 0, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is red.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a CSS color string.
- * let c = 'rgb(175, 100, 220)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'redValue' to 175.
- * let redValue = red(c);
- *
- * // Draw the right rectangle.
- * fill(redValue, 0, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is red.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use RGB color with values in the range 0-100.
- * colorMode(RGB, 100);
- *
- * // Create a p5.Color object.
- * let c = color(69, 39, 86);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'redValue' to 69.
- * let redValue = red(c);
- *
- * // Draw the right rectangle.
- * fill(redValue, 0, 0);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is light purple and the right one is red.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(175, 100, 220);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'redValue' to 175.
+ * let redValue = red(c);
+ *
+ * // Draw the right rectangle.
+ * fill(redValue, 0, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is red.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a color array.
+ * let c = [175, 100, 220];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'redValue' to 175.
+ * let redValue = red(c);
+ *
+ * // Draw the right rectangle.
+ * fill(redValue, 0, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is red.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(175, 100, 220)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'redValue' to 175.
+ * let redValue = red(c);
+ *
+ * // Draw the right rectangle.
+ * fill(redValue, 0, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is red.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use RGB color with values in the range 0-100.
+ * colorMode(RGB, 100);
+ *
+ * // Create a p5.Color object.
+ * let c = color(69, 39, 86);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'redValue' to 69.
+ * let redValue = red(c);
+ *
+ * // Draw the right rectangle.
+ * fill(redValue, 0, 0);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is light purple and the right one is red.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a p5.Color object.
- * let c = color(0, 50, 100);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'satValue' to 50.
- * let satValue = saturation(c);
- *
- * // Draw the right rectangle.
- * fill(satValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is dark gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a color array.
- * let c = [0, 50, 100];
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'satValue' to 100.
- * let satValue = saturation(c);
- *
- * // Draw the right rectangle.
- * fill(satValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Create a CSS color string.
- * let c = 'rgb(255, 128, 128)';
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'satValue' to 100.
- * let satValue = saturation(c);
- *
- * // Draw the right rectangle.
- * fill(satValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Create a p5.Color object.
- * let c = color(0, 100, 75);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'satValue' to 100.
- * let satValue = saturation(c);
- *
- * // Draw the right rectangle.
- * fill(satValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Use HSL color with values in the range 0-255.
- * colorMode(HSL, 255);
- *
- * // Create a p5.Color object.
- * let c = color(0, 255, 191.5);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 15, 35, 70);
- *
- * // Set 'satValue' to 255.
- * let satValue = saturation(c);
- *
- * // Draw the right rectangle.
- * fill(satValue);
- * rect(50, 15, 35, 70);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is white.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 50, 100);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'satValue' to 50.
+ * let satValue = saturation(c);
+ *
+ * // Draw the right rectangle.
+ * fill(satValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is dark gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a color array.
+ * let c = [0, 50, 100];
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'satValue' to 100.
+ * let satValue = saturation(c);
+ *
+ * // Draw the right rectangle.
+ * fill(satValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Create a CSS color string.
+ * let c = 'rgb(255, 128, 128)';
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'satValue' to 100.
+ * let satValue = saturation(c);
+ *
+ * // Draw the right rectangle.
+ * fill(satValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is gray.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 100, 75);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'satValue' to 100.
+ * let satValue = saturation(c);
+ *
+ * // Draw the right rectangle.
+ * fill(satValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Use HSL color with values in the range 0-255.
+ * colorMode(HSL, 255);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, 255, 191.5);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 15, 35, 70);
+ *
+ * // Set 'satValue' to 255.
+ * let satValue = saturation(c);
+ *
+ * // Draw the right rectangle.
+ * fill(satValue);
+ * rect(50, 15, 35, 70);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is white.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
+ * When different color representations are calculated, the results are cached
+ * for performance. These values are normalized, floating-point numbers.
*
- * background(200);
+ * Note: color() is the recommended way to create an
+ * instance of this class.
*
- * // Create a p5.Color object.
- * let myColor = color('darkorchid');
+ * @class p5.Color
+ * @param {p5} [pInst] pointer to p5 instance.
*
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the text.
- * text(myColor.toString('#rrggbb'), 50, 50);
- *
- * describe('The text "#9932cc" written in purple on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(255, 128, 128);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Change the red value.
- * c.setRed(64);
- *
- * // Draw the right rectangle.
- * fill(c);
- * rect(50, 20, 35, 60);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is teal.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let myColor = color('darkorchid');
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the text.
+ * text(myColor.toString('#rrggbb'), 50, 50);
+ *
+ * describe('The text "#9932cc" written in purple on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(255, 128, 128);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Change the green value.
- * c.setGreen(255);
- *
- * // Draw the right rectangle.
- * fill(c);
- * rect(50, 20, 35, 60);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is yellow.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(255, 128, 128);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Change the red value.
+ * c.setRed(64);
+ *
+ * // Draw the right rectangle.
+ * fill(c);
+ * rect(50, 20, 35, 60);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is teal.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(255, 128, 128);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Change the blue value.
- * c.setBlue(255);
- *
- * // Draw the right rectangle.
- * fill(c);
- * rect(50, 20, 35, 60);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is pale fuchsia.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(255, 128, 128);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Change the green value.
+ * c.setGreen(255);
+ *
+ * // Draw the right rectangle.
+ * fill(c);
+ * rect(50, 20, 35, 60);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is yellow.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let c = color(255, 128, 128);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(c);
- * rect(15, 20, 35, 60);
- *
- * // Change the alpha value.
- * c.setAlpha(128);
- *
- * // Draw the right rectangle.
- * fill(c);
- * rect(50, 20, 35, 60);
- *
- * describe('Two rectangles. The left one is salmon pink and the right one is faded pink.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(255, 128, 128);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Change the blue value.
+ * c.setBlue(255);
+ *
+ * // Draw the right rectangle.
+ * fill(c);
+ * rect(50, 20, 35, 60);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is pale fuchsia.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let c = color(255, 128, 128);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(c);
+ * rect(15, 20, 35, 60);
+ *
+ * // Change the alpha value.
+ * c.setAlpha(128);
+ *
+ * // Draw the right rectangle.
+ * fill(c);
+ * rect(50, 20, 35, 60);
+ *
+ * describe('Two rectangles. The left one is salmon pink and the right one is faded pink.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a mask.
- * beginClip();
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * endClip();
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- *
- * describe('A white triangle and circle on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an inverted mask.
- * beginClip({ invert: true });
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * endClip();
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- *
- * describe('A white square at the top-left corner of a gray square. The white square has a triangle and a circle cut out of it.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * noStroke();
- *
- * // Draw a masked shape.
- * push();
- * // Create a mask.
- * beginClip();
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * endClip();
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- * pop();
- *
- * // Translate the origin to the center.
- * translate(50, 50);
- *
- * // Draw an inverted masked shape.
- * push();
- * // Create an inverted mask.
- * beginClip({ invert: true });
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * endClip();
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- * pop();
- *
- * describe('In the top left, a white triangle and circle. In the bottom right, a white square with a triangle and circle cut out of it.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A silhouette of a rotating torus colored fuchsia.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Create a mask.
- * beginClip();
- * push();
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- * scale(0.5);
- * torus(30, 15);
- * pop();
- * endClip();
- *
- * // Draw a backing shape.
- * noStroke();
- * fill('fuchsia');
- * plane(100);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A silhouette of a rotating torus colored with a gradient from cyan to purple.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Create a mask.
- * beginClip();
- * push();
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- * scale(0.5);
- * torus(30, 15);
- * pop();
- * endClip();
- *
- * // Draw a backing shape.
- * noStroke();
- * beginShape(QUAD_STRIP);
- * fill(0, 255, 255);
- * vertex(-width / 2, -height / 2);
- * vertex(width / 2, -height / 2);
- * fill(100, 0, 100);
- * vertex(-width / 2, height / 2);
- * vertex(width / 2, height / 2);
- * endShape();
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a mask.
+ * beginClip();
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ *
+ * describe('A white triangle and circle on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an inverted mask.
+ * beginClip({ invert: true });
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ *
+ * describe('A white square at the top-left corner of a gray square. The white square has a triangle and a circle cut out of it.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * noStroke();
+ *
+ * // Draw a masked shape.
+ * push();
+ * // Create a mask.
+ * beginClip();
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ * pop();
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw an inverted masked shape.
+ * push();
+ * // Create an inverted mask.
+ * beginClip({ invert: true });
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ * pop();
+ *
+ * describe('In the top left, a white triangle and circle. In the bottom right, a white square with a triangle and circle cut out of it.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A silhouette of a rotating torus colored fuchsia.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Create a mask.
+ * beginClip();
+ * push();
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * scale(0.5);
+ * torus(30, 15);
+ * pop();
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * noStroke();
+ * fill('fuchsia');
+ * plane(100);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A silhouette of a rotating torus colored with a gradient from cyan to purple.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Create a mask.
+ * beginClip();
+ * push();
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * scale(0.5);
+ * torus(30, 15);
+ * pop();
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * noStroke();
+ * beginShape(QUAD_STRIP);
+ * fill(0, 255, 255);
+ * vertex(-width / 2, -height / 2);
+ * vertex(width / 2, -height / 2);
+ * fill(100, 0, 100);
+ * vertex(-width / 2, height / 2);
+ * vertex(width / 2, height / 2);
+ * endShape();
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a mask.
- * beginClip();
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * endClip();
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- *
- * describe('A white triangle and circle on a gray background.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a mask.
+ * beginClip();
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * endClip();
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ *
+ * describe('A white triangle and circle on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a mask.
- * clip(mask);
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- *
- * describe('A white triangle and circle on a gray background.');
- * }
- *
- * // Declare a function that defines the mask.
- * function mask() {
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an inverted mask.
- * clip(mask, { invert: true });
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- *
- * describe('A white square at the top-left corner of a gray square. The white square has a triangle and a circle cut out of it.');
- * }
- *
- * // Declare a function that defines the mask.
- * function mask() {
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * noStroke();
- *
- * // Draw a masked shape.
- * push();
- * // Create a mask.
- * clip(mask);
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- * pop();
- *
- * // Translate the origin to the center.
- * translate(50, 50);
- *
- * // Draw an inverted masked shape.
- * push();
- * // Create an inverted mask.
- * clip(mask, { invert: true });
- *
- * // Draw a backing shape.
- * square(5, 5, 45);
- * pop();
- *
- * describe('In the top left, a white triangle and circle. In the bottom right, a white square with a triangle and circle cut out of it.');
- * }
- *
- * // Declare a function that defines the mask.
- * function mask() {
- * triangle(15, 37, 30, 13, 43, 37);
- * circle(45, 45, 7);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A silhouette of a rotating torus colored fuchsia.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Create a mask.
- * clip(mask);
- *
- * // Draw a backing shape.
- * noStroke();
- * fill('fuchsia');
- * plane(100);
- * }
- *
- * // Declare a function that defines the mask.
- * function mask() {
- * push();
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- * scale(0.5);
- * torus(30, 15);
- * pop();
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A silhouette of a rotating torus colored with a gradient from cyan to purple.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Create a mask.
- * clip(mask);
- *
- * // Draw a backing shape.
- * noStroke();
- * beginShape(QUAD_STRIP);
- * fill(0, 255, 255);
- * vertex(-width / 2, -height / 2);
- * vertex(width / 2, -height / 2);
- * fill(100, 0, 100);
- * vertex(-width / 2, height / 2);
- * vertex(width / 2, height / 2);
- * endShape();
- * }
- *
- * // Declare a function that defines the mask.
- * function mask() {
- * push();
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- * scale(0.5);
- * torus(30, 15);
- * pop();
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a mask.
+ * clip(mask);
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ *
+ * describe('A white triangle and circle on a gray background.');
+ * }
+ *
+ * // Declare a function that defines the mask.
+ * function mask() {
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an inverted mask.
+ * clip(mask, { invert: true });
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ *
+ * describe('A white square at the top-left corner of a gray square. The white square has a triangle and a circle cut out of it.');
+ * }
+ *
+ * // Declare a function that defines the mask.
+ * function mask() {
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * noStroke();
+ *
+ * // Draw a masked shape.
+ * push();
+ * // Create a mask.
+ * clip(mask);
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ * pop();
+ *
+ * // Translate the origin to the center.
+ * translate(50, 50);
+ *
+ * // Draw an inverted masked shape.
+ * push();
+ * // Create an inverted mask.
+ * clip(mask, { invert: true });
+ *
+ * // Draw a backing shape.
+ * square(5, 5, 45);
+ * pop();
+ *
+ * describe('In the top left, a white triangle and circle. In the bottom right, a white square with a triangle and circle cut out of it.');
+ * }
+ *
+ * // Declare a function that defines the mask.
+ * function mask() {
+ * triangle(15, 37, 30, 13, 43, 37);
+ * circle(45, 45, 7);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A silhouette of a rotating torus colored fuchsia.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Create a mask.
+ * clip(mask);
+ *
+ * // Draw a backing shape.
+ * noStroke();
+ * fill('fuchsia');
+ * plane(100);
+ * }
+ *
+ * // Declare a function that defines the mask.
+ * function mask() {
+ * push();
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * scale(0.5);
+ * torus(30, 15);
+ * pop();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A silhouette of a rotating torus colored with a gradient from cyan to purple.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Create a mask.
+ * clip(mask);
+ *
+ * // Draw a backing shape.
+ * noStroke();
+ * beginShape(QUAD_STRIP);
+ * fill(0, 255, 255);
+ * vertex(-width / 2, -height / 2);
+ * vertex(width / 2, -height / 2);
+ * fill(100, 0, 100);
+ * vertex(-width / 2, height / 2);
+ * vertex(width / 2, height / 2);
+ * endShape();
+ * }
+ *
+ * // Declare a function that defines the mask.
+ * function mask() {
+ * push();
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ * scale(0.5);
+ * torus(30, 15);
+ * pop();
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // A grayscale value.
- * background(51);
- *
- * describe('A canvas with a dark charcoal gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // A grayscale value and an alpha value.
- * background(51, 0.4);
- * describe('A canvas with a transparent gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // R, G & B values.
- * background(255, 204, 0);
- *
- * describe('A canvas with a yellow background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // H, S & B values.
- * background(255, 204, 100);
- *
- * describe('A canvas with a royal blue background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // A CSS named color.
- * background('red');
- *
- * describe('A canvas with a red background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Three-digit hex RGB notation.
- * background('#fae');
- *
- * describe('A canvas with a pink background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Six-digit hex RGB notation.
- * background('#222222');
- *
- * describe('A canvas with a black background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Integer RGB notation.
- * background('rgb(0, 255, 0)');
- *
- * describe('A canvas with a bright green background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Integer RGBA notation.
- * background('rgba(0, 255, 0, 0.25)');
- *
- * describe('A canvas with a transparent green background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Percentage RGB notation.
- * background('rgb(100%, 0%, 10%)');
- *
- * describe('A canvas with a red background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Percentage RGBA notation.
- * background('rgba(100%, 0%, 100%, 0.5)');
- *
- * describe('A canvas with a transparent purple background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // A p5.Color object.
- * let c = color(0, 0, 255);
- * background(c);
- *
- * describe('A canvas with a blue background.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // A grayscale value.
+ * background(51);
+ *
+ * describe('A canvas with a dark charcoal gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // A grayscale value and an alpha value.
+ * background(51, 0.4);
+ * describe('A canvas with a transparent gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // R, G & B values.
+ * background(255, 204, 0);
+ *
+ * describe('A canvas with a yellow background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // H, S & B values.
+ * background(255, 204, 100);
+ *
+ * describe('A canvas with a royal blue background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // A CSS named color.
+ * background('red');
+ *
+ * describe('A canvas with a red background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Three-digit hex RGB notation.
+ * background('#fae');
+ *
+ * describe('A canvas with a pink background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Six-digit hex RGB notation.
+ * background('#222222');
+ *
+ * describe('A canvas with a black background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Integer RGB notation.
+ * background('rgb(0, 255, 0)');
+ *
+ * describe('A canvas with a bright green background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Integer RGBA notation.
+ * background('rgba(0, 255, 0, 0.25)');
+ *
+ * describe('A canvas with a transparent green background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Percentage RGB notation.
+ * background('rgb(100%, 0%, 10%)');
+ *
+ * describe('A canvas with a red background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Percentage RGBA notation.
+ * background('rgba(100%, 0%, 100%, 0.5)');
+ *
+ * describe('A canvas with a transparent purple background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // A p5.Color object.
+ * let c = color(0, 0, 255);
+ * background(c);
+ *
+ * describe('A canvas with a blue background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * describe('A gray square. White circles are drawn as the user moves the mouse. The circles disappear when the user presses the mouse.');
- * }
- *
- * function draw() {
- * circle(mouseX, mouseY, 20);
- * }
- *
- * function mousePressed() {
- * clear();
- * background(200);
- * }
- *
- *
- * let pg;
- *
- * function setup() {
- * createCanvas(100, 100);
- * background(200);
- *
- * pg = createGraphics(60, 60);
- * pg.background(200);
- * pg.noStroke();
- * pg.circle(pg.width / 2, pg.height / 2, 15);
- * image(pg, 20, 20);
- *
- * describe('A white circle drawn on a gray square. The square gets smaller when the mouse is pressed.');
- * }
- *
- * function mousePressed() {
- * clear();
- * image(pg, 20, 20);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * describe('A gray square. White circles are drawn as the user moves the mouse. The circles disappear when the user presses the mouse.');
+ * }
+ *
+ * function draw() {
+ * circle(mouseX, mouseY, 20);
+ * }
+ *
+ * function mousePressed() {
+ * clear();
+ * background(200);
+ * }
+ *
+ *
+ * let pg;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ *
+ * pg = createGraphics(60, 60);
+ * pg.background(200);
+ * pg.noStroke();
+ * pg.circle(pg.width / 2, pg.height / 2, 15);
+ * image(pg, 20, 20);
+ *
+ * describe('A white circle drawn on a gray square. The square gets smaller when the mouse is pressed.');
+ * }
+ *
+ * function mousePressed() {
+ * clear();
+ * image(pg, 20, 20);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Fill with pure red.
- * fill(255, 0, 0);
- *
- * circle(50, 50, 25);
- *
- * describe('A gray square with a red circle at its center.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use RGB color with values in the range 0-100.
- * colorMode(RGB, 100);
- *
- * // Fill with pure red.
- * fill(100, 0, 0);
- *
- * circle(50, 50, 25);
- *
- * describe('A gray square with a red circle at its center.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // Fill with pure red.
- * fill(0, 100, 100);
- *
- * circle(50, 50, 25);
- *
- * describe('A gray square with a red circle at its center.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSL color.
- * colorMode(HSL);
- *
- * // Fill with pure red.
- * fill(0, 100, 50);
- *
- * circle(50, 50, 25);
- *
- * describe('A gray square with a red circle at its center.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use RGB color with values in the range 0-100.
- * colorMode(RGB, 100);
- *
- * for (let x = 0; x < 100; x += 1) {
- * for (let y = 0; y < 100; y += 1) {
- * stroke(x, y, 0);
- * point(x, y);
- * }
- * }
- *
- * describe(
- * 'A diagonal green to red gradient from bottom-left to top-right with shading transitioning to black at top-left corner.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use HSB color with values in the range 0-100.
- * colorMode(HSB, 100);
- *
- * for (let x = 0; x < 100; x += 1) {
- * for (let y = 0; y < 100; y += 1) {
- * stroke(x, y, 100);
- * point(x, y);
- * }
- * }
- *
- * describe('A rainbow gradient from left-to-right. Brightness transitions to white at the top.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create a p5.Color object.
- * let myColor = color(180, 175, 230);
- * background(myColor);
- *
- * // Use RGB color with values in the range 0-1.
- * colorMode(RGB, 1);
- *
- * // Get the red, green, and blue color components.
- * let redValue = red(myColor);
- * let greenValue = green(myColor);
- * let blueValue = blue(myColor);
- *
- * // Round the color components for display.
- * redValue = round(redValue, 2);
- * greenValue = round(greenValue, 2);
- * blueValue = round(blueValue, 2);
- *
- * // Display the color components.
- * text(`Red: ${redValue}`, 10, 10, 80, 80);
- * text(`Green: ${greenValue}`, 10, 40, 80, 80);
- * text(`Blue: ${blueValue}`, 10, 70, 80, 80);
- *
- * describe('A purple canvas with the red, green, and blue decimal values of the color written on it.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(255);
- *
- * // Use RGB color with alpha values in the range 0-1.
- * colorMode(RGB, 255, 255, 255, 1);
- *
- * noFill();
- * strokeWeight(4);
- * stroke(255, 0, 10, 0.3);
- * circle(40, 40, 50);
- * circle(50, 60, 50);
- *
- * describe('Two overlapping translucent pink circle outlines.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Fill with pure red.
+ * fill(255, 0, 0);
+ *
+ * circle(50, 50, 25);
+ *
+ * describe('A gray square with a red circle at its center.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use RGB color with values in the range 0-100.
+ * colorMode(RGB, 100);
+ *
+ * // Fill with pure red.
+ * fill(100, 0, 0);
+ *
+ * circle(50, 50, 25);
+ *
+ * describe('A gray square with a red circle at its center.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // Fill with pure red.
+ * fill(0, 100, 100);
+ *
+ * circle(50, 50, 25);
+ *
+ * describe('A gray square with a red circle at its center.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSL color.
+ * colorMode(HSL);
+ *
+ * // Fill with pure red.
+ * fill(0, 100, 50);
+ *
+ * circle(50, 50, 25);
+ *
+ * describe('A gray square with a red circle at its center.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use RGB color with values in the range 0-100.
+ * colorMode(RGB, 100);
+ *
+ * for (let x = 0; x < 100; x += 1) {
+ * for (let y = 0; y < 100; y += 1) {
+ * stroke(x, y, 0);
+ * point(x, y);
+ * }
+ * }
+ *
+ * describe(
+ * 'A diagonal green to red gradient from bottom-left to top-right with shading transitioning to black at top-left corner.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use HSB color with values in the range 0-100.
+ * colorMode(HSB, 100);
+ *
+ * for (let x = 0; x < 100; x += 1) {
+ * for (let y = 0; y < 100; y += 1) {
+ * stroke(x, y, 100);
+ * point(x, y);
+ * }
+ * }
+ *
+ * describe('A rainbow gradient from left-to-right. Brightness transitions to white at the top.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create a p5.Color object.
+ * let myColor = color(180, 175, 230);
+ * background(myColor);
+ *
+ * // Use RGB color with values in the range 0-1.
+ * colorMode(RGB, 1);
+ *
+ * // Get the red, green, and blue color components.
+ * let redValue = red(myColor);
+ * let greenValue = green(myColor);
+ * let blueValue = blue(myColor);
+ *
+ * // Round the color components for display.
+ * redValue = round(redValue, 2);
+ * greenValue = round(greenValue, 2);
+ * blueValue = round(blueValue, 2);
+ *
+ * // Display the color components.
+ * text(`Red: ${redValue}`, 10, 10, 80, 80);
+ * text(`Green: ${greenValue}`, 10, 40, 80, 80);
+ * text(`Blue: ${blueValue}`, 10, 70, 80, 80);
+ *
+ * describe('A purple canvas with the red, green, and blue decimal values of the color written on it.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Use RGB color with alpha values in the range 0-1.
+ * colorMode(RGB, 255, 255, 255, 1);
+ *
+ * noFill();
+ * strokeWeight(4);
+ * stroke(255, 0, 10, 0.3);
+ * circle(40, 40, 50);
+ * circle(50, 60, 50);
+ *
+ * describe('Two overlapping translucent pink circle outlines.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A grayscale value.
- * fill(51);
- * square(20, 20, 60);
- *
- * describe('A dark charcoal gray square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // R, G & B values.
- * fill(255, 204, 0);
- * square(20, 20, 60);
- *
- * describe('A yellow square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(100);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // H, S & B values.
- * fill(255, 204, 100);
- * square(20, 20, 60);
- *
- * describe('A royal blue square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A CSS named color.
- * fill('red');
- * square(20, 20, 60);
- *
- * describe('A red square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Three-digit hex RGB notation.
- * fill('#fae');
- * square(20, 20, 60);
- *
- * describe('A pink square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Six-digit hex RGB notation.
- * fill('#A251FA');
- * square(20, 20, 60);
- *
- * describe('A purple square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Integer RGB notation.
- * fill('rgb(0, 255, 0)');
- * square(20, 20, 60);
- *
- * describe('A bright green square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Integer RGBA notation.
- * fill('rgba(0, 255, 0, 0.25)');
- * square(20, 20, 60);
- *
- * describe('A soft green rectange with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Percentage RGB notation.
- * fill('rgb(100%, 0%, 10%)');
- * square(20, 20, 60);
- *
- * describe('A red square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Percentage RGBA notation.
- * fill('rgba(100%, 0%, 100%, 0.5)');
- * square(20, 20, 60);
- *
- * describe('A dark fuchsia square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A p5.Color object.
- * let c = color(0, 0, 255);
- * fill(c);
- * square(20, 20, 60);
- *
- * describe('A blue square with a black outline.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A grayscale value.
+ * fill(51);
+ * square(20, 20, 60);
+ *
+ * describe('A dark charcoal gray square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // R, G & B values.
+ * fill(255, 204, 0);
+ * square(20, 20, 60);
+ *
+ * describe('A yellow square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(100);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // H, S & B values.
+ * fill(255, 204, 100);
+ * square(20, 20, 60);
+ *
+ * describe('A royal blue square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A CSS named color.
+ * fill('red');
+ * square(20, 20, 60);
+ *
+ * describe('A red square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Three-digit hex RGB notation.
+ * fill('#fae');
+ * square(20, 20, 60);
+ *
+ * describe('A pink square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Six-digit hex RGB notation.
+ * fill('#A251FA');
+ * square(20, 20, 60);
+ *
+ * describe('A purple square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Integer RGB notation.
+ * fill('rgb(0, 255, 0)');
+ * square(20, 20, 60);
+ *
+ * describe('A bright green square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Integer RGBA notation.
+ * fill('rgba(0, 255, 0, 0.25)');
+ * square(20, 20, 60);
+ *
+ * describe('A soft green rectange with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Percentage RGB notation.
+ * fill('rgb(100%, 0%, 10%)');
+ * square(20, 20, 60);
+ *
+ * describe('A red square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Percentage RGBA notation.
+ * fill('rgba(100%, 0%, 100%, 0.5)');
+ * square(20, 20, 60);
+ *
+ * describe('A dark fuchsia square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A p5.Color object.
+ * let c = color(0, 0, 255);
+ * fill(c);
+ * square(20, 20, 60);
+ *
+ * describe('A blue square with a black outline.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Draw the top square.
- * square(32, 10, 35);
- *
- * // Draw the bottom square.
- * noFill();
- * square(32, 55, 35);
- *
- * describe('A white square on above an empty square. Both squares have black outlines.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A purple cube wireframe spinning on a black canvas.');
- * }
- *
- * function draw() {
- * background(0);
- *
- * // Style the box.
- * noFill();
- * stroke(100, 100, 240);
- *
- * // Rotate the coordinates.
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- *
- * // Draw the box.
- * box(45);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw the top square.
+ * square(32, 10, 35);
+ *
+ * // Draw the bottom square.
+ * noFill();
+ * square(32, 55, 35);
+ *
+ * describe('A white square on above an empty square. Both squares have black outlines.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A purple cube wireframe spinning on a black canvas.');
+ * }
+ *
+ * function draw() {
+ * background(0);
+ *
+ * // Style the box.
+ * noFill();
+ * stroke(100, 100, 240);
+ *
+ * // Rotate the coordinates.
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ *
+ * // Draw the box.
+ * box(45);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * noStroke();
- * square(20, 20, 60);
- *
- * describe('A white square with no outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A pink cube with no edge outlines spinning on a black canvas.');
- * }
- *
- * function draw() {
- * background(0);
- *
- * // Style the box.
- * noStroke();
- * fill(240, 150, 150);
- *
- * // Rotate the coordinates.
- * rotateX(frameCount * 0.01);
- * rotateY(frameCount * 0.01);
- *
- * // Draw the box.
- * box(45);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * noStroke();
+ * square(20, 20, 60);
+ *
+ * describe('A white square with no outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A pink cube with no edge outlines spinning on a black canvas.');
+ * }
+ *
+ * function draw() {
+ * background(0);
+ *
+ * // Style the box.
+ * noStroke();
+ * fill(240, 150, 150);
+ *
+ * // Rotate the coordinates.
+ * rotateX(frameCount * 0.01);
+ * rotateY(frameCount * 0.01);
+ *
+ * // Draw the box.
+ * box(45);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A grayscale value.
- * strokeWeight(4);
- * stroke(51);
- * square(20, 20, 60);
- *
- * describe('A white square with a dark charcoal gray outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // R, G & B values.
- * stroke(255, 204, 0);
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a yellow outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use HSB color.
- * colorMode(HSB);
- *
- * // H, S & B values.
- * strokeWeight(4);
- * stroke(255, 204, 100);
- * square(20, 20, 60);
- *
- * describe('A white square with a royal blue outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A CSS named color.
- * stroke('red');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a red outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Three-digit hex RGB notation.
- * stroke('#fae');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a pink outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Six-digit hex RGB notation.
- * stroke('#222222');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a black outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Integer RGB notation.
- * stroke('rgb(0, 255, 0)');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A whiite square with a bright green outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Integer RGBA notation.
- * stroke('rgba(0, 255, 0, 0.25)');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a soft green outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Percentage RGB notation.
- * stroke('rgb(100%, 0%, 10%)');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a red outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Percentage RGBA notation.
- * stroke('rgba(100%, 0%, 100%, 0.5)');
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a dark fuchsia outline.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // A p5.Color object.
- * stroke(color(0, 0, 255));
- * strokeWeight(4);
- * square(20, 20, 60);
- *
- * describe('A white square with a blue outline.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A grayscale value.
+ * strokeWeight(4);
+ * stroke(51);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a dark charcoal gray outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // R, G & B values.
+ * stroke(255, 204, 0);
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a yellow outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use HSB color.
+ * colorMode(HSB);
+ *
+ * // H, S & B values.
+ * strokeWeight(4);
+ * stroke(255, 204, 100);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a royal blue outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A CSS named color.
+ * stroke('red');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a red outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Three-digit hex RGB notation.
+ * stroke('#fae');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a pink outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Six-digit hex RGB notation.
+ * stroke('#222222');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a black outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Integer RGB notation.
+ * stroke('rgb(0, 255, 0)');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A whiite square with a bright green outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Integer RGBA notation.
+ * stroke('rgba(0, 255, 0, 0.25)');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a soft green outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Percentage RGB notation.
+ * stroke('rgb(100%, 0%, 10%)');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a red outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Percentage RGBA notation.
+ * stroke('rgba(100%, 0%, 100%, 0.5)');
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a dark fuchsia outline.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // A p5.Color object.
+ * stroke(color(0, 0, 255));
+ * strokeWeight(4);
+ * square(20, 20, 60);
+ *
+ * describe('A white square with a blue outline.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(100, 100, 250);
- *
- * // Draw a pink square.
- * fill(250, 100, 100);
- * square(20, 20, 60);
- *
- * // Erase a circular area.
- * erase();
- * circle(25, 30, 30);
- * noErase();
- *
- * describe('A purple canvas with a pink square in the middle. A circle is erased from the top-left, leaving a hole.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(100, 100, 250);
- *
- * // Draw a pink square.
- * fill(250, 100, 100);
- * square(20, 20, 60);
- *
- * // Erase a circular area.
- * strokeWeight(5);
- * erase(150, 255);
- * circle(25, 30, 30);
- * noErase();
- *
- * describe('A purple canvas with a pink square in the middle. A circle at the top-left partially erases its interior and a fully erases its outline.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(100, 100, 250);
+ *
+ * // Draw a pink square.
+ * fill(250, 100, 100);
+ * square(20, 20, 60);
+ *
+ * // Erase a circular area.
+ * erase();
+ * circle(25, 30, 30);
+ * noErase();
+ *
+ * describe('A purple canvas with a pink square in the middle. A circle is erased from the top-left, leaving a hole.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(100, 100, 250);
+ *
+ * // Draw a pink square.
+ * fill(250, 100, 100);
+ * square(20, 20, 60);
+ *
+ * // Erase a circular area.
+ * strokeWeight(5);
+ * erase(150, 255);
+ * circle(25, 30, 30);
+ * noErase();
+ *
+ * describe('A purple canvas with a pink square in the middle. A circle at the top-left partially erases its interior and a fully erases its outline.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(235, 145, 15);
- *
- * // Draw the left rectangle.
- * noStroke();
- * fill(30, 45, 220);
- * rect(30, 10, 10, 80);
- *
- * // Erase a circle.
- * erase();
- * circle(50, 50, 60);
- * noErase();
- *
- * // Draw the right rectangle.
- * rect(70, 10, 10, 80);
- *
- * describe('An orange canvas with two tall blue rectangles. A circular hole in the center erases the rectangle on the left but not the one on the right.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(235, 145, 15);
+ *
+ * // Draw the left rectangle.
+ * noStroke();
+ * fill(30, 45, 220);
+ * rect(30, 10, 10, 80);
+ *
+ * // Erase a circle.
+ * erase();
+ * circle(50, 50, 60);
+ * noErase();
+ *
+ * // Draw the right rectangle.
+ * rect(70, 10, 10, 80);
+ *
+ * describe('An orange canvas with two tall blue rectangles. A circular hole in the center erases the rectangle on the left but not the one on the right.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Store the player's name.
- * storeItem('name', 'Feist');
- *
- * // Store the player's score.
- * storeItem('score', 1234);
- *
- * describe('The text "Feist: 1234" written in black on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Retrieve the name.
- * let name = getItem('name');
- *
- * // Retrieve the score.
- * let score = getItem('score');
- *
- * // Display the score.
- * text(`${name}: ${score}`, 50, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create an object.
- * let p = { x: 50, y: 50 };
- *
- * // Store the object.
- * storeItem('position', p);
- *
- * describe('A white circle on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Retrieve the object.
- * let p = getItem('position');
- *
- * // Draw the circle.
- * circle(p.x, p.y, 30);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Store the player's name.
+ * storeItem('name', 'Feist');
+ *
+ * // Store the player's score.
+ * storeItem('score', 1234);
+ *
+ * describe('The text "Feist: 1234" written in black on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Retrieve the name.
+ * let name = getItem('name');
+ *
+ * // Retrieve the score.
+ * let score = getItem('score');
+ *
+ * // Display the score.
+ * text(`${name}: ${score}`, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create an object.
+ * let p = { x: 50, y: 50 };
+ *
+ * // Store the object.
+ * storeItem('position', p);
+ *
+ * describe('A white circle on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Retrieve the object.
+ * let p = getItem('position');
+ *
+ * // Draw the circle.
+ * circle(p.x, p.y, 30);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Store the player's name.
- * storeItem('name', 'Feist');
- *
- * // Store the player's score.
- * storeItem('score', 1234);
- *
- * describe('The text "Feist: 1234" written in black on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Retrieve the name.
- * let name = getItem('name');
- *
- * // Retrieve the score.
- * let score = getItem('score');
- *
- * // Display the score.
- * text(`${name}: ${score}`, 50, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create an object.
- * let p = { x: 50, y: 50 };
- *
- * // Store the object.
- * storeItem('position', p);
- *
- * describe('A white circle on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Retrieve the object.
- * let p = getItem('position');
- *
- * // Draw the circle.
- * circle(p.x, p.y, 30);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create a p5.Color object.
- * let c = color('deeppink');
- *
- * // Store the object.
- * storeItem('color', c);
- *
- * describe('A pink circle on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Retrieve the object.
- * let c = getItem('color');
- *
- * // Style the circle.
- * fill(c);
- *
- * // Draw the circle.
- * circle(50, 50, 30);
- * }
- *
- *
- * // Double-click to clear localStorage.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Store the player's name.
- * storeItem('name', 'Feist');
- *
- * // Store the player's score.
- * storeItem('score', 1234);
- *
- * describe(
- * 'The text "Feist: 1234" written in black on a gray background. The text "null: null" appears when the user double-clicks.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Retrieve the name.
- * let name = getItem('name');
- *
- * // Retrieve the score.
- * let score = getItem('score');
- *
- * // Display the score.
- * text(`${name}: ${score}`, 50, 50);
- * }
- *
- * // Clear localStorage when the user double-clicks.
- * function doubleClicked() {
- * clearStorage();
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Store the player's name.
+ * storeItem('name', 'Feist');
+ *
+ * // Store the player's score.
+ * storeItem('score', 1234);
+ *
+ * describe('The text "Feist: 1234" written in black on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Retrieve the name.
+ * let name = getItem('name');
+ *
+ * // Retrieve the score.
+ * let score = getItem('score');
+ *
+ * // Display the score.
+ * text(`${name}: ${score}`, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create an object.
+ * let p = { x: 50, y: 50 };
+ *
+ * // Store the object.
+ * storeItem('position', p);
+ *
+ * describe('A white circle on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Retrieve the object.
+ * let p = getItem('position');
+ *
+ * // Draw the circle.
+ * circle(p.x, p.y, 30);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create a p5.Color object.
+ * let c = color('deeppink');
+ *
+ * // Store the object.
+ * storeItem('color', c);
+ *
+ * describe('A pink circle on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Retrieve the object.
+ * let c = getItem('color');
+ *
+ * // Style the circle.
+ * fill(c);
+ *
+ * // Draw the circle.
+ * circle(50, 50, 30);
+ * }
+ *
+ *
- * // Double-click to remove an item from localStorage.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Store the player's name.
- * storeItem('name', 'Feist');
- *
- * // Store the player's score.
- * storeItem('score', 1234);
- *
- * describe(
- * 'The text "Feist: 1234" written in black on a gray background. The text "Feist: null" appears when the user double-clicks.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Retrieve the name.
- * let name = getItem('name');
- *
- * // Retrieve the score.
- * let score = getItem('score');
- *
- * // Display the score.
- * text(`${name}: ${score}`, 50, 50);
- * }
- *
- * // Remove the word from localStorage when the user double-clicks.
- * function doubleClicked() {
- * removeItem('score');
- * }
- *
- *
+ * // Double-click to clear localStorage.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Store the player's name.
+ * storeItem('name', 'Feist');
+ *
+ * // Store the player's score.
+ * storeItem('score', 1234);
+ *
+ * describe(
+ * 'The text "Feist: 1234" written in black on a gray background. The text "null: null" appears when the user double-clicks.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Retrieve the name.
+ * let name = getItem('name');
+ *
+ * // Retrieve the score.
+ * let score = getItem('score');
+ *
+ * // Display the score.
+ * text(`${name}: ${score}`, 50, 50);
+ * }
+ *
+ * // Clear localStorage when the user double-clicks.
+ * function doubleClicked() {
+ * clearStorage();
+ * }
+ *
+ *
+ * // Double-click to remove an item from localStorage.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Store the player's name.
+ * storeItem('name', 'Feist');
+ *
+ * // Store the player's score.
+ * storeItem('score', 1234);
+ *
+ * describe(
+ * 'The text "Feist: 1234" written in black on a gray background. The text "Feist: null" appears when the user double-clicks.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Retrieve the name.
+ * let name = getItem('name');
+ *
+ * // Retrieve the score.
+ * let score = getItem('score');
+ *
+ * // Display the score.
+ * text(`${name}: ${score}`, 50, 50);
+ * }
+ *
+ * // Remove the word from localStorage when the user double-clicks.
+ * function doubleClicked() {
+ * removeItem('score');
+ * }
+ *
+ *
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * print(myDictionary.hasKey('p5')); // logs true to console
- *
- * let anotherDictionary = createStringDict({ happy: 'coding' });
- * print(anotherDictionary.hasKey('happy')); // logs true to console
- * }
- *
- * function setup() {
- * let myDictionary = createNumberDict(100, 42);
- * print(myDictionary.hasKey(100)); // logs true to console
- *
- * let anotherDictionary = createNumberDict({ 200: 84 });
- * print(anotherDictionary.hasKey(200)); // logs true to console
- * }
- *
- * function setup() {
- * let myDictionary = createNumberDict(1, 10);
- * myDictionary.create(2, 20);
- * myDictionary.create(3, 30);
- * print(myDictionary.size()); // logs 3 to the console
- * }
- *
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * let myValue = myDictionary.get('p5');
- * print(myValue === 'js'); // logs true to console
- * }
- *
* function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * myDictionary.set('p5', 'JS');
- * myDictionary.print(); // logs "key: p5 - value: JS" to console
+ * let myDictionary = createNumberDict(100, 42);
+ * print(myDictionary.hasKey(100)); // logs true to console
+ *
+ * let anotherDictionary = createNumberDict({ 200: 84 });
+ * print(anotherDictionary.hasKey(200)); // logs true to console
* }
*
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * myDictionary.create('happy', 'coding');
- * myDictionary.print();
- * // above logs "key: p5 - value: js, key: happy - value: coding" to console
- * }
- *
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * print(myDictionary.hasKey('p5')); // prints 'true'
- * myDictionary.clear();
- * print(myDictionary.hasKey('p5')); // prints 'false'
- * }
- *
- *
+ * function setup() {
+ * let myDictionary = createNumberDict(1, 10);
+ * myDictionary.create(2, 20);
+ * myDictionary.create(3, 30);
+ * print(myDictionary.size()); // logs 3 to the console
+ * }
+ *
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * myDictionary.create('happy', 'coding');
- * myDictionary.print();
- * // above logs "key: p5 - value: js, key: happy - value: coding" to console
- * myDictionary.remove('p5');
- * myDictionary.print();
- * // above logs "key: happy value: coding" to console
- * }
- *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * print(myDictionary.hasKey('p5')); // logs true to console
+ * }
+ *
- * function setup() {
- * let myDictionary = createStringDict('p5', 'js');
- * myDictionary.create('happy', 'coding');
- * myDictionary.print();
- * // above logs "key: p5 - value: js, key: happy - value: coding" to console
- * }
- *
- *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * let myValue = myDictionary.get('p5');
+ * print(myValue === 'js'); // logs true to console
+ * }
+ *
- * function setup() {
- * createCanvas(100, 100);
- * background(200);
- * text('click here to save', 10, 10, 70, 80);
- * }
- *
- * function mousePressed() {
- * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
- * createStringDict({
- * john: 1940,
- * paul: 1942,
- * george: 1943,
- * ringo: 1940
- * }).saveTable('beatles');
- * }
- * }
- *
- *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.set('p5', 'JS');
+ * myDictionary.print(); // logs "key: p5 - value: JS" to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * }
+ *
- * function setup() {
- * createCanvas(100, 100);
- * background(200);
- * text('click here to save', 10, 10, 70, 80);
- * }
- *
- * function mousePressed() {
- * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
- * createStringDict({
- * john: 1940,
- * paul: 1942,
- * george: 1943,
- * ringo: 1940
- * }).saveJSON('beatles');
- * }
- * }
- *
- *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * print(myDictionary.hasKey('p5')); // prints 'true'
+ * myDictionary.clear();
+ * print(myDictionary.hasKey('p5')); // prints 'false'
+ * }
+ *
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * myDictionary.remove('p5');
+ * myDictionary.print();
+ * // above logs "key: happy value: coding" to console
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createStringDict('p5', 'js');
+ * myDictionary.create('happy', 'coding');
+ * myDictionary.print();
+ * // above logs "key: p5 - value: js, key: happy - value: coding" to console
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * createStringDict({
+ * john: 1940,
+ * paul: 1942,
+ * george: 1943,
+ * ringo: 1940
+ * }).saveTable('beatles');
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * text('click here to save', 10, 10, 70, 80);
+ * }
+ *
+ * function mousePressed() {
+ * if (mouseX > 0 && mouseX < width && mouseY > 0 && mouseY < height) {
+ * createStringDict({
+ * john: 1940,
+ * paul: 1942,
+ * george: 1943,
+ * ringo: 1940
+ * }).saveJSON('beatles');
+ * }
+ * }
+ *
+ *
- * function setup() {
- * let myDictionary = createNumberDict(2, 5);
- * myDictionary.add(2, 2);
- * print(myDictionary.get(2)); // logs 7 to console.
- * }
- *
- * function setup() {
- * let myDictionary = createNumberDict(2, 5);
- * myDictionary.sub(2, 2);
- * print(myDictionary.get(2)); // logs 3 to console.
- * }
- *
- * function setup() {
- * let myDictionary = createNumberDict(2, 4);
- * myDictionary.mult(2, 2);
- * print(myDictionary.get(2)); // logs 8 to console.
- * }
- *
- * function setup() {
- * let myDictionary = createNumberDict(2, 8);
- * myDictionary.div(2, 2);
- * print(myDictionary.get(2)); // logs 4 to console.
- * }
- *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 5);
+ * myDictionary.add(2, 2);
+ * print(myDictionary.get(2)); // logs 7 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 5);
+ * myDictionary.sub(2, 2);
+ * print(myDictionary.get(2)); // logs 3 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 4);
+ * myDictionary.mult(2, 2);
+ * print(myDictionary.get(2)); // logs 8 to console.
+ * }
+ *
+ * function setup() {
+ * let myDictionary = createNumberDict(2, 8);
+ * myDictionary.div(2, 2);
+ * print(myDictionary.get(2)); // logs 4 to console.
+ * }
+ *
- * function setup() {
- * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
- * let lowestValue = myDictionary.minValue(); // value is -10
- * print(lowestValue);
- * }
- *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
+ * let lowestValue = myDictionary.minValue(); // value is -10
+ * print(lowestValue);
+ * }
+ *
- * function setup() {
- * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
- * let highestValue = myDictionary.maxValue(); // value is 3
- * print(highestValue);
- * }
- *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: -10, 4: 0.65, 1.2: 3 });
+ * let highestValue = myDictionary.maxValue(); // value is 3
+ * print(highestValue);
+ * }
+ *
- * function setup() {
- * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
- * let lowestKey = myDictionary.minKey(); // value is 1.2
- * print(lowestKey);
- * }
- *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
+ * let lowestKey = myDictionary.minKey(); // value is 1.2
+ * print(lowestKey);
+ * }
+ *
- * function setup() {
- * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
- * let highestKey = myDictionary.maxKey(); // value is 4
- * print(highestKey);
- * }
- *
+ * function setup() {
+ * let myDictionary = createNumberDict({ 2: 4, 4: 6, 1.2: 3 });
+ * let highestKey = myDictionary.maxKey(); // value is 4
+ * print(highestKey);
+ * }
+ *
- * // Move a touchscreen device to register
- * // acceleration changes.
- * function draw() {
- * background(220, 50);
- * fill('magenta');
- * ellipse(width / 2, height / 2, accelerationX);
- * describe('Magnitude of device acceleration is displayed as ellipse size.');
- * }
- *
- *
- * // Move a touchscreen device to register
- * // acceleration changes.
- * function draw() {
- * background(220, 50);
- * fill('magenta');
- * ellipse(width / 2, height / 2, accelerationY);
- * describe('Magnitude of device acceleration is displayed as ellipse size');
- * }
- *
- *
- * // Move a touchscreen device to register
- * // acceleration changes.
- * function draw() {
- * background(220, 50);
- * fill('magenta');
- * ellipse(width / 2, height / 2, accelerationZ);
- * describe('Magnitude of device acceleration is displayed as ellipse size');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- * }
- *
- * function draw() {
- * background(200);
- * //rotateZ(radians(rotationZ));
- * rotateX(radians(rotationX));
- * //rotateY(radians(rotationY));
- * box(200, 200, 200);
- * describe(`red horizontal line right, green vertical line bottom.
- * black background.`);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- * }
- *
- * function draw() {
- * background(200);
- * //rotateZ(radians(rotationZ));
- * //rotateX(radians(rotationX));
- * rotateY(radians(rotationY));
- * box(200, 200, 200);
- * describe(`red horizontal line right, green vertical line bottom.
- * black background.`);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- * }
- *
- * function draw() {
- * background(200);
- * rotateZ(radians(rotationZ));
- * //rotateX(radians(rotationX));
- * //rotateY(radians(rotationY));
- * box(200, 200, 200);
- * describe(`red horizontal line right, green vertical line bottom.
- * black background.`);
- * }
- *
- *
- * // A simple if statement looking at whether
- * // rotationX - pRotationX < 0 is true or not will be
- * // sufficient for determining the rotate direction
- * // in most cases.
- *
- * // Some extra logic is needed to account for cases where
- * // the angles wrap around.
- * let rotateDirection = 'clockwise';
- *
- * // Simple range conversion to make things simpler.
- * // This is not absolutely necessary but the logic
- * // will be different in that case.
- *
- * let rX = rotationX + 180;
- * let pRX = pRotationX + 180;
- *
- * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) {
- * rotateDirection = 'clockwise';
- * } else if (rX - pRX < 0 || rX - pRX > 270) {
- * rotateDirection = 'counter-clockwise';
- * }
- *
- * print(rotateDirection);
- * describe('no image to display.');
- *
- *
- * // A simple if statement looking at whether
- * // rotationY - pRotationY < 0 is true or not will be
- * // sufficient for determining the rotate direction
- * // in most cases.
- *
- * // Some extra logic is needed to account for cases where
- * // the angles wrap around.
- * let rotateDirection = 'clockwise';
- *
- * // Simple range conversion to make things simpler.
- * // This is not absolutely necessary but the logic
- * // will be different in that case.
- *
- * let rY = rotationY + 180;
- * let pRY = pRotationY + 180;
- *
- * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) {
- * rotateDirection = 'clockwise';
- * } else if (rY - pRY < 0 || rY - pRY > 270) {
- * rotateDirection = 'counter-clockwise';
- * }
- * print(rotateDirection);
- * describe('no image to display.');
- *
- *
- * // A simple if statement looking at whether
- * // rotationZ - pRotationZ < 0 is true or not will be
- * // sufficient for determining the rotate direction
- * // in most cases.
- *
- * // Some extra logic is needed to account for cases where
- * // the angles wrap around.
- * let rotateDirection = 'clockwise';
- *
- * if (
- * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) ||
- * rotationZ - pRotationZ < -270
- * ) {
- * rotateDirection = 'clockwise';
- * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) {
- * rotateDirection = 'counter-clockwise';
- * }
- * print(rotateDirection);
- * describe('no image to display.');
- *
- *
- * // Run this example on a mobile device
- * // Rotate the device by 90 degrees in the
- * // X-axis to change the value.
- *
- * let value = 0;
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device turns`);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when x-axis turns`);
- * }
- * function deviceTurned() {
- * if (turnAxis === 'X') {
- * if (value === 0) {
- * value = 255;
- * } else if (value === 255) {
- * value = 0;
- * }
- * }
- * }
- *
- *
- * // Run this example on a mobile device
- * // You will need to move the device incrementally further
- * // the closer the square's color gets to white in order to change the value.
- *
- * let value = 0;
- * let threshold = 0.5;
- * function setup() {
- * setMoveThreshold(threshold);
- * }
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device moves`);
- * }
- * function deviceMoved() {
- * value = value + 5;
- * threshold = threshold + 0.1;
- * if (value > 255) {
- * value = 0;
- * threshold = 30;
- * }
- * setMoveThreshold(threshold);
- * }
- *
- *
- * // Run this example on a mobile device
- * // You will need to shake the device more firmly
- * // the closer the box's fill gets to white in order to change the value.
- *
- * let value = 0;
- * let threshold = 30;
- * function setup() {
- * setShakeThreshold(threshold);
- * }
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device is being shaked`);
- * }
- * function deviceMoved() {
- * value = value + 5;
- * threshold = threshold + 5;
- * if (value > 255) {
- * value = 0;
- * threshold = 30;
- * }
- * setShakeThreshold(threshold);
- * }
- *
- *
- * // Run this example on a mobile device
- * // Move the device around
- * // to change the value.
- *
- * let value = 0;
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device moves`);
- * }
- * function deviceMoved() {
- * value = value + 5;
- * if (value > 255) {
- * value = 0;
- * }
- * }
- *
- *
- * // Run this example on a mobile device
- * // Rotate the device by 90 degrees
- * // to change the value.
- *
- * let value = 0;
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device turns`);
- * }
- * function deviceTurned() {
- * if (value === 0) {
- * value = 255;
- * } else if (value === 255) {
- * value = 0;
- * }
- * }
- *
- *
- * // Run this example on a mobile device
- * // Rotate the device by 90 degrees in the
- * // X-axis to change the value.
- *
- * let value = 0;
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when x-axis turns`);
- * }
- * function deviceTurned() {
- * if (turnAxis === 'X') {
- * if (value === 0) {
- * value = 255;
- * } else if (value === 255) {
- * value = 0;
- * }
- * }
- * }
- *
- *
- * // Run this example on a mobile device
- * // Shake the device to change the value.
- *
- * let value = 0;
- * function draw() {
- * fill(value);
- * rect(25, 25, 50, 50);
- * describe(`50-by-50 black rect in center of canvas.
- * turns white on mobile when device shakes`);
- * }
- * function deviceShaken() {
- * value = value + 5;
- * if (value > 255) {
- * value = 0;
- * }
- * }
- *
- *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationX);
+ * describe('Magnitude of device acceleration is displayed as ellipse size.');
+ * }
+ *
+ *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationY);
+ * describe('Magnitude of device acceleration is displayed as ellipse size');
+ * }
+ *
+ *
+ * // Move a touchscreen device to register
+ * // acceleration changes.
+ * function draw() {
+ * background(220, 50);
+ * fill('magenta');
+ * ellipse(width / 2, height / 2, accelerationZ);
+ * describe('Magnitude of device acceleration is displayed as ellipse size');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * //rotateZ(radians(rotationZ));
+ * rotateX(radians(rotationX));
+ * //rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * describe(`red horizontal line right, green vertical line bottom.
+ * black background.`);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * //rotateZ(radians(rotationZ));
+ * //rotateX(radians(rotationX));
+ * rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * describe(`red horizontal line right, green vertical line bottom.
+ * black background.`);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ * }
+ *
+ * function draw() {
+ * background(200);
+ * rotateZ(radians(rotationZ));
+ * //rotateX(radians(rotationX));
+ * //rotateY(radians(rotationY));
+ * box(200, 200, 200);
+ * describe(`red horizontal line right, green vertical line bottom.
+ * black background.`);
+ * }
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationX - pRotationX < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * // Simple range conversion to make things simpler.
+ * // This is not absolutely necessary but the logic
+ * // will be different in that case.
+ *
+ * let rX = rotationX + 180;
+ * let pRX = pRotationX + 180;
+ *
+ * if ((rX - pRX > 0 && rX - pRX < 270) || rX - pRX < -270) {
+ * rotateDirection = 'clockwise';
+ * } else if (rX - pRX < 0 || rX - pRX > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ *
+ * print(rotateDirection);
+ * describe('no image to display.');
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationY - pRotationY < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * // Simple range conversion to make things simpler.
+ * // This is not absolutely necessary but the logic
+ * // will be different in that case.
+ *
+ * let rY = rotationY + 180;
+ * let pRY = pRotationY + 180;
+ *
+ * if ((rY - pRY > 0 && rY - pRY < 270) || rY - pRY < -270) {
+ * rotateDirection = 'clockwise';
+ * } else if (rY - pRY < 0 || rY - pRY > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ * print(rotateDirection);
+ * describe('no image to display.');
+ *
+ *
+ * // A simple if statement looking at whether
+ * // rotationZ - pRotationZ < 0 is true or not will be
+ * // sufficient for determining the rotate direction
+ * // in most cases.
+ *
+ * // Some extra logic is needed to account for cases where
+ * // the angles wrap around.
+ * let rotateDirection = 'clockwise';
+ *
+ * if (
+ * (rotationZ - pRotationZ > 0 && rotationZ - pRotationZ < 270) ||
+ * rotationZ - pRotationZ < -270
+ * ) {
+ * rotateDirection = 'clockwise';
+ * } else if (rotationZ - pRotationZ < 0 || rotationZ - pRotationZ > 270) {
+ * rotateDirection = 'counter-clockwise';
+ * }
+ * print(rotateDirection);
+ * describe('no image to display.');
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees in the
+ * // X-axis to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device turns`);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when x-axis turns`);
+ * }
+ * function deviceTurned() {
+ * if (turnAxis === 'X') {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // You will need to move the device incrementally further
+ * // the closer the square's color gets to white in order to change the value.
+ *
+ * let value = 0;
+ * let threshold = 0.5;
+ * function setup() {
+ * setMoveThreshold(threshold);
+ * }
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device moves`);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * threshold = threshold + 0.1;
+ * if (value > 255) {
+ * value = 0;
+ * threshold = 30;
+ * }
+ * setMoveThreshold(threshold);
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // You will need to shake the device more firmly
+ * // the closer the box's fill gets to white in order to change the value.
+ *
+ * let value = 0;
+ * let threshold = 30;
+ * function setup() {
+ * setShakeThreshold(threshold);
+ * }
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device is being shaked`);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * threshold = threshold + 5;
+ * if (value > 255) {
+ * value = 0;
+ * threshold = 30;
+ * }
+ * setShakeThreshold(threshold);
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Move the device around
+ * // to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device moves`);
+ * }
+ * function deviceMoved() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees
+ * // to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device turns`);
+ * }
+ * function deviceTurned() {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Rotate the device by 90 degrees in the
+ * // X-axis to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when x-axis turns`);
+ * }
+ * function deviceTurned() {
+ * if (turnAxis === 'X') {
+ * if (value === 0) {
+ * value = 255;
+ * } else if (value === 255) {
+ * value = 0;
+ * }
+ * }
+ * }
+ *
+ *
+ * // Run this example on a mobile device
+ * // Shake the device to change the value.
+ *
+ * let value = 0;
+ * function draw() {
+ * fill(value);
+ * rect(25, 25, 50, 50);
+ * describe(`50-by-50 black rect in center of canvas.
+ * turns white on mobile when device shakes`);
+ * }
+ * function deviceShaken() {
+ * value = value + 5;
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The white square turns black when the user presses a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * if (keyIsPressed === true) {
+ * fill(0);
+ * } else {
+ * fill(255);
+ * }
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The white square turns black when the user presses a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * if (keyIsPressed) {
+ * fill(0);
+ * } else {
+ * fill(255);
+ * }
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the word "false" at its center. The word switches to "true" when the user presses a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the value of keyIsPressed.
+ * text(keyIsPressed, 50, 50);
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The white square turns black when the user presses a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * if (keyIsPressed === true) {
- * fill(0);
- * } else {
- * fill(255);
- * }
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The white square turns black when the user presses a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * if (keyIsPressed) {
- * fill(0);
- * } else {
- * fill(255);
- * }
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the word "false" at its center. The word switches to "true" when the user presses a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the value of keyIsPressed.
- * text(keyIsPressed, 50, 50);
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. The last key pressed is displayed at the center.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the last key pressed.
+ * text(key, 50, 50);
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let x = 50;
+ * let y = 50;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * describe(
+ * 'A gray square with a black circle at its center. The circle moves when the user presses the keys "w", "a", "s", or "d". It leaves a trail as it moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * // Update x and y if a key is pressed.
+ * if (keyIsPressed === true) {
+ * if (key === 'w') {
+ * y -= 1;
+ * } else if (key === 's') {
+ * y += 1;
+ * } else if (key === 'a') {
+ * x -= 1;
+ * } else if (key === 'd') {
+ * x += 1;
+ * }
+ * }
+ *
+ * // Style the circle.
+ * fill(0);
+ *
+ * // Draw the circle at (x, y).
+ * circle(x, y, 5);
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. The last key pressed is displayed at the center.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the last key pressed.
- * text(key, 50, 50);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let x = 50;
- * let y = 50;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * describe(
- * 'A gray square with a black circle at its center. The circle moves when the user presses the keys "w", "a", "s", or "d". It leaves a trail as it moves.'
- * );
- * }
- *
- * function draw() {
- * // Update x and y if a key is pressed.
- * if (keyIsPressed === true) {
- * if (key === 'w') {
- * y -= 1;
- * } else if (key === 's') {
- * y += 1;
- * } else if (key === 'a') {
- * x -= 1;
- * } else if (key === 'd') {
- * x += 1;
- * }
- * }
- *
- * // Style the circle.
- * fill(0);
- *
- * // Draw the circle at (x, y).
- * circle(x, y, 5);
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. The last key pressed and its code are displayed at the center.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the last key pressed and its code.
+ * text(`${key} : ${keyCode}`, 50, 50);
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let x = 50;
+ * let y = 50;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * describe(
+ * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * // Update x and y if an arrow key is pressed.
+ * if (keyIsPressed === true) {
+ * if (keyCode === UP_ARROW) {
+ * y -= 1;
+ * } else if (keyCode === DOWN_ARROW) {
+ * y += 1;
+ * } else if (keyCode === LEFT_ARROW) {
+ * x -= 1;
+ * } else if (keyCode === RIGHT_ARROW) {
+ * x += 1;
+ * }
+ * }
+ *
+ * // Style the circle.
+ * fill(0);
+ *
+ * // Draw the circle at (x, y).
+ * circle(x, y, 5);
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. The last key pressed and its code are displayed at the center.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the last key pressed and its code.
- * text(`${key} : ${keyCode}`, 50, 50);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let x = 50;
- * let y = 50;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * describe(
- * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
- * );
- * }
- *
- * function draw() {
- * // Update x and y if an arrow key is pressed.
- * if (keyIsPressed === true) {
- * if (keyCode === UP_ARROW) {
- * y -= 1;
- * } else if (keyCode === DOWN_ARROW) {
- * y += 1;
- * } else if (keyCode === LEFT_ARROW) {
- * x -= 1;
- * } else if (keyCode === RIGHT_ARROW) {
- * x += 1;
- * }
- * }
- *
- * // Style the circle.
- * fill(0);
- *
- * // Draw the circle at (x, y).
- * circle(x, y, 5);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square changes color when the user presses a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the background color when the user presses a key.
- * function keyPressed() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The inner square turns black when the user presses the "b" key. It turns white when the user presses the "a" key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Reassign value when the user presses the 'a' or 'b' key.
- * function keyPressed() {
- * if (key === 'a') {
- * value = 255;
- * } else if (key === 'b') {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square turns white when the user presses the left arrow key. It turns black when the user presses the right arrow key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the background color when the user presses an arrow key.
- * function keyPressed() {
- * if (keyCode === LEFT_ARROW) {
- * value = 255;
- * } else if (keyCode === RIGHT_ARROW) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square changes color when the user presses a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the background color when the user presses a key.
+ * function keyPressed() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The inner square turns black when the user presses the "b" key. It turns white when the user presses the "a" key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Reassign value when the user presses the 'a' or 'b' key.
+ * function keyPressed() {
+ * if (key === 'a') {
+ * value = 255;
+ * } else if (key === 'b') {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square turns white when the user presses the left arrow key. It turns black when the user presses the right arrow key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the background color when the user presses an arrow key.
+ * function keyPressed() {
+ * if (keyCode === LEFT_ARROW) {
+ * value = 255;
+ * } else if (keyCode === RIGHT_ARROW) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square changes color when the user releases a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle value when the user releases a key.
- * function keyReleased() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes white when the user releases the "w" key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Set value to 255 the user releases the 'w' key.
- * function keyReleased() {
- * if (key === 'w') {
- * value = 255;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square turns white when the user presses and releases the left arrow key. It turns black when the user presses and releases the right arrow key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the background color when the user releases an arrow key.
- * function keyReleased() {
- * if (keyCode === LEFT_ARROW) {
- * value = 255;
- * } else if (keyCode === RIGHT_ARROW) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square changes color when the user releases a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle value when the user releases a key.
+ * function keyReleased() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes white when the user releases the "w" key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Set value to 255 the user releases the 'w' key.
+ * function keyReleased() {
+ * if (key === 'w') {
+ * value = 255;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square turns white when the user presses and releases the left arrow key. It turns black when the user presses and releases the right arrow key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the background color when the user releases an arrow key.
+ * function keyReleased() {
+ * if (keyCode === LEFT_ARROW) {
+ * value = 255;
+ * } else if (keyCode === RIGHT_ARROW) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- * // Note: Pressing special keys such as SPACE have no effect.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The inner square changes color when the user presses a key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the square's color when the user types a printable key.
- * function keyTyped() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The inner square turns black when the user types the "b" key. It turns white when the user types the "a" key.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Reassign value when the user types the 'a' or 'b' key.
- * function keyTyped() {
- * if (key === 'a') {
- * value = 255;
- * } else if (key === 'b') {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ * // Note: Pressing special keys such as SPACE have no effect.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The inner square changes color when the user presses a key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the square's color when the user types a printable key.
+ * function keyTyped() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The inner square turns black when the user types the "b" key. It turns white when the user types the "a" key.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Reassign value when the user types the 'a' or 'b' key.
+ * function keyTyped() {
+ * if (key === 'a') {
+ * value = 255;
+ * } else if (key === 'b') {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * // Click on the canvas to begin detecting key presses.
- *
- * let x = 50;
- * let y = 50;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * describe(
- * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
- * );
- * }
- *
- * function draw() {
- * // Update x and y if an arrow key is pressed.
- * if (keyIsDown(LEFT_ARROW) === true) {
- * x -= 1;
- * }
- *
- * if (keyIsDown(RIGHT_ARROW) === true) {
- * x += 1;
- * }
- *
- * if (keyIsDown(UP_ARROW) === true) {
- * y -= 1;
- * }
- *
- * if (keyIsDown(DOWN_ARROW) === true) {
- * y += 1;
- * }
- *
- * // Style the circle.
- * fill(0);
- *
- * // Draw the circle.
- * circle(x, y, 5);
- * }
- *
- *
- * // Click on the canvas to begin detecting key presses.
- *
- * let x = 50;
- * let y = 50;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * describe(
- * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
- * );
- * }
- *
- * function draw() {
- * // Update x and y if an arrow key is pressed.
- * if (keyIsDown(37) === true) {
- * x -= 1;
- * }
- *
- * if (keyIsDown(39) === true) {
- * x += 1;
- * }
- *
- * if (keyIsDown(38) === true) {
- * y -= 1;
- * }
- *
- * if (keyIsDown(40) === true) {
- * y += 1;
- * }
- *
- * // Style the circle.
- * fill(0);
- *
- * // Draw the circle.
- * circle(x, y, 5);
- * }
- *
- *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let x = 50;
+ * let y = 50;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * describe(
+ * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * // Update x and y if an arrow key is pressed.
+ * if (keyIsDown(LEFT_ARROW) === true) {
+ * x -= 1;
+ * }
+ *
+ * if (keyIsDown(RIGHT_ARROW) === true) {
+ * x += 1;
+ * }
+ *
+ * if (keyIsDown(UP_ARROW) === true) {
+ * y -= 1;
+ * }
+ *
+ * if (keyIsDown(DOWN_ARROW) === true) {
+ * y += 1;
+ * }
+ *
+ * // Style the circle.
+ * fill(0);
+ *
+ * // Draw the circle.
+ * circle(x, y, 5);
+ * }
+ *
+ *
+ * // Click on the canvas to begin detecting key presses.
+ *
+ * let x = 50;
+ * let y = 50;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * describe(
+ * 'A gray square with a black circle at its center. The circle moves when the user presses an arrow key. It leaves a trail as it moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * // Update x and y if an arrow key is pressed.
+ * if (keyIsDown(37) === true) {
+ * x -= 1;
+ * }
+ *
+ * if (keyIsDown(39) === true) {
+ * x += 1;
+ * }
+ *
+ * if (keyIsDown(38) === true) {
+ * y -= 1;
+ * }
+ *
+ * if (keyIsDown(40) === true) {
+ * y += 1;
+ * }
+ *
+ * // Style the circle.
+ * fill(0);
+ *
+ * // Draw the circle.
+ * circle(x, y, 5);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. The text ">>" appears when the user moves the mouse to the right. The text "<<" appears when the user moves the mouse to the left.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display >> when movedX is positive and
- * // << when it's negative.
- * if (movedX > 0) {
- * text('>>', 50, 50);
- * } else if (movedX < 0) {
- * text('<<', 50, 50);
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. The text ">>" appears when the user moves the mouse to the right. The text "<<" appears when the user moves the mouse to the left.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display >> when movedX is positive and
+ * // << when it's negative.
+ * if (movedX > 0) {
+ * text('>>', 50, 50);
+ * } else if (movedX < 0) {
+ * text('<<', 50, 50);
+ * }
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. The text "▲" appears when the user moves the mouse upward. The text "▼" appears when the user moves the mouse downward.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display ▼ when movedY is positive and
- * // ▲ when it's negative.
- * if (movedY > 0) {
- * text('▼', 50, 50);
- * } else if (movedY < 0) {
- * text('▲', 50, 50);
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. The text "▲" appears when the user moves the mouse upward. The text "▼" appears when the user moves the mouse downward.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display ▼ when movedY is positive and
+ * // ▲ when it's negative.
+ * if (movedY > 0) {
+ * text('▼', 50, 50);
+ * } else if (movedY < 0) {
+ * text('▲', 50, 50);
+ * }
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A vertical black line moves left and right following the mouse's x-position.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Draw a vertical line that follows the mouse's x-coordinate.
- * line(mouseX, 0, mouseX, 100);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouse's coordinates.
- * text(`x: ${mouseX} y: ${mouseY}`, 50, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe("A vertical black line moves left and right following the mouse's x-position.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Adjust coordinates for WebGL mode.
- * // The origin (0, 0) is at the center of the canvas.
- * let mx = mouseX - 50;
- *
- * // Draw the line.
- * line(mx, -50, mx, 50);
- * }
- *
- *
- * let font;
- *
- * // Load a font for WebGL mode.
- * function preload() {
- * font = loadFont('assets/inconsolata.otf');
- * }
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe(
- * "A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse."
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- * textFont(font);
- * fill(0);
- *
- * // Display the mouse's coordinates.
- * text(`x: ${mouseX} y: ${mouseY}`, 0, 0);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A vertical black line moves left and right following the mouse's x-position.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Draw a vertical line that follows the mouse's x-coordinate.
+ * line(mouseX, 0, mouseX, 100);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouse's coordinates.
+ * text(`x: ${mouseX} y: ${mouseY}`, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe("A vertical black line moves left and right following the mouse's x-position.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Adjust coordinates for WebGL mode.
+ * // The origin (0, 0) is at the center of the canvas.
+ * let mx = mouseX - 50;
+ *
+ * // Draw the line.
+ * line(mx, -50, mx, 50);
+ * }
+ *
+ *
+ * let font;
+ *
+ * // Load a font for WebGL mode.
+ * function preload() {
+ * font = loadFont('assets/inconsolata.otf');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe(
+ * "A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse."
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ * textFont(font);
+ * fill(0);
+ *
+ * // Display the mouse's coordinates.
+ * text(`x: ${mouseX} y: ${mouseY}`, 0, 0);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A horizontal black line moves up and down following the mouse's y-position.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Draw a horizontal line that follows the mouse's y-coordinate.
- * line(0, mouseY, 0, mouseY);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouse's coordinates.
- * text(`x: ${mouseX} y: ${mouseY}`, 50, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe("A horizontal black line moves up and down following the mouse's y-position.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Adjust coordinates for WebGL mode.
- * // The origin (0, 0) is at the center of the canvas.
- * let my = mouseY - 50;
- *
- * // Draw the line.
- * line(-50, my, 50, my);
- * }
- *
- *
- * let font;
- *
- * // Load a font for WebGL mode.
- * function preload() {
- * font = loadFont('assets/inconsolata.otf');
- * }
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe(
- * "A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse."
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- * textFont(font);
- * fill(0);
- *
- * // Display the mouse's coordinates.
- * text(`x: ${mouseX} y: ${mouseY}`, 0, 0);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A horizontal black line moves up and down following the mouse's y-position.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Draw a horizontal line that follows the mouse's y-coordinate.
+ * line(0, mouseY, 0, mouseY);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouse's coordinates.
+ * text(`x: ${mouseX} y: ${mouseY}`, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe("A horizontal black line moves up and down following the mouse's y-position.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Adjust coordinates for WebGL mode.
+ * // The origin (0, 0) is at the center of the canvas.
+ * let my = mouseY - 50;
+ *
+ * // Draw the line.
+ * line(-50, my, 50, my);
+ * }
+ *
+ *
+ * let font;
+ *
+ * // Load a font for WebGL mode.
+ * function preload() {
+ * font = loadFont('assets/inconsolata.otf');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe(
+ * "A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse."
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ * textFont(font);
+ * fill(0);
+ *
+ * // Display the mouse's coordinates.
+ * text(`x: ${mouseX} y: ${mouseY}`, 0, 0);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Slow the frame rate.
- * frameRate(10);
- *
- * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * line(pmouseX, pmouseY, mouseX, mouseY);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Adjust coordinates for WebGL mode.
- * // The origin (0, 0) is at the center of the canvas.
- * let pmx = pmouseX - 50;
- * let pmy = pmouseY - 50;
- * let mx = mouseX - 50;
- * let my = mouseY - 50;
- *
- * // Draw the line.
- * line(pmx, pmy, mx, my);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Slow the frame rate.
+ * frameRate(10);
+ *
+ * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * line(pmouseX, pmouseY, mouseX, mouseY);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Adjust coordinates for WebGL mode.
+ * // The origin (0, 0) is at the center of the canvas.
+ * let pmx = pmouseX - 50;
+ * let pmy = pmouseY - 50;
+ * let mx = mouseX - 50;
+ * let my = mouseY - 50;
+ *
+ * // Draw the line.
+ * line(pmx, pmy, mx, my);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Slow the frame rate.
- * frameRate(10);
- *
- * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * line(pmouseX, pmouseY, mouseX, mouseY);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100, WEBGL);
- *
- * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Adjust coordinates for WebGL mode.
- * // The origin (0, 0) is at the center of the canvas.
- * let pmx = pmouseX - 50;
- * let pmy = pmouseY - 50;
- * let mx = mouseX - 50;
- * let my = mouseY - 50;
- *
- * // Draw the line.
- * line(pmx, pmy, mx, my);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Slow the frame rate.
+ * frameRate(10);
+ *
+ * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * line(pmouseX, pmouseY, mouseX, mouseY);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100, WEBGL);
+ *
+ * describe('A line follows the mouse as it moves. The line grows longer with faster movements.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Adjust coordinates for WebGL mode.
+ * // The origin (0, 0) is at the center of the canvas.
+ * let pmx = pmouseX - 50;
+ * let pmy = pmouseY - 50;
+ * let mx = mouseX - 50;
+ * let my = mouseY - 50;
+ *
+ * // Draw the line.
+ * line(pmx, pmy, mx, my);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouse's coordinates within the browser window.
- * text(`x: ${winMouseX} y: ${winMouseY}`, 50, 50);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouse's coordinates within the browser window.
+ * text(`x: ${winMouseX} y: ${winMouseY}`, 50, 50);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouse's coordinates within the browser window.
- * text(`x: ${winMouseX} y: ${winMouseY}`, 50, 50);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe("A gray square. The mouse's x- and y-coordinates are displayed as the user moves the mouse.");
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouse's coordinates within the browser window.
+ * text(`x: ${winMouseX} y: ${winMouseY}`, 50, 50);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Slow the frame rate.
- * frameRate(10);
- *
- * describe('A gray square. A white circle at its center grows larger when the mouse moves horizontally.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Calculate the circle's diameter.
- * let d = winMouseX - pwinMouseX;
- *
- * // Draw the circle.
- * circle(50, 50, d);
- * }
- *
- *
- * function setup() {
- * // Create the canvas and set its position.
- * let cnv = createCanvas(100, 100);
- * cnv.position(20, 20);
- *
- * describe('A gray square with a number at its center. The number changes as the user moves the mouse vertically.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display pwinMouseX.
- * text(pwinMouseX, 50, 50);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Slow the frame rate.
+ * frameRate(10);
+ *
+ * describe('A gray square. A white circle at its center grows larger when the mouse moves horizontally.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Calculate the circle's diameter.
+ * let d = winMouseX - pwinMouseX;
+ *
+ * // Draw the circle.
+ * circle(50, 50, d);
+ * }
+ *
+ *
+ * function setup() {
+ * // Create the canvas and set its position.
+ * let cnv = createCanvas(100, 100);
+ * cnv.position(20, 20);
+ *
+ * describe('A gray square with a number at its center. The number changes as the user moves the mouse vertically.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display pwinMouseX.
+ * text(pwinMouseX, 50, 50);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Slow the frame rate.
- * frameRate(10);
- *
- * describe('A gray square. A white circle at its center grows larger when the mouse moves vertically.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Calculate the circle's diameter.
- * let d = winMouseY - pwinMouseY;
- *
- * // Draw the circle.
- * circle(50, 50, d);
- * }
- *
- *
- * function setup() {
- * // Create the canvas and set its position.
- * let cnv = createCanvas(100, 100);
- * cnv.position(20, 20);
- *
- * describe('A gray square with a number at its center. The number changes as the user moves the mouse vertically.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display pwinMouseY.
- * text(pwinMouseY, 50, 50);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Slow the frame rate.
+ * frameRate(10);
+ *
+ * describe('A gray square. A white circle at its center grows larger when the mouse moves vertically.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Calculate the circle's diameter.
+ * let d = winMouseY - pwinMouseY;
+ *
+ * // Draw the circle.
+ * circle(50, 50, d);
+ * }
+ *
+ *
+ * function setup() {
+ * // Create the canvas and set its position.
+ * let cnv = createCanvas(100, 100);
+ * cnv.position(20, 20);
+ *
+ * describe('A gray square with a number at its center. The number changes as the user moves the mouse vertically.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display pwinMouseY.
+ * text(pwinMouseY, 50, 50);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with black text at its center. The text changes from 0 to either "left" or "right" when the user clicks a mouse button.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouse button.
- * text(mouseButton, 50, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * "A gray square. Different shapes appear at its center depending on the mouse button that's clicked."
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * if (mouseIsPressed === true) {
- * if (mouseButton === LEFT) {
- * circle(50, 50, 50);
- * }
- * if (mouseButton === RIGHT) {
- * square(25, 25, 50);
- * }
- * if (mouseButton === CENTER) {
- * triangle(23, 75, 50, 20, 78, 75);
- * }
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with black text at its center. The text changes from 0 to either "left" or "right" when the user clicks a mouse button.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouse button.
+ * text(mouseButton, 50, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * "A gray square. Different shapes appear at its center depending on the mouse button that's clicked."
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * if (mouseIsPressed === true) {
+ * if (mouseButton === LEFT) {
+ * circle(50, 50, 50);
+ * }
+ * if (mouseButton === RIGHT) {
+ * square(25, 25, 50);
+ * }
+ * if (mouseButton === CENTER) {
+ * triangle(23, 75, 50, 20, 78, 75);
+ * }
+ * }
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the word "false" at its center. The word changes to "true" when the user presses a mouse button.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the mouseIsPressed variable.
- * text(mouseIsPressed, 25, 50);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a white square at its center. The inner square turns black when the user presses the mouse.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * if (mouseIsPressed === true) {
- * fill(0);
- * } else {
- * fill(255);
- * }
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the word "false" at its center. The word changes to "true" when the user presses a mouse button.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the mouseIsPressed variable.
+ * text(mouseIsPressed, 25, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a white square at its center. The inner square turns black when the user presses the mouse.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * if (mouseIsPressed === true) {
+ * fill(0);
+ * } else {
+ * fill(255);
+ * }
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes lighter as the mouse moves.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * function mouseMoved() {
- * // Update the grayscale value.
- * value += 5;
- *
- * // Reset the grayscale value.
- * if (value > 255) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes lighter as the mouse moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * function mouseMoved() {
+ * // Update the grayscale value.
+ * value += 5;
+ *
+ * // Reset the grayscale value.
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes lighter as the user drags the mouse.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * function mouseDragged() {
- * // Update the grayscale value.
- * value += 5;
- *
- * // Reset the grayscale value.
- * if (value > 255) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes lighter as the user drags the mouse.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * function mouseDragged() {
+ * // Update the grayscale value.
+ * value += 5;
+ *
+ * // Reset the grayscale value.
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes lighter when the user presses a mouse button.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * function mousePressed() {
+ * // Update the grayscale value.
+ * value += 5;
+ *
+ * // Reset the grayscale value.
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Style the circle.
+ * fill('orange');
+ * stroke('royalblue');
+ * strokeWeight(10);
+ *
+ * describe(
+ * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(220);
+ *
+ * // Draw the circle.
+ * circle(50, 50, 20);
+ * }
+ *
+ * // Set the stroke color and weight as soon as the user clicks.
+ * function mousePressed() {
+ * stroke('deeppink');
+ * strokeWeight(3);
+ * }
+ *
+ * // Set the stroke and fill colors as soon as the user releases
+ * // the mouse.
+ * function mouseReleased() {
+ * stroke('royalblue');
+ *
+ * // This is never visible because fill() is called
+ * // in mouseClicked() which runs immediately after
+ * // mouseReleased();
+ * fill('limegreen');
+ * }
+ *
+ * // Set the fill color and stroke weight after
+ * // mousePressed() and mouseReleased() are called.
+ * function mouseClicked() {
+ * fill('orange');
+ * strokeWeight(10);
+ * }
+ *
+ *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes lighter when the user presses a mouse button.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * function mousePressed() {
- * // Update the grayscale value.
- * value += 5;
- *
- * // Reset the grayscale value.
- * if (value > 255) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Style the circle.
- * fill('orange');
- * stroke('royalblue');
- * strokeWeight(10);
- *
- * describe(
- * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
- * );
- * }
- *
- * function draw() {
- * background(220);
- *
- * // Draw the circle.
- * circle(50, 50, 20);
- * }
- *
- * // Set the stroke color and weight as soon as the user clicks.
- * function mousePressed() {
- * stroke('deeppink');
- * strokeWeight(3);
- * }
- *
- * // Set the stroke and fill colors as soon as the user releases
- * // the mouse.
- * function mouseReleased() {
- * stroke('royalblue');
- *
- * // This is never visible because fill() is called
- * // in mouseClicked() which runs immediately after
- * // mouseReleased();
- * fill('limegreen');
- * }
- *
- * // Set the fill color and stroke weight after
- * // mousePressed() and mouseReleased() are called.
- * function mouseClicked() {
- * fill('orange');
- * strokeWeight(10);
- * }
- *
- *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes lighter when the user presses and releases a mouse button.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * function mouseReleased() {
+ * // Update the grayscale value.
+ * value += 5;
+ *
+ * // Reset the grayscale value.
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Style the circle.
+ * fill('orange');
+ * stroke('royalblue');
+ * strokeWeight(10);
+ *
+ * describe(
+ * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(220);
+ *
+ * // Draw the circle.
+ * circle(50, 50, 20);
+ * }
+ *
+ * // Set the stroke color and weight as soon as the user clicks.
+ * function mousePressed() {
+ * stroke('deeppink');
+ * strokeWeight(3);
+ * }
+ *
+ * // Set the stroke and fill colors as soon as the user releases
+ * // the mouse.
+ * function mouseReleased() {
+ * stroke('royalblue');
+ *
+ * // This is never visible because fill() is called
+ * // in mouseClicked() which runs immediately after
+ * // mouseReleased();
+ * fill('limegreen');
+ * }
+ *
+ * // Set the fill color and stroke weight after
+ * // mousePressed() and mouseReleased() are called.
+ * function mouseClicked() {
+ * fill('orange');
+ * strokeWeight(10);
+ * }
+ *
+ *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes lighter when the user presses and releases a mouse button.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * function mouseReleased() {
- * // Update the grayscale value.
- * value += 5;
- *
- * // Reset the grayscale value.
- * if (value > 255) {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Style the circle.
- * fill('orange');
- * stroke('royalblue');
- * strokeWeight(10);
- *
- * describe(
- * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
- * );
- * }
- *
- * function draw() {
- * background(220);
- *
- * // Draw the circle.
- * circle(50, 50, 20);
- * }
- *
- * // Set the stroke color and weight as soon as the user clicks.
- * function mousePressed() {
- * stroke('deeppink');
- * strokeWeight(3);
- * }
- *
- * // Set the stroke and fill colors as soon as the user releases
- * // the mouse.
- * function mouseReleased() {
- * stroke('royalblue');
- *
- * // This is never visible because fill() is called
- * // in mouseClicked() which runs immediately after
- * // mouseReleased();
- * fill('limegreen');
- * }
- *
- * // Set the fill color and stroke weight after
- * // mousePressed() and mouseReleased() are called.
- * function mouseClicked() {
- * fill('orange');
- * strokeWeight(10);
- * }
- *
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square changes color when the user presses and releases a mouse button.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the square's color when the user clicks.
- * function mouseClicked() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Style the circle.
- * fill('orange');
- * stroke('royalblue');
- * strokeWeight(10);
- *
- * describe(
- * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
- * );
- * }
- *
- * function draw() {
- * background(220);
- *
- * // Draw the circle.
- * circle(50, 50, 20);
- * }
- *
- * // Set the stroke color and weight as soon as the user clicks.
- * function mousePressed() {
- * stroke('deeppink');
- * strokeWeight(3);
- * }
- *
- * // Set the stroke and fill colors as soon as the user releases
- * // the mouse.
- * function mouseReleased() {
- * stroke('royalblue');
- *
- * // This is never visible because fill() is called
- * // in mouseClicked() which runs immediately after
- * // mouseReleased();
- * fill('limegreen');
- * }
- *
- * // Set the fill color and stroke weight after
- * // mousePressed() and mouseReleased() are called.
- * function mouseClicked() {
- * fill('orange');
- * strokeWeight(10);
- * }
- *
- *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square changes color when the user presses and releases a mouse button.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the square's color when the user clicks.
+ * function mouseClicked() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Style the circle.
+ * fill('orange');
+ * stroke('royalblue');
+ * strokeWeight(10);
+ *
+ * describe(
+ * 'An orange circle with a thick, blue border drawn on a gray background. When the user presses and holds the mouse, the border becomes thin and pink. When the user releases the mouse, the border becomes thicker and changes color to blue.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(220);
+ *
+ * // Draw the circle.
+ * circle(50, 50, 20);
+ * }
+ *
+ * // Set the stroke color and weight as soon as the user clicks.
+ * function mousePressed() {
+ * stroke('deeppink');
+ * strokeWeight(3);
+ * }
+ *
+ * // Set the stroke and fill colors as soon as the user releases
+ * // the mouse.
+ * function mouseReleased() {
+ * stroke('royalblue');
+ *
+ * // This is never visible because fill() is called
+ * // in mouseClicked() which runs immediately after
+ * // mouseReleased();
+ * fill('limegreen');
+ * }
+ *
+ * // Set the fill color and stroke weight after
+ * // mousePressed() and mouseReleased() are called.
+ * function mouseClicked() {
+ * fill('orange');
+ * strokeWeight(10);
+ * }
+ *
+ *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square changes color when the user double-clicks.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle the square's color when the user double-clicks.
- * function doubleClicked() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black circle at its center. When the user double-clicks on the circle, it changes color to white.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the circle.
- * fill(value);
- *
- * // Draw the circle.
- * circle(50, 50, 80);
- * }
- *
- * // Reassign value to 255 when the user double-clicks on the circle.
- * function doubleClicked() {
- * if (dist(50, 50, mouseX, mouseY) < 40) {
- * value = 255;
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square changes color when the user double-clicks.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle the square's color when the user double-clicks.
+ * function doubleClicked() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black circle at its center. When the user double-clicks on the circle, it changes color to white.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the circle.
+ * fill(value);
+ *
+ * // Draw the circle.
+ * circle(50, 50, 80);
+ * }
+ *
+ * // Reassign value to 255 when the user double-clicks on the circle.
+ * function doubleClicked() {
+ * if (dist(50, 50, mouseX, mouseY) < 40) {
+ * value = 255;
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * let circleSize = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. A white circle at its center grows up when the user scrolls the mouse wheel.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Draw the circle
- * circle(circleSize, 50, 50);
- * }
- *
- * // Increment circleSize when the user scrolls the mouse wheel.
- * function mouseWheel() {
- * circleSize += 1;
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
- * let direction = '';
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. An arrow at its center points up when the user scrolls up. The arrow points down when the user scrolls down.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Draw an arrow that points where
- * // the mouse last scrolled.
- * text(direction, 50, 50);
- * }
- *
- * // Change direction when the user scrolls the mouse wheel.
- * function mouseWheel(event) {
- * if (event.delta > 0) {
- * direction = '▲';
- * } else {
- * direction = '▼';
- * }
- * // Uncomment to prevent any default behavior.
- * // return false;
- * }
- *
- *
+ * let circleSize = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. A white circle at its center grows up when the user scrolls the mouse wheel.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Draw the circle
+ * circle(circleSize, 50, 50);
+ * }
+ *
+ * // Increment circleSize when the user scrolls the mouse wheel.
+ * function mouseWheel() {
+ * circleSize += 1;
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
+ * let direction = '';
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. An arrow at its center points up when the user scrolls up. The arrow points down when the user scrolls down.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Draw an arrow that points where
+ * // the mouse last scrolled.
+ * text(direction, 50, 50);
+ * }
+ *
+ * // Change direction when the user scrolls the mouse wheel.
+ * function mouseWheel(event) {
+ * if (event.delta > 0) {
+ * direction = '▲';
+ * } else {
+ * direction = '▼';
+ * }
+ * // Uncomment to prevent any default behavior.
+ * // return false;
+ * }
+ *
+ *
- * let score = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the text "Score: X" at its center. The score increases when the user moves the mouse upward. It decreases when the user moves the mouse downward.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Update the score.
- * score -= movedY;
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Display the score.
- * text(`Score: ${score}`, 50, 50);
- * }
- *
- * // Lock the pointer when the user double-clicks.
- * function doubleClicked() {
- * requestPointerLock();
- * }
- *
- *
+ * let score = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the text "Score: X" at its center. The score increases when the user moves the mouse upward. It decreases when the user moves the mouse downward.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Update the score.
+ * score -= movedY;
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Display the score.
+ * text(`Score: ${score}`, 50, 50);
+ * }
+ *
+ * // Lock the pointer when the user double-clicks.
+ * function doubleClicked() {
+ * requestPointerLock();
+ * }
+ *
+ *
- * let isLocked = false;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a word at its center. The word changes between "Unlocked" and "Locked" when the user double-clicks.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- *
- * // Tell the user whether the pointer is locked.
- * if (isLocked === true) {
- * text('Locked', 50, 50);
- * } else {
- * text('Unlocked', 50, 50);
- * }
- * }
- *
- * // Toggle the pointer lock when the user double-clicks.
- * function doubleClicked() {
- * if (isLocked === true) {
- * exitPointerLock();
- * isLocked = false;
- * } else {
- * requestPointerLock();
- * isLocked = true;
- * }
- * }
- *
- *
+ * let isLocked = false;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a word at its center. The word changes between "Unlocked" and "Locked" when the user double-clicks.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ *
+ * // Tell the user whether the pointer is locked.
+ * if (isLocked === true) {
+ * text('Locked', 50, 50);
+ * } else {
+ * text('Unlocked', 50, 50);
+ * }
+ * }
+ *
+ * // Toggle the pointer lock when the user double-clicks.
+ * function doubleClicked() {
+ * if (isLocked === true) {
+ * exitPointerLock();
+ * isLocked = false;
+ * } else {
+ * requestPointerLock();
+ * isLocked = true;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. White circles appear where the user touches the square.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Draw a circle at each touch point.
+ * for (let touch of touches) {
+ * circle(touch.x, touch.y, 40);
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square. Labels appear where the user touches the square, displaying the coordinates.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Draw a label above each touch point.
+ * for (let touch of touches) {
+ * text(`${touch.x}, ${touch.y}`, touch.x, touch.y - 40);
+ * }
+ * }
+ *
+ *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. White circles appear where the user touches the square.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Draw a circle at each touch point.
- * for (let touch of touches) {
- * circle(touch.x, touch.y, 40);
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square. Labels appear where the user touches the square, displaying the coordinates.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Draw a label above each touch point.
- * for (let touch of touches) {
- * text(`${touch.x}, ${touch.y}`, touch.x, touch.y - 40);
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square switches color between black and white each time the user touches the screen.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle colors with each touch.
- * function touchStarted() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let bgColor = 50;
- * let fillColor = 255;
- * let borderWidth = 0.5;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
- * );
- * }
- *
- * function draw() {
- * background(bgColor);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- * fill(0);
- * noStroke();
- *
- * // Display the number of touch points.
- * text(touches.length, 50, 20);
- *
- * // Style the touch points.
- * fill(fillColor);
- * stroke(0);
- * strokeWeight(borderWidth);
- *
- * // Display the touch points as circles.
- * for (let touch of touches) {
- * circle(touch.x, touch.y, 40);
- * }
- * }
- *
- * // Set the background color to a random grayscale value.
- * function touchStarted() {
- * bgColor = random(80, 255);
- * }
- *
- * // Set the fill color to a random grayscale value.
- * function touchEnded() {
- * fillColor = random(0, 255);
- * }
- *
- * // Set the stroke weight.
- * function touchMoved() {
- * // Increment the border width.
- * borderWidth += 0.1;
- *
- * // Reset the border width once it's too thick.
- * if (borderWidth > 20) {
- * borderWidth = 0.5;
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square becomes lighter when the user touches the screen and moves.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * function touchMoved() {
- * // Update the grayscale value.
- * value += 5;
- *
- * // Reset the grayscale value.
- * if (value > 255) {
- * value = 0;
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let bgColor = 50;
- * let fillColor = 255;
- * let borderWidth = 0.5;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
- * );
- * }
- *
- * function draw() {
- * background(bgColor);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- * fill(0);
- * noStroke();
- *
- * // Display the number of touch points.
- * text(touches.length, 50, 20);
- *
- * // Style the touch points.
- * fill(fillColor);
- * stroke(0);
- * strokeWeight(borderWidth);
- *
- * // Display the touch points as circles.
- * for (let touch of touches) {
- * circle(touch.x, touch.y, 40);
- * }
- * }
- *
- * // Set the background color to a random grayscale value.
- * function touchStarted() {
- * bgColor = random(80, 255);
- * }
- *
- * // Set the fill color to a random grayscale value.
- * function touchEnded() {
- * fillColor = random(0, 255);
- * }
- *
- * // Set the stroke weight.
- * function touchMoved() {
- * // Increment the border width.
- * borderWidth += 0.1;
- *
- * // Reset the border width once it's too thick.
- * if (borderWidth > 20) {
- * borderWidth = 0.5;
- * }
- * }
- *
- *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square switches color between black and white each time the user touches the screen.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle colors with each touch.
+ * function touchStarted() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let bgColor = 50;
+ * let fillColor = 255;
+ * let borderWidth = 0.5;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(bgColor);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ * fill(0);
+ * noStroke();
+ *
+ * // Display the number of touch points.
+ * text(touches.length, 50, 20);
+ *
+ * // Style the touch points.
+ * fill(fillColor);
+ * stroke(0);
+ * strokeWeight(borderWidth);
+ *
+ * // Display the touch points as circles.
+ * for (let touch of touches) {
+ * circle(touch.x, touch.y, 40);
+ * }
+ * }
+ *
+ * // Set the background color to a random grayscale value.
+ * function touchStarted() {
+ * bgColor = random(80, 255);
+ * }
+ *
+ * // Set the fill color to a random grayscale value.
+ * function touchEnded() {
+ * fillColor = random(0, 255);
+ * }
+ *
+ * // Set the stroke weight.
+ * function touchMoved() {
+ * // Increment the border width.
+ * borderWidth += 0.1;
+ *
+ * // Reset the border width once it's too thick.
+ * if (borderWidth > 20) {
+ * borderWidth = 0.5;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square becomes lighter when the user touches the screen and moves.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * function touchMoved() {
+ * // Update the grayscale value.
+ * value += 5;
+ *
+ * // Reset the grayscale value.
+ * if (value > 255) {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let bgColor = 50;
+ * let fillColor = 255;
+ * let borderWidth = 0.5;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(bgColor);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ * fill(0);
+ * noStroke();
+ *
+ * // Display the number of touch points.
+ * text(touches.length, 50, 20);
+ *
+ * // Style the touch points.
+ * fill(fillColor);
+ * stroke(0);
+ * strokeWeight(borderWidth);
+ *
+ * // Display the touch points as circles.
+ * for (let touch of touches) {
+ * circle(touch.x, touch.y, 40);
+ * }
+ * }
+ *
+ * // Set the background color to a random grayscale value.
+ * function touchStarted() {
+ * bgColor = random(80, 255);
+ * }
+ *
+ * // Set the fill color to a random grayscale value.
+ * function touchEnded() {
+ * fillColor = random(0, 255);
+ * }
+ *
+ * // Set the stroke weight.
+ * function touchMoved() {
+ * // Increment the border width.
+ * borderWidth += 0.1;
+ *
+ * // Reset the border width once it's too thick.
+ * if (borderWidth > 20) {
+ * borderWidth = 0.5;
+ * }
+ * }
+ *
+ *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let value = 0;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with a black square at its center. The inner square switches color between black and white each time the user stops touching the screen.'
- * );
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the square.
- * fill(value);
- *
- * // Draw the square.
- * square(25, 25, 50);
- * }
- *
- * // Toggle colors when a touch ends.
- * function touchEnded() {
- * if (value === 0) {
- * value = 255;
- * } else {
- * value = 0;
- * }
- * }
- *
- *
- * // On a touchscreen device, touch the canvas using one or more fingers
- * // at the same time.
- *
- * let bgColor = 50;
- * let fillColor = 255;
- * let borderWidth = 0.5;
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe(
- * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
- * );
- * }
- *
- * function draw() {
- * background(bgColor);
- *
- * // Style the text.
- * textAlign(CENTER);
- * textSize(16);
- * fill(0);
- * noStroke();
- *
- * // Display the number of touch points.
- * text(touches.length, 50, 20);
- *
- * // Style the touch points.
- * fill(fillColor);
- * stroke(0);
- * strokeWeight(borderWidth);
- *
- * // Display the touch points as circles.
- * for (let touch of touches) {
- * circle(touch.x, touch.y, 40);
- * }
- * }
- *
- * // Set the background color to a random grayscale value.
- * function touchStarted() {
- * bgColor = random(80, 255);
- * }
- *
- * // Set the fill color to a random grayscale value.
- * function touchEnded() {
- * fillColor = random(0, 255);
- * }
- *
- * // Set the stroke weight.
- * function touchMoved() {
- * // Increment the border width.
- * borderWidth += 0.1;
- *
- * // Reset the border width once it's too thick.
- * if (borderWidth > 20) {
- * borderWidth = 0.5;
- * }
- * }
- *
- *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let value = 0;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with a black square at its center. The inner square switches color between black and white each time the user stops touching the screen.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the square.
+ * fill(value);
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ * }
+ *
+ * // Toggle colors when a touch ends.
+ * function touchEnded() {
+ * if (value === 0) {
+ * value = 255;
+ * } else {
+ * value = 0;
+ * }
+ * }
+ *
+ *
+ * // On a touchscreen device, touch the canvas using one or more fingers
+ * // at the same time.
+ *
+ * let bgColor = 50;
+ * let fillColor = 255;
+ * let borderWidth = 0.5;
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe(
+ * 'A gray square with the number 0 at the top-center. The number tracks the number of places the user is touching the screen. Circles appear at each touch point and change style in response to events.'
+ * );
+ * }
+ *
+ * function draw() {
+ * background(bgColor);
+ *
+ * // Style the text.
+ * textAlign(CENTER);
+ * textSize(16);
+ * fill(0);
+ * noStroke();
+ *
+ * // Display the number of touch points.
+ * text(touches.length, 50, 20);
+ *
+ * // Style the touch points.
+ * fill(fillColor);
+ * stroke(0);
+ * strokeWeight(borderWidth);
+ *
+ * // Display the touch points as circles.
+ * for (let touch of touches) {
+ * circle(touch.x, touch.y, 40);
+ * }
+ * }
+ *
+ * // Set the background color to a random grayscale value.
+ * function touchStarted() {
+ * bgColor = random(80, 255);
+ * }
+ *
+ * // Set the fill color to a random grayscale value.
+ * function touchEnded() {
+ * fillColor = random(0, 255);
+ * }
+ *
+ * // Set the stroke weight.
+ * function touchMoved() {
+ * // Increment the border width.
+ * borderWidth += 0.1;
+ *
+ * // Reset the border width once it's too thick.
+ * if (borderWidth > 20) {
+ * borderWidth = 0.5;
+ * }
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels into memory.
- * img.loadPixels();
- *
- * // Set all the image's pixels to black.
- * for (let x = 0; x < img.width; x += 1) {
- * for (let y = 0; y < img.height; y += 1) {
- * img.set(x, y, 0);
- * }
- * }
- *
- * // Update the image's pixel values.
- * img.updatePixels();
- *
- * // Draw the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels into memory.
- * img.loadPixels();
- *
- * // Create a color gradient.
- * for (let x = 0; x < img.width; x += 1) {
- * for (let y = 0; y < img.height; y += 1) {
- * // Calculate the transparency.
- * let a = map(x, 0, img.width, 0, 255);
- *
- * // Create a p5.Color object.
- * let c = color(0, a);
- *
- * // Set the pixel's color.
- * img.set(x, y, c);
- * }
- * }
- *
- * // Update the image's pixels.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A square with a horizontal color gradient that transitions from gray to black.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the pixels into memory.
- * img.loadPixels();
- * // Get the current pixel density.
- * let d = pixelDensity();
- *
- * // Calculate the pixel that is halfway through the image's pixel array.
- * let halfImage = 4 * (d * img.width) * (d * img.height / 2);
- *
- * // Set half of the image's pixels to black.
- * for (let i = 0; i < halfImage; i += 4) {
- * // Red.
- * img.pixels[i] = 0;
- * // Green.
- * img.pixels[i + 1] = 0;
- * // Blue.
- * img.pixels[i + 2] = 0;
- * // Alpha.
- * img.pixels[i + 3] = 255;
- * }
- *
- * // Update the image's pixels.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the image's pixels into memory.
+ * img.loadPixels();
+ *
+ * // Set all the image's pixels to black.
+ * for (let x = 0; x < img.width; x += 1) {
+ * for (let y = 0; y < img.height; y += 1) {
+ * img.set(x, y, 0);
+ * }
+ * }
+ *
+ * // Update the image's pixel values.
+ * img.updatePixels();
+ *
+ * // Draw the image.
+ * image(img, 17, 17);
+ *
+ * describe('A black square drawn in the middle of a gray square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the image's pixels into memory.
+ * img.loadPixels();
+ *
+ * // Create a color gradient.
+ * for (let x = 0; x < img.width; x += 1) {
+ * for (let y = 0; y < img.height; y += 1) {
+ * // Calculate the transparency.
+ * let a = map(x, 0, img.width, 0, 255);
+ *
+ * // Create a p5.Color object.
+ * let c = color(0, a);
+ *
+ * // Set the pixel's color.
+ * img.set(x, y, c);
+ * }
+ * }
+ *
+ * // Update the image's pixels.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A square with a horizontal color gradient that transitions from gray to black.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the pixels into memory.
+ * img.loadPixels();
+ * // Get the current pixel density.
+ * let d = pixelDensity();
+ *
+ * // Calculate the pixel that is halfway through the image's pixel array.
+ * let halfImage = 4 * (d * img.width) * (d * img.height / 2);
+ *
+ * // Set half of the image's pixels to black.
+ * for (let i = 0; i < halfImage; i += 4) {
+ * // Red.
+ * img.pixels[i] = 0;
+ * // Green.
+ * img.pixels[i + 1] = 0;
+ * // Blue.
+ * img.pixels[i + 2] = 0;
+ * // Alpha.
+ * img.pixels[i + 3] = 255;
+ * }
+ *
+ * // Update the image's pixels.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A black square drawn in the middle of a gray square.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- * background(255);
- *
- * // Save the canvas to 'untitled.png'.
- * saveCanvas();
- *
- * describe('A white square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(255);
- *
- * // Save the canvas to 'myCanvas.jpg'.
- * saveCanvas('myCanvas.jpg');
- *
- * describe('A white square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(255);
- *
- * // Save the canvas to 'myCanvas.jpg'.
- * saveCanvas('myCanvas', 'jpg');
- *
- * describe('A white square.');
- * }
- *
- *
- * function setup() {
- * let cnv = createCanvas(100, 100);
- *
- * background(255);
- *
- * // Save the canvas to 'untitled.png'.
- * saveCanvas(cnv);
- *
- * describe('A white square.');
- * }
- *
- *
- * function setup() {
- * let cnv = createCanvas(100, 100);
- *
- * background(255);
- *
- * // Save the canvas to 'myCanvas.jpg'.
- * saveCanvas(cnv, 'myCanvas.jpg');
- *
- * describe('A white square.');
- * }
- *
- *
- * function setup() {
- * let cnv = createCanvas(100, 100);
- *
- * background(255);
- *
- * // Save the canvas to 'myCanvas.jpg'.
- * saveCanvas(cnv, 'myCanvas', 'jpg');
- *
- * describe('A white square.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(255);
+ *
+ * // Save the canvas to 'untitled.png'.
+ * saveCanvas();
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Save the canvas to 'myCanvas.jpg'.
+ * saveCanvas('myCanvas.jpg');
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Save the canvas to 'myCanvas.jpg'.
+ * saveCanvas('myCanvas', 'jpg');
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Save the canvas to 'untitled.png'.
+ * saveCanvas(cnv);
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Save the canvas to 'myCanvas.jpg'.
+ * saveCanvas(cnv, 'myCanvas.jpg');
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
+ * function setup() {
+ * let cnv = createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Save the canvas to 'myCanvas.jpg'.
+ * saveCanvas(cnv, 'myCanvas', 'jpg');
+ *
+ * describe('A white square.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A square repeatedly changes color from blue to pink.');
- * }
- *
- * function draw() {
- * let r = frameCount % 255;
- * let g = 50;
- * let b = 100;
- * background(r, g, b);
- * }
- *
- * // Save the frames when the user presses the 's' key.
- * function keyPressed() {
- * if (key === 's') {
- * saveFrames('frame', 'png', 1, 5);
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A square repeatedly changes color from blue to pink.');
- * }
- *
- * function draw() {
- * let r = frameCount % 255;
- * let g = 50;
- * let b = 100;
- * background(r, g, b);
- * }
- *
- * // Print 5 frames when the user presses the mouse.
- * function mousePressed() {
- * saveFrames('frame', 'png', 1, 5, printFrames);
- * }
- *
- * // Prints an array of objects containing raw image data, filenames, and extensions.
- * function printFrames(frames) {
- * for (let frame of frames) {
- * print(frame);
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A square repeatedly changes color from blue to pink.');
+ * }
+ *
+ * function draw() {
+ * let r = frameCount % 255;
+ * let g = 50;
+ * let b = 100;
+ * background(r, g, b);
+ * }
+ *
+ * // Save the frames when the user presses the 's' key.
+ * function keyPressed() {
+ * if (key === 's') {
+ * saveFrames('frame', 'png', 1, 5);
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A square repeatedly changes color from blue to pink.');
+ * }
+ *
+ * function draw() {
+ * let r = frameCount % 255;
+ * let g = 50;
+ * let b = 100;
+ * background(r, g, b);
+ * }
+ *
+ * // Print 5 frames when the user presses the mouse.
+ * function mousePressed() {
+ * saveFrames('frame', 'png', 1, 5, printFrames);
+ * }
+ *
+ * // Prints an array of objects containing raw image data, filenames, and extensions.
+ * function printFrames(frames) {
+ * for (let frame of frames) {
+ * print(frame);
+ * }
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image and create a p5.Image object.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Draw the image.
+ * image(img, 0, 0);
+ *
+ * describe('Image of the underside of a white umbrella and a gridded ceiling.');
+ * }
+ *
+ *
+ * function setup() {
+ * // Call handleImage() once the image loads.
+ * loadImage('assets/laDefense.jpg', handleImage);
+ *
+ * describe('Image of the underside of a white umbrella and a gridded ceiling.');
+ * }
+ *
+ * // Display the image.
+ * function handleImage(img) {
+ * image(img, 0, 0);
+ * }
+ *
+ *
+ * function setup() {
+ * // Call handleImage() once the image loads or
+ * // call handleError() if an error occurs.
+ * loadImage('assets/laDefense.jpg', handleImage, handleError);
+ * }
+ *
+ * // Display the image.
+ * function handleImage(img) {
+ * image(img, 0, 0);
+ *
+ * describe('Image of the underside of a white umbrella and a gridded ceiling.');
+ * }
+ *
+ * // Log the error.
+ * function handleError(event) {
+ * console.error('Oops!', event);
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image and create a p5.Image object.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Draw the image.
- * image(img, 0, 0);
- *
- * describe('Image of the underside of a white umbrella and a gridded ceiling.');
- * }
- *
- *
- * function setup() {
- * // Call handleImage() once the image loads.
- * loadImage('assets/laDefense.jpg', handleImage);
- *
- * describe('Image of the underside of a white umbrella and a gridded ceiling.');
- * }
- *
- * // Display the image.
- * function handleImage(img) {
- * image(img, 0, 0);
- * }
- *
- *
- * function setup() {
- * // Call handleImage() once the image loads or
- * // call handleError() if an error occurs.
- * loadImage('assets/laDefense.jpg', handleImage, handleError);
- * }
- *
- * // Display the image.
- * function handleImage(img) {
- * image(img, 0, 0);
- *
- * describe('Image of the underside of a white umbrella and a gridded ceiling.');
- * }
- *
- * // Log the error.
- * function handleError(event) {
- * console.error('Oops!', event);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A circle drawn in the middle of a gray square. The circle changes color from black to white, then repeats.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the circle.
- * let c = frameCount % 255;
- * fill(c);
- *
- * // Display the circle.
- * circle(50, 50, 25);
- * }
- *
- * // Save a 5-second gif when the user presses the 's' key.
- * function keyPressed() {
- * if (key === 's') {
- * saveGif('mySketch', 5);
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A circle drawn in the middle of a gray square. The circle changes color from black to white, then repeats.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Style the circle.
- * let c = frameCount % 255;
- * fill(c);
- *
- * // Display the circle.
- * circle(50, 50, 25);
- * }
- *
- * // Save a 5-second gif when the user presses the 's' key.
- * // Wait 1 second after the key press before recording.
- * function keyPressed() {
- * if (key === 's') {
- * saveGif('mySketch', 5, { delay: 1 });
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A circle drawn in the middle of a gray square. The circle changes color from black to white, then repeats.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the circle.
+ * let c = frameCount % 255;
+ * fill(c);
+ *
+ * // Display the circle.
+ * circle(50, 50, 25);
+ * }
+ *
+ * // Save a 5-second gif when the user presses the 's' key.
+ * function keyPressed() {
+ * if (key === 's') {
+ * saveGif('mySketch', 5);
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A circle drawn in the middle of a gray square. The circle changes color from black to white, then repeats.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Style the circle.
+ * let c = frameCount % 255;
+ * fill(c);
+ *
+ * // Display the circle.
+ * circle(50, 50, 25);
+ * }
+ *
+ * // Save a 5-second gif when the user presses the 's' key.
+ * // Wait 1 second after the key press before recording.
+ * function keyPressed() {
+ * if (key === 's') {
+ * saveGif('mySketch', 5, { delay: 1 });
+ * }
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the image.
- * image(img, 0, 0);
- *
- * describe('An image of the underside of a white umbrella with a gridded ceiling above.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the image.
- * image(img, 10, 10);
- *
- * describe('An image of the underside of a white umbrella with a gridded ceiling above. The image has dark gray borders on its left and top.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the image 50x50.
- * image(img, 0, 0, 50, 50);
- *
- * describe('An image of the underside of a white umbrella with a gridded ceiling above. The image is drawn in the top left corner of a dark gray square.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the center of the image.
- * image(img, 25, 25, 50, 50, 25, 25, 50, 50);
- *
- * describe('An image of a gridded ceiling drawn in the center of a dark gray square.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/moonwalk.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the image and scale it to fit within the canvas.
- * image(img, 0, 0, width, height, 0, 0, img.width, img.height, CONTAIN);
- *
- * describe('An image of an astronaut on the moon. The top and bottom borders of the image are dark gray.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * // Image is 50 x 50 pixels.
- * img = loadImage('assets/laDefense50.png');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(50);
- *
- * // Draw the image and scale it to cover the canvas.
- * image(img, 0, 0, width, height, 0, 0, img.width, img.height, COVER);
- *
- * describe('A pixelated image of the underside of a white umbrella with a gridded ceiling above.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the image.
+ * image(img, 0, 0);
+ *
+ * describe('An image of the underside of a white umbrella with a gridded ceiling above.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the image.
+ * image(img, 10, 10);
+ *
+ * describe('An image of the underside of a white umbrella with a gridded ceiling above. The image has dark gray borders on its left and top.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the image 50x50.
+ * image(img, 0, 0, 50, 50);
+ *
+ * describe('An image of the underside of a white umbrella with a gridded ceiling above. The image is drawn in the top left corner of a dark gray square.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the center of the image.
+ * image(img, 25, 25, 50, 50, 25, 25, 50, 50);
+ *
+ * describe('An image of a gridded ceiling drawn in the center of a dark gray square.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/moonwalk.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the image and scale it to fit within the canvas.
+ * image(img, 0, 0, width, height, 0, 0, img.width, img.height, CONTAIN);
+ *
+ * describe('An image of an astronaut on the moon. The top and bottom borders of the image are dark gray.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * // Image is 50 x 50 pixels.
+ * img = loadImage('assets/laDefense50.png');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(50);
+ *
+ * // Draw the image and scale it to cover the canvas.
+ * image(img, 0, 0, width, height, 0, 0, img.width, img.height, COVER);
+ *
+ * describe('A pixelated image of the underside of a white umbrella with a gridded ceiling above.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Left image.
- * image(img, 0, 0);
- *
- * // Right image.
- * // Tint with a CSS color string.
- * tint('red');
- * image(img, 50, 0);
- *
- * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Left image.
- * image(img, 0, 0);
- *
- * // Right image.
- * // Tint with RGB values.
- * tint(255, 0, 0);
- * image(img, 50, 0);
- *
- * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Left.
- * image(img, 0, 0);
- *
- * // Right.
- * // Tint with RGBA values.
- * tint(255, 0, 0, 100);
- * image(img, 50, 0);
- *
- * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a transparent red tint.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Left.
- * image(img, 0, 0);
- *
- * // Right.
- * // Tint with grayscale and alpha values.
- * tint(255, 180);
- * image(img, 50, 0);
- *
- * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right is transparent.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/laDefense.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Left.
- * // Tint with a CSS color string.
- * tint('red');
- * image(img, 0, 0);
- *
- * // Right.
- * // Remove the tint.
- * noTint();
- * image(img, 50, 0);
- *
- * describe('Two images of an umbrella and a ceiling side-by-side. The image on the left has a red tint.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use CORNER mode.
- * imageMode(CORNER);
- *
- * // Display the image.
- * image(img, 10, 10, 50, 50);
- *
- * describe('A square image of a brick wall is drawn at the top left of a gray square.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use CORNERS mode.
- * imageMode(CORNERS);
- *
- * // Display the image.
- * image(img, 10, 10, 90, 40);
- *
- * describe('An image of a brick wall is drawn on a gray square. The image is squeezed into a small rectangular area.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Use CENTER mode.
- * imageMode(CENTER);
- *
- * // Display the image.
- * image(img, 50, 50, 80, 80);
- *
- * describe('A square image of a brick wall is drawn on a gray square.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Left image.
+ * image(img, 0, 0);
+ *
+ * // Right image.
+ * // Tint with a CSS color string.
+ * tint('red');
+ * image(img, 50, 0);
+ *
+ * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Left image.
+ * image(img, 0, 0);
+ *
+ * // Right image.
+ * // Tint with RGB values.
+ * tint(255, 0, 0);
+ * image(img, 50, 0);
+ *
+ * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a red tint.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Left.
+ * image(img, 0, 0);
+ *
+ * // Right.
+ * // Tint with RGBA values.
+ * tint(255, 0, 0, 100);
+ * image(img, 50, 0);
+ *
+ * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right has a transparent red tint.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Left.
+ * image(img, 0, 0);
+ *
+ * // Right.
+ * // Tint with grayscale and alpha values.
+ * tint(255, 180);
+ * image(img, 50, 0);
+ *
+ * describe('Two images of an umbrella and a ceiling side-by-side. The image on the right is transparent.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/laDefense.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Left.
+ * // Tint with a CSS color string.
+ * tint('red');
+ * image(img, 0, 0);
+ *
+ * // Right.
+ * // Remove the tint.
+ * noTint();
+ * image(img, 50, 0);
+ *
+ * describe('Two images of an umbrella and a ceiling side-by-side. The image on the left has a red tint.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use CORNER mode.
+ * imageMode(CORNER);
+ *
+ * // Display the image.
+ * image(img, 10, 10, 50, 50);
+ *
+ * describe('A square image of a brick wall is drawn at the top left of a gray square.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use CORNERS mode.
+ * imageMode(CORNERS);
+ *
+ * // Display the image.
+ * image(img, 10, 10, 90, 40);
+ *
+ * describe('An image of a brick wall is drawn on a gray square. The image is squeezed into a small rectangular area.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Use CENTER mode.
+ * imageMode(CENTER);
+ *
+ * // Display the image.
+ * image(img, 50, 50, 80, 80);
+ *
+ * describe('A square image of a brick wall is drawn on a gray square.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('An image of a brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the GRAY filter.
- * img.filter(GRAY);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A grayscale image of a brick wall.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels.
- * img.loadPixels();
- *
- * // Set the pixels to black.
- * for (let x = 0; x < img.width; x += 1) {
- * for (let y = 0; y < img.height; y += 1) {
- * img.set(x, y, 0);
- * }
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('An image of a brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the GRAY filter.
+ * img.filter(GRAY);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A grayscale image of a brick wall.');
+ * }
+ *
+ *
* function setup() {
* createCanvas(100, 100);
*
@@ -246,7 +100,244 @@ p5.Image = class Image {
*
*
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the image's pixels.
+ * img.loadPixels();
+ *
+ * // Set the pixels to black.
+ * for (let x = 0; x < img.width; x += 1) {
+ * for (let y = 0; y < img.height; y += 1) {
+ * img.set(x, y, 0);
+ * }
+ * }
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A black square drawn in the middle of a gray square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the image's pixels.
+ * img.loadPixels();
+ *
+ * for (let i = 0; i < img.pixels.length; i += 4) {
+ * // Red.
+ * img.pixels[i] = 0;
+ * // Green.
+ * img.pixels[i + 1] = 0;
+ * // Blue.
+ * img.pixels[i + 2] = 0;
+ * // Alpha.
+ * img.pixels[i + 3] = 255;
+ * }
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A black square drawn in the middle of a gray square.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Load the image's pixels.
+ * img.loadPixels();
+ *
+ * // Set the pixels to black.
+ * for (let x = 0; x < img.width; x += 1) {
+ * for (let y = 0; y < img.height; y += 1) {
+ * img.set(x, y, 0);
+ * }
+ * }
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A black square drawn in the middle of a gray square.');
+ * }
+ *
+ *
* function setup() {
* createCanvas(100, 100);
@@ -259,6 +350,7 @@ p5.Image = class Image {
* // Load the image's pixels.
* img.loadPixels();
*
+ * // Set the pixels to black.
* for (let i = 0; i < img.pixels.length; i += 4) {
* // Red.
* img.pixels[i] = 0;
@@ -280,1160 +372,1476 @@ p5.Image = class Image {
* }
*
*
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels.
- * img.loadPixels();
- *
- * // Set the pixels to black.
- * for (let x = 0; x < img.width; x += 1) {
- * for (let y = 0; y < img.height; y += 1) {
- * img.set(x, y, 0);
- * }
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels.
- * img.loadPixels();
- *
- * // Set the pixels to black.
- * for (let i = 0; i < img.pixels.length; i += 4) {
- * // Red.
- * img.pixels[i] = 0;
- * // Green.
- * img.pixels[i + 1] = 0;
- * // Blue.
- * img.pixels[i + 2] = 0;
- * // Alpha.
- * img.pixels[i + 3] = 255;
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Copy the image.
- * let img2 = get();
- *
- * // Display the copied image on the right.
- * image(img2, 50, 0);
- *
- * describe('Two identical mountain landscapes shown side-by-side.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Get a pixel's color.
- * let c = img.get(50, 90);
- *
- * // Style the square using the pixel's color.
- * fill(c);
- * noStroke();
- *
- * // Draw the square.
- * square(25, 25, 50);
- *
- * describe('A mountain landscape with an olive green square in its center.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Copy half of the image.
- * let img2 = img.get(0, 0, img.width / 2, img.height / 2);
- *
- * // Display half of the image.
- * image(img2, 50, 50);
- *
- * describe('A mountain landscape drawn on top of another mountain landscape.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Copy the image.
+ * let img2 = get();
+ *
+ * // Display the copied image on the right.
+ * image(img2, 50, 0);
+ *
+ * describe('Two identical mountain landscapes shown side-by-side.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Get a pixel's color.
+ * let c = img.get(50, 90);
+ *
+ * // Style the square using the pixel's color.
+ * fill(c);
+ * noStroke();
+ *
+ * // Draw the square.
+ * square(25, 25, 50);
+ *
+ * describe('A mountain landscape with an olive green square in its center.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Copy half of the image.
+ * let img2 = img.get(0, 0, img.width / 2, img.height / 2);
+ *
+ * // Display half of the image.
+ * image(img2, 50, 50);
+ *
+ * describe('A mountain landscape drawn on top of another mountain landscape.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(100, 100);
- *
- * // Set four pixels to black.
- * img.set(30, 20, 0);
- * img.set(85, 20, 0);
- * img.set(85, 75, 0);
- * img.set(30, 75, 0);
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('Four black dots arranged in a square drawn on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(100, 100);
- *
- * // Create a p5.Color object.
- * let black = color(0);
- *
- * // Set four pixels to black.
- * img.set(30, 20, black);
- * img.set(85, 20, black);
- * img.set(85, 75, black);
- * img.set(30, 75, black);
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('Four black dots arranged in a square drawn on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Draw a color gradient.
- * for (let x = 0; x < img.width; x += 1) {
- * for (let y = 0; y < img.height; y += 1) {
- * let c = map(x, 0, img.width, 0, 255);
- * img.set(x, y, c);
- * }
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A square with a horiztonal color gradient from black to white drawn on a gray background.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create a p5.Image object.
- * let img2 = createImage(100, 100);
- *
- * // Set the blank image's pixels using the landscape.
- * img2.set(0, 0, img);
- *
- * // Display the second image.
- * image(img2, 0, 0);
- *
- * describe('An image of a mountain landscape.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Resize the image.
- * img.resize(50, 100);
- *
- * // Display the resized image.
- * image(img, 0, 0);
- *
- * describe('Two images of a mountain landscape. One copy of the image is squeezed horizontally.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Resize the image, keeping the aspect ratio.
- * img.resize(0, 30);
- *
- * // Display the resized image.
- * image(img, 0, 0);
- *
- * describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Resize the image, keeping the aspect ratio.
- * img.resize(60, 0);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(100, 100);
+ *
+ * // Set four pixels to black.
+ * img.set(30, 20, 0);
+ * img.set(85, 20, 0);
+ * img.set(85, 75, 0);
+ * img.set(30, 75, 0);
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('Four black dots arranged in a square drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(100, 100);
+ *
+ * // Create a p5.Color object.
+ * let black = color(0);
+ *
+ * // Set four pixels to black.
+ * img.set(30, 20, black);
+ * img.set(85, 20, black);
+ * img.set(85, 75, black);
+ * img.set(30, 75, black);
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('Four black dots arranged in a square drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
+ *
+ * // Draw a color gradient.
+ * for (let x = 0; x < img.width; x += 1) {
+ * for (let y = 0; y < img.height; y += 1) {
+ * let c = map(x, 0, img.width, 0, 255);
+ * img.set(x, y, c);
+ * }
+ * }
+ *
+ * // Update the image.
+ * img.updatePixels();
+ *
+ * // Display the image.
+ * image(img, 17, 17);
+ *
+ * describe('A square with a horiztonal color gradient from black to white drawn on a gray background.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create a p5.Image object.
+ * let img2 = createImage(100, 100);
+ *
+ * // Set the blank image's pixels using the landscape.
+ * img2.set(0, 0, img);
+ *
+ * // Display the second image.
+ * image(img2, 0, 0);
+ *
+ * describe('An image of a mountain landscape.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Resize the image.
+ * img.resize(50, 100);
+ *
+ * // Display the resized image.
+ * image(img, 0, 0);
+ *
+ * describe('Two images of a mountain landscape. One copy of the image is squeezed horizontally.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Resize the image, keeping the aspect ratio.
+ * img.resize(0, 30);
+ *
+ * // Display the resized image.
+ * image(img, 0, 0);
+ *
+ * describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Resize the image, keeping the aspect ratio.
+ * img.resize(60, 0);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('Two images of a mountain landscape. The small copy of the image covers the top-left corner of the larger image.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Copy one region of the image to another.
+ * img.copy(7, 22, 10, 10, 35, 25, 50, 50);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Outline the copied region.
+ * stroke(255);
+ * noFill();
+ * square(7, 22, 10);
+ *
+ * describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.');
+ * }
+ *
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * // Load the images.
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Calculate the center of the bricks image.
+ * let x = bricks.width / 2;
+ * let y = bricks.height / 2;
+ *
+ * // Copy the bricks to the mountains image.
+ * mountains.copy(bricks, 0, 0, x, y, 0, 0, x, y);
+ *
+ * // Display the mountains image.
+ * image(mountains, 0, 0);
+ *
+ * describe('An image of a brick wall drawn at the top-left of an image of a mountain landscape.');
+ * }
+ *
+ *
+ * let photo;
+ * let maskImage;
+ *
+ * // Load the images.
+ * function preload() {
+ * photo = loadImage('assets/rockies.jpg');
+ * maskImage = loadImage('assets/mask2.png');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the mask.
+ * photo.mask(maskImage);
+ *
+ * // Display the image.
+ * image(photo, 0, 0);
+ *
+ * describe('An image of a mountain landscape. The right side of the image has a faded patch of white.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the INVERT filter.
+ * img.filter(INVERT);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A blue brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the GRAY filter.
+ * img.filter(GRAY);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A brick wall drawn in grayscale.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the THRESHOLD filter.
+ * img.filter(THRESHOLD);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A brick wall drawn in black and white.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the OPAQUE filter.
+ * img.filter(OPAQUE);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A red brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the POSTERIZE filter.
+ * img.filter(POSTERIZE, 3);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('An image of a red brick wall drawn with a limited color palette.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the BLUR filter.
+ * img.filter(BLUR, 3);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A blurry image of a red brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the DILATE filter.
+ * img.filter(DILATE);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A red brick wall with bright lines between each brick.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Apply the ERODE filter.
+ * img.filter(ERODE);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('A red brick wall with faint lines between each brick.');
+ * }
+ *
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * // Load the images.
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Blend the bricks image into the mountains.
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
+ *
+ * // Display the mountains image.
+ * image(mountains, 0, 0);
+ *
+ * // Display the bricks image.
+ * image(bricks, 0, 0);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.');
+ * }
+ *
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * // Load the images.
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Blend the bricks image into the mountains.
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
+ *
+ * // Display the mountains image.
+ * image(mountains, 0, 0);
+ *
+ * // Display the bricks image.
+ * image(bricks, 0, 0);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.');
+ * }
+ *
+ *
+ * let mountains;
+ * let bricks;
+ *
+ * // Load the images.
+ * function preload() {
+ * mountains = loadImage('assets/rockies.jpg');
+ * bricks = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Blend the bricks image into the mountains.
+ * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
+ *
+ * // Display the mountains image.
+ * image(mountains, 0, 0);
+ *
+ * // Display the bricks image.
+ * image(bricks, 0, 0);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * describe('An image of a mountain landscape. The image is downloaded when the user presses the "s", "j", or "p" key.');
+ * }
+ *
+ * // Save the image with different options when the user presses a key.
+ * function keyPressed() {
+ * if (key === 's') {
+ * img.save();
+ * } else if (key === 'j') {
+ * img.save('rockies.jpg');
+ * } else if (key === 'p') {
+ * img.save('rockies', 'png');
+ * }
+ * }
+ *
+ *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-wink-loop-once.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A cartoon face winks once and then freezes. Clicking resets the face and makes it wink again.');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ *
+ * // Display the image.
+ * image(gif, 0, 0);
+ * }
+ *
+ * // Reset the GIF when the user presses the mouse.
+ * function mousePressed() {
+ * gif.reset();
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Copy one region of the image to another.
- * img.copy(7, 22, 10, 10, 35, 25, 50, 50);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Outline the copied region.
- * stroke(255);
- * noFill();
- * square(7, 22, 10);
- *
- * describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.');
- * }
- *
- *
- * let mountains;
- * let bricks;
- *
- * // Load the images.
- * function preload() {
- * mountains = loadImage('assets/rockies.jpg');
- * bricks = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Calculate the center of the bricks image.
- * let x = bricks.width / 2;
- * let y = bricks.height / 2;
- *
- * // Copy the bricks to the mountains image.
- * mountains.copy(bricks, 0, 0, x, y, 0, 0, x, y);
- *
- * // Display the mountains image.
- * image(mountains, 0, 0);
- *
- * describe('An image of a brick wall drawn at the top-left of an image of a mountain landscape.');
- * }
- *
- *
- * let photo;
- * let maskImage;
- *
- * // Load the images.
- * function preload() {
- * photo = loadImage('assets/rockies.jpg');
- * maskImage = loadImage('assets/mask2.png');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the mask.
- * photo.mask(maskImage);
- *
- * // Display the image.
- * image(photo, 0, 0);
- *
- * describe('An image of a mountain landscape. The right side of the image has a faded patch of white.');
- * }
- *
- *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A cartoon eye repeatedly looks around, then outwards. A number displayed in the bottom-left corner increases from 0 to 124, then repeats.');
+ * }
+ *
+ * function draw() {
+ * // Get the index of the current GIF frame.
+ * let index = gif.getCurrentFrame();
+ *
+ * // Display the image.
+ * image(gif, 0, 0);
+ *
+ * // Display the current frame.
+ * text(index, 10, 90);
+ * }
+ *
+ *
+ * let gif;
+ * let frameSlider;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Get the index of the last frame.
+ * let maxFrame = gif.numFrames() - 1;
+ *
+ * // Create a slider to control which frame is drawn.
+ * frameSlider = createSlider(0, maxFrame);
+ * frameSlider.position(10, 80);
+ * frameSlider.size(80);
+ *
+ * describe('A cartoon eye looks around when a slider is moved.');
+ * }
+ *
+ * function draw() {
+ * // Get the slider's value.
+ * let index = frameSlider.value();
+ *
+ * // Set the GIF's frame.
+ * gif.setFrame(index);
+ *
+ * // Display the image.
+ * image(gif, 0, 0);
+ * }
+ *
+ *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A cartoon eye looks around. The text "n / 125" is shown at the bottom of the canvas.');
+ * }
+ *
+ * function draw() {
+ * // Display the image.
+ * image(gif, 0, 0);
+ *
+ * // Display the current state of playback.
+ * let total = gif.numFrames();
+ * let index = gif.getCurrentFrame();
+ * text(`${index} / ${total}`, 30, 90);
+ * }
+ *
+ *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ * image(gif, 0, 0);
+ * }
+ *
+ * // Pause the GIF when the user presses the mouse.
+ * function mousePressed() {
+ * gif.pause();
+ * }
+ *
+ * // Play the GIF when the user releases the mouse.
+ * function mouseReleased() {
+ * gif.play();
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the INVERT filter.
- * img.filter(INVERT);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A blue brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the GRAY filter.
- * img.filter(GRAY);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A brick wall drawn in grayscale.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the THRESHOLD filter.
- * img.filter(THRESHOLD);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A brick wall drawn in black and white.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the OPAQUE filter.
- * img.filter(OPAQUE);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A red brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the POSTERIZE filter.
- * img.filter(POSTERIZE, 3);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('An image of a red brick wall drawn with a limited color palette.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the BLUR filter.
- * img.filter(BLUR, 3);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A blurry image of a red brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the DILATE filter.
- * img.filter(DILATE);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A red brick wall with bright lines between each brick.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Apply the ERODE filter.
- * img.filter(ERODE);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * describe('A red brick wall with faint lines between each brick.');
- * }
- *
- *
- * let mountains;
- * let bricks;
- *
- * // Load the images.
- * function preload() {
- * mountains = loadImage('assets/rockies.jpg');
- * bricks = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Blend the bricks image into the mountains.
- * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
- *
- * // Display the mountains image.
- * image(mountains, 0, 0);
- *
- * // Display the bricks image.
- * image(bricks, 0, 0);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.');
- * }
- *
- *
- * let mountains;
- * let bricks;
- *
- * // Load the images.
- * function preload() {
- * mountains = loadImage('assets/rockies.jpg');
- * bricks = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Blend the bricks image into the mountains.
- * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
- *
- * // Display the mountains image.
- * image(mountains, 0, 0);
- *
- * // Display the bricks image.
- * image(bricks, 0, 0);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.');
- * }
- *
- *
- * let mountains;
- * let bricks;
- *
- * // Load the images.
- * function preload() {
- * mountains = loadImage('assets/rockies.jpg');
- * bricks = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Blend the bricks image into the mountains.
- * mountains.blend(bricks, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
- *
- * // Display the mountains image.
- * image(mountains, 0, 0);
- *
- * // Display the bricks image.
- * image(bricks, 0, 0);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.');
- * }
- *
- *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.');
+ * }
+ *
+ * function draw() {
+ * background(255);
+ *
+ * // Display the image.
+ * image(gif, 0, 0);
+ * }
+ *
+ * // Pause the GIF when the user presses the mouse.
+ * function mousePressed() {
+ * gif.pause();
+ * }
+ *
+ * // Play the GIF when the user presses the mouse.
+ * function mouseReleased() {
+ * gif.play();
+ * }
+ *
+ *
+ * let gifFast;
+ * let gifSlow;
+ *
+ * // Load the images.
+ * function preload() {
+ * gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Resize the images.
+ * gifFast.resize(50, 50);
+ * gifSlow.resize(50, 50);
+ *
+ * // Set the delay lengths.
+ * gifFast.delay(10);
+ * gifSlow.delay(100);
+ *
+ * describe('Two animated eyes looking around. The eye on the left moves faster than the eye on the right.');
+ * }
+ *
+ * function draw() {
+ * // Display the images.
+ * image(gifFast, 0, 0);
+ * image(gifSlow, 50, 0);
+ * }
+ *
+ *
+ * let gif;
+ *
+ * // Load the image.
+ * function preload() {
+ * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Set the delay of frame 67.
+ * gif.delay(3000, 67);
+ *
+ * describe('An animated eye looking around. It pauses for three seconds while it looks down.');
+ * }
+ *
+ * function draw() {
+ * // Display the image.
+ * image(gif, 0, 0);
+ * }
+ *
+ *
- * let gif;
- *
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/arnott-wallace-wink-loop-once.gif');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A cartoon face winks once and then freezes. Clicking resets the face and makes it wink again.');
- * }
- *
- * function draw() {
- * background(255);
- *
- * // Display the image.
- * image(gif, 0, 0);
- * }
- *
- * // Reset the GIF when the user presses the mouse.
- * function mousePressed() {
- * gif.reset();
- * }
- *
- *
- * let gif;
- *
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A cartoon eye repeatedly looks around, then outwards. A number displayed in the bottom-left corner increases from 0 to 124, then repeats.');
- * }
- *
- * function draw() {
- * // Get the index of the current GIF frame.
- * let index = gif.getCurrentFrame();
+ * // Calculate the center coordinates.
+ * let x = img.width / 2;
+ * let y = img.height / 2;
*
- * // Display the image.
- * image(gif, 0, 0);
+ * // Draw a circle at the image's center.
+ * circle(x, y, 20);
*
- * // Display the current frame.
- * text(index, 10, 90);
+ * describe('An image of a mountain landscape with a white circle drawn in the middle.');
* }
*
*
- * let gif;
- * let frameSlider;
+ * let img;
*
* // Load the image.
* function preload() {
- * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
+ * img = loadImage('assets/rockies.jpg');
* }
*
* function setup() {
* createCanvas(100, 100);
*
- * // Get the index of the last frame.
- * let maxFrame = gif.numFrames() - 1;
- *
- * // Create a slider to control which frame is drawn.
- * frameSlider = createSlider(0, maxFrame);
- * frameSlider.position(10, 80);
- * frameSlider.size(80);
- *
- * describe('A cartoon eye looks around when a slider is moved.');
- * }
- *
- * function draw() {
- * // Get the slider's value.
- * let index = frameSlider.value();
- *
- * // Set the GIF's frame.
- * gif.setFrame(index);
- *
* // Display the image.
- * image(gif, 0, 0);
- * }
- *
- *
- * let gif;
- *
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
+ * image(img, 0, 0);
*
- * describe('A cartoon eye looks around. The text "n / 125" is shown at the bottom of the canvas.');
- * }
+ * // Calculate the center coordinates.
+ * let x = img.width / 2;
+ * let y = img.height / 2;
*
- * function draw() {
- * // Display the image.
- * image(gif, 0, 0);
+ * // Draw a circle at the image's center.
+ * circle(x, y, 20);
*
- * // Display the current state of playback.
- * let total = gif.numFrames();
- * let index = gif.getCurrentFrame();
- * text(`${index} / ${total}`, 30, 90);
+ * describe('An image of a mountain landscape with a white circle drawn in the middle.');
* }
*
*
- * let gif;
- *
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
- * }
- *
* function setup() {
* createCanvas(100, 100);
*
- * describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.');
- * }
- *
- * function draw() {
- * background(255);
- * image(gif, 0, 0);
- * }
- *
- * // Pause the GIF when the user presses the mouse.
- * function mousePressed() {
- * gif.pause();
- * }
- *
- * // Play the GIF when the user releases the mouse.
- * function mouseReleased() {
- * gif.play();
- * }
- *
- *
- * let gif;
+ * background(200);
*
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/nancy-liang-wind-loop-forever.gif');
- * }
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
*
- * function setup() {
- * createCanvas(100, 100);
+ * // Load the image's pixels.
+ * img.loadPixels();
*
- * describe('A drawing of a child with hair blowing in the wind. The animation freezes when clicked and resumes when released.');
- * }
+ * for (let i = 0; i < img.pixels.length; i += 4) {
+ * // Red.
+ * img.pixels[i] = 0;
+ * // Green.
+ * img.pixels[i + 1] = 0;
+ * // Blue.
+ * img.pixels[i + 2] = 0;
+ * // Alpha.
+ * img.pixels[i + 3] = 255;
+ * }
*
- * function draw() {
- * background(255);
+ * // Update the image.
+ * img.updatePixels();
*
* // Display the image.
- * image(gif, 0, 0);
- * }
- *
- * // Pause the GIF when the user presses the mouse.
- * function mousePressed() {
- * gif.pause();
- * }
+ * image(img, 17, 17);
*
- * // Play the GIF when the user presses the mouse.
- * function mouseReleased() {
- * gif.play();
+ * describe('A black square drawn in the middle of a gray square.');
* }
*
*
- * let gifFast;
- * let gifSlow;
- *
- * // Load the images.
- * function preload() {
- * gifFast = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
- * gifSlow = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
- * }
- *
* function setup() {
* createCanvas(100, 100);
*
* background(200);
*
- * // Resize the images.
- * gifFast.resize(50, 50);
- * gifSlow.resize(50, 50);
- *
- * // Set the delay lengths.
- * gifFast.delay(10);
- * gifSlow.delay(100);
- *
- * describe('Two animated eyes looking around. The eye on the left moves faster than the eye on the right.');
- * }
- *
- * function draw() {
- * // Display the images.
- * image(gifFast, 0, 0);
- * image(gifSlow, 50, 0);
- * }
- *
- *
- * let gif;
- *
- * // Load the image.
- * function preload() {
- * gif = loadImage('assets/arnott-wallace-eye-loop-forever.gif');
- * }
+ * // Create a p5.Image object.
+ * let img = createImage(66, 66);
*
- * function setup() {
- * createCanvas(100, 100);
+ * // Load the image's pixels.
+ * img.loadPixels();
*
- * // Set the delay of frame 67.
- * gif.delay(3000, 67);
+ * // Set the pixels to red.
+ * for (let i = 0; i < img.pixels.length; i += 4) {
+ * // Red.
+ * img.pixels[i] = 255;
+ * // Green.
+ * img.pixels[i + 1] = 0;
+ * // Blue.
+ * img.pixels[i + 2] = 0;
+ * // Alpha.
+ * img.pixels[i + 3] = 255;
+ * }
*
- * describe('An animated eye looking around. It pauses for three seconds while it looks down.');
- * }
+ * // Update the image.
+ * img.updatePixels();
*
- * function draw() {
* // Display the image.
- * image(gif, 0, 0);
+ * image(img, 17, 17);
+ *
+ * describe('A red square drawn in the middle of a gray square.');
* }
*
*
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Calculate the center coordinates.
- * let x = img.width / 2;
- * let y = img.height / 2;
- *
- * // Draw a circle at the image's center.
- * circle(x, y, 20);
- *
- * describe('An image of a mountain landscape with a white circle drawn in the middle.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Calculate the center coordinates.
- * let x = img.width / 2;
- * let y = img.height / 2;
- *
- * // Draw a circle at the image's center.
- * circle(x, y, 20);
- *
- * describe('An image of a mountain landscape with a white circle drawn in the middle.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels.
- * img.loadPixels();
- *
- * for (let i = 0; i < img.pixels.length; i += 4) {
- * // Red.
- * img.pixels[i] = 0;
- * // Green.
- * img.pixels[i + 1] = 0;
- * // Blue.
- * img.pixels[i + 2] = 0;
- * // Alpha.
- * img.pixels[i + 3] = 255;
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A black square drawn in the middle of a gray square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Image object.
- * let img = createImage(66, 66);
- *
- * // Load the image's pixels.
- * img.loadPixels();
- *
- * // Set the pixels to red.
- * for (let i = 0; i < img.pixels.length; i += 4) {
- * // Red.
- * img.pixels[i] = 255;
- * // Green.
- * img.pixels[i + 1] = 0;
- * // Blue.
- * img.pixels[i + 2] = 0;
- * // Alpha.
- * img.pixels[i + 3] = 255;
- * }
- *
- * // Update the image.
- * img.updatePixels();
- *
- * // Display the image.
- * image(img, 17, 17);
- *
- * describe('A red square drawn in the middle of a gray square.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Load the pixels array.
- * loadPixels();
- *
- * // Set the dot's coordinates.
- * let x = 50;
- * let y = 50;
- *
- * // Get the pixel density.
- * let d = pixelDensity();
- *
- * // Set the pixel(s) at the center of the canvas black.
- * for (let i = 0; i < d; i += 1) {
- * for (let j = 0; j < d; j += 1) {
- * let index = 4 * ((y * d + j) * width * d + (x * d + i));
- * // Red.
- * pixels[index] = 0;
- * // Green.
- * pixels[index + 1] = 0;
- * // Blue.
- * pixels[index + 2] = 0;
- * // Alpha.
- * pixels[index + 3] = 255;
- * }
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('A black dot in the middle of a gray rectangle.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Load the pixels array.
- * loadPixels();
- *
- * // Get the pixel density.
- * let d = pixelDensity();
- *
- * // Calculate the halfway index in the pixels array.
- * let halfImage = 4 * (d * width) * (d * height / 2);
- *
- * // Make the top half of the canvas red.
- * for (let i = 0; i < halfImage; i += 4) {
- * // Red.
- * pixels[i] = 255;
- * // Green.
- * pixels[i + 1] = 0;
- * // Blue.
- * pixels[i + 2] = 0;
- * // Alpha.
- * pixels[i + 3] = 255;
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('A red rectangle drawn above a gray rectangle.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Create a p5.Color object.
- * let pink = color(255, 102, 204);
- *
- * // Load the pixels array.
- * loadPixels();
- *
- * // Get the pixel density.
- * let d = pixelDensity();
- *
- * // Calculate the halfway index in the pixels array.
- * let halfImage = 4 * (d * width) * (d * height / 2);
- *
- * // Make the top half of the canvas red.
- * for (let i = 0; i < halfImage; i += 4) {
- * pixels[i] = red(pink);
- * pixels[i + 1] = green(pink);
- * pixels[i + 2] = blue(pink);
- * pixels[i + 3] = alpha(pink);
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('A pink rectangle drawn above a gray rectangle.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Load the pixels array.
+ * loadPixels();
+ *
+ * // Set the dot's coordinates.
+ * let x = 50;
+ * let y = 50;
+ *
+ * // Get the pixel density.
+ * let d = pixelDensity();
+ *
+ * // Set the pixel(s) at the center of the canvas black.
+ * for (let i = 0; i < d; i += 1) {
+ * for (let j = 0; j < d; j += 1) {
+ * let index = 4 * ((y * d + j) * width * d + (x * d + i));
+ * // Red.
+ * pixels[index] = 0;
+ * // Green.
+ * pixels[index + 1] = 0;
+ * // Blue.
+ * pixels[index + 2] = 0;
+ * // Alpha.
+ * pixels[index + 3] = 255;
+ * }
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('A black dot in the middle of a gray rectangle.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Load the pixels array.
+ * loadPixels();
+ *
+ * // Get the pixel density.
+ * let d = pixelDensity();
+ *
+ * // Calculate the halfway index in the pixels array.
+ * let halfImage = 4 * (d * width) * (d * height / 2);
+ *
+ * // Make the top half of the canvas red.
+ * for (let i = 0; i < halfImage; i += 4) {
+ * // Red.
+ * pixels[i] = 255;
+ * // Green.
+ * pixels[i + 1] = 0;
+ * // Blue.
+ * pixels[i + 2] = 0;
+ * // Alpha.
+ * pixels[i + 3] = 255;
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('A red rectangle drawn above a gray rectangle.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Create a p5.Color object.
+ * let pink = color(255, 102, 204);
+ *
+ * // Load the pixels array.
+ * loadPixels();
+ *
+ * // Get the pixel density.
+ * let d = pixelDensity();
+ *
+ * // Calculate the halfway index in the pixels array.
+ * let halfImage = 4 * (d * width) * (d * height / 2);
+ *
+ * // Make the top half of the canvas red.
+ * for (let i = 0; i < halfImage; i += 4) {
+ * pixels[i] = red(pink);
+ * pixels[i + 1] = green(pink);
+ * pixels[i + 2] = blue(pink);
+ * pixels[i + 3] = alpha(pink);
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('A pink rectangle drawn above a gray rectangle.');
+ * }
+ *
+ *
- * let img0;
- * let img1;
- *
- * // Load the images.
- * function preload() {
- * img0 = loadImage('assets/rockies.jpg');
- * img1 = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use the mountains as the background.
- * background(img0);
- *
- * // Display the bricks.
- * image(img1, 0, 0);
- *
- * // Display the bricks faded into the landscape.
- * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.');
- * }
- *
- *
- * let img0;
- * let img1;
- *
- * // Load the images.
- * function preload() {
- * img0 = loadImage('assets/rockies.jpg');
- * img1 = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use the mountains as the background.
- * background(img0);
- *
- * // Display the bricks.
- * image(img1, 0, 0);
- *
- * // Display the bricks partially transparent.
- * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.');
- * }
- *
- *
- * let img0;
- * let img1;
- *
- * // Load the images.
- * function preload() {
- * img0 = loadImage('assets/rockies.jpg');
- * img1 = loadImage('assets/bricks_third.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use the mountains as the background.
- * background(img0);
- *
- * // Display the bricks.
- * image(img1, 0, 0);
- *
- * // Display the bricks washed out into the landscape.
- * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
- *
- * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.');
- * }
- *
- *
+ * let img0;
+ * let img1;
+ *
+ * // Load the images.
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use the mountains as the background.
+ * background(img0);
+ *
+ * // Display the bricks.
+ * image(img1, 0, 0);
+ *
+ * // Display the bricks faded into the landscape.
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears faded on the right of the image.');
+ * }
+ *
+ *
+ * let img0;
+ * let img1;
+ *
+ * // Load the images.
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use the mountains as the background.
+ * background(img0);
+ *
+ * // Display the bricks.
+ * image(img1, 0, 0);
+ *
+ * // Display the bricks partially transparent.
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears transparent on the right of the image.');
+ * }
+ *
+ *
+ * let img0;
+ * let img1;
+ *
+ * // Load the images.
+ * function preload() {
+ * img0 = loadImage('assets/rockies.jpg');
+ * img1 = loadImage('assets/bricks_third.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use the mountains as the background.
+ * background(img0);
+ *
+ * // Display the bricks.
+ * image(img1, 0, 0);
+ *
+ * // Display the bricks washed out into the landscape.
+ * blend(img1, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
+ *
+ * describe('A wall of bricks in front of a mountain landscape. The same wall of bricks appears washed out on the right of the image.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use the mountains as the background.
- * background(img);
- *
- * // Copy a region of pixels to another spot.
- * copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
- *
- * // Outline the copied region.
- * stroke(255);
- * noFill();
- * square(7, 22, 10);
- *
- * describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use the mountains as the background.
+ * background(img);
+ *
+ * // Copy a region of pixels to another spot.
+ * copy(img, 7, 22, 10, 10, 35, 25, 50, 50);
+ *
+ * // Outline the copied region.
+ * stroke(255);
+ * noFill();
+ * square(7, 22, 10);
+ *
+ * describe('An image of a mountain landscape. A square region is outlined in white. A larger square contains a pixelated view of the outlined region.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the INVERT filter.
- * filter(INVERT);
- *
- * describe('A blue brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the GRAY filter.
- * filter(GRAY);
- *
- * describe('A brick wall drawn in grayscale.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the THRESHOLD filter.
- * filter(THRESHOLD);
- *
- * describe('A brick wall drawn in black and white.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the OPAQUE filter.
- * filter(OPAQUE);
- *
- * describe('A red brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the POSTERIZE filter.
- * filter(POSTERIZE, 3);
- *
- * describe('An image of a red brick wall drawn with limited color palette.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the BLUR filter.
- * filter(BLUR, 3);
- *
- * describe('A blurry image of a red brick wall.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the DILATE filter.
- * filter(DILATE);
- *
- * describe('A red brick wall with bright lines between each brick.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the ERODE filter.
- * filter(ERODE);
- *
- * describe('A red brick wall with faint lines between each brick.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/bricks.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Apply the BLUR filter.
- * // Don't use WebGL.
- * filter(BLUR, 3, false);
- *
- * describe('A blurry image of a red brick wall.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the INVERT filter.
+ * filter(INVERT);
+ *
+ * describe('A blue brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the GRAY filter.
+ * filter(GRAY);
+ *
+ * describe('A brick wall drawn in grayscale.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the THRESHOLD filter.
+ * filter(THRESHOLD);
+ *
+ * describe('A brick wall drawn in black and white.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the OPAQUE filter.
+ * filter(OPAQUE);
+ *
+ * describe('A red brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the POSTERIZE filter.
+ * filter(POSTERIZE, 3);
+ *
+ * describe('An image of a red brick wall drawn with limited color palette.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the BLUR filter.
+ * filter(BLUR, 3);
+ *
+ * describe('A blurry image of a red brick wall.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the DILATE filter.
+ * filter(DILATE);
+ *
+ * describe('A red brick wall with bright lines between each brick.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the ERODE filter.
+ * filter(ERODE);
+ *
+ * describe('A red brick wall with faint lines between each brick.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/bricks.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Apply the BLUR filter.
+ * // Don't use WebGL.
+ * filter(BLUR, 3, false);
+ *
+ * describe('A blurry image of a red brick wall.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Get the entire canvas.
- * let c = get();
- *
- * // Display half the canvas.
- * image(c, 50, 0);
- *
- * describe('Two identical mountain landscapes shown side-by-side.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Get the color of a pixel.
- * let c = get(50, 90);
- *
- * // Style the square with the pixel's color.
- * fill(c);
- * noStroke();
- *
- * // Display the square.
- * square(25, 25, 50);
- *
- * describe('A mountain landscape with an olive green square in its center.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0);
- *
- * // Get a region of the image.
- * let c = get(0, 0, 50, 50);
- *
- * // Display the region.
- * image(c, 50, 50);
- *
- * describe('A mountain landscape drawn on top of another mountain landscape.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Get the entire canvas.
+ * let c = get();
+ *
+ * // Display half the canvas.
+ * image(c, 50, 0);
+ *
+ * describe('Two identical mountain landscapes shown side-by-side.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Get the color of a pixel.
+ * let c = get(50, 90);
+ *
+ * // Style the square with the pixel's color.
+ * fill(c);
+ * noStroke();
+ *
+ * // Display the square.
+ * square(25, 25, 50);
+ *
+ * describe('A mountain landscape with an olive green square in its center.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0);
+ *
+ * // Get a region of the image.
+ * let c = get(0, 0, 50, 50);
+ *
+ * // Display the region.
+ * image(c, 50, 50);
+ *
+ * describe('A mountain landscape drawn on top of another mountain landscape.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0, 100, 100);
- *
- * // Get the pixel density.
- * let d = pixelDensity();
- *
- * // Calculate the halfway index in the pixels array.
- * let halfImage = 4 * (d * width) * (d * height / 2);
- *
- * // Load the pixels array.
- * loadPixels();
- *
- * // Copy the top half of the canvas to the bottom.
- * for (let i = 0; i < halfImage; i += 1) {
- * pixels[i + halfImage] = pixels[i];
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('Two identical images of mountain landscapes, one on top of the other.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0, 100, 100);
+ *
+ * // Get the pixel density.
+ * let d = pixelDensity();
+ *
+ * // Calculate the halfway index in the pixels array.
+ * let halfImage = 4 * (d * width) * (d * height / 2);
+ *
+ * // Load the pixels array.
+ * loadPixels();
+ *
+ * // Copy the top half of the canvas to the bottom.
+ * for (let i = 0; i < halfImage; i += 1) {
+ * pixels[i + halfImage] = pixels[i];
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('Two identical images of mountain landscapes, one on top of the other.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Set four pixels to black.
- * set(30, 20, 0);
- * set(85, 20, 0);
- * set(85, 75, 0);
- * set(30, 75, 0);
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('Four black dots arranged in a square drawn on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object.
- * let black = color(0);
- *
- * // Set four pixels to black.
- * set(30, 20, black);
- * set(85, 20, black);
- * set(85, 75, black);
- * set(30, 75, black);
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('Four black dots arranged in a square drawn on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(255);
- *
- * // Draw a horizontal color gradient.
- * for (let x = 0; x < 100; x += 1) {
- * for (let y = 0; y < 100; y += 1) {
- * // Calculate the grayscale value.
- * let c = map(x, 0, 100, 0, 255);
- *
- * // Set the pixel using the grayscale value.
- * set(x, y, c);
- * }
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('A horiztonal color gradient from black to white.');
- * }
- *
- *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Use the image to set all pixels.
- * set(0, 0, img);
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('An image of a mountain landscape.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Set four pixels to black.
+ * set(30, 20, 0);
+ * set(85, 20, 0);
+ * set(85, 75, 0);
+ * set(30, 75, 0);
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('Four black dots arranged in a square drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object.
+ * let black = color(0);
+ *
+ * // Set four pixels to black.
+ * set(30, 20, black);
+ * set(85, 20, black);
+ * set(85, 75, black);
+ * set(30, 75, black);
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('Four black dots arranged in a square drawn on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(255);
+ *
+ * // Draw a horizontal color gradient.
+ * for (let x = 0; x < 100; x += 1) {
+ * for (let y = 0; y < 100; y += 1) {
+ * // Calculate the grayscale value.
+ * let c = map(x, 0, 100, 0, 255);
+ *
+ * // Set the pixel using the grayscale value.
+ * set(x, y, c);
+ * }
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('A horiztonal color gradient from black to white.');
+ * }
+ *
+ *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Use the image to set all pixels.
+ * set(0, 0, img);
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('An image of a mountain landscape.');
+ * }
+ *
+ *
- * let img;
- *
- * // Load the image.
- * function preload() {
- * img = loadImage('assets/rockies.jpg');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * // Display the image.
- * image(img, 0, 0, 100, 100);
- *
- * // Get the pixel density.
- * let d = pixelDensity();
- *
- * // Calculate the halfway index in the pixels array.
- * let halfImage = 4 * (d * width) * (d * height / 2);
- *
- * // Load the pixels array.
- * loadPixels();
- *
- * // Copy the top half of the canvas to the bottom.
- * for (let i = 0; i < halfImage; i += 1) {
- * pixels[i + halfImage] = pixels[i];
- * }
- *
- * // Update the canvas.
- * updatePixels();
- *
- * describe('Two identical images of mountain landscapes, one on top of the other.');
- * }
- *
- *
+ * let img;
+ *
+ * // Load the image.
+ * function preload() {
+ * img = loadImage('assets/rockies.jpg');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * // Display the image.
+ * image(img, 0, 0, 100, 100);
+ *
+ * // Get the pixel density.
+ * let d = pixelDensity();
+ *
+ * // Calculate the halfway index in the pixels array.
+ * let halfImage = 4 * (d * width) * (d * height / 2);
+ *
+ * // Load the pixels array.
+ * loadPixels();
+ *
+ * // Copy the top half of the canvas to the bottom.
+ * for (let i = 0; i < halfImage; i += 1) {
+ * pixels[i + halfImage] = pixels[i];
+ * }
+ *
+ * // Update the canvas.
+ * updatePixels();
+ *
+ * describe('Two identical images of mountain landscapes, one on top of the other.');
+ * }
+ *
+ *
- * let myData;
- *
- * // Load the JSON and create an object.
- * function preload() {
- * myData = loadJSON('assets/data.json');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the circle.
- * fill(myData.color);
- * noStroke();
- *
- * // Draw the circle.
- * circle(myData.x, myData.y, myData.d);
- *
- * describe('A pink circle on a gray background.');
- * }
- *
- *
- * let myData;
- *
- * // Load the JSON and create an object.
- * function preload() {
- * myData = loadJSON('assets/data.json');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.Color object and make it transparent.
- * let c = color(myData.color);
- * c.setAlpha(80);
- *
- * // Style the circles.
- * fill(c);
- * noStroke();
- *
- * // Iterate over the myData.bubbles array.
- * for (let b of myData.bubbles) {
- * // Draw a circle for each bubble.
- * circle(b.x, b.y, b.d);
- * }
- *
- * describe('Several pink bubbles floating in a blue sky.');
- * }
- *
- *
- * let myData;
- *
- * // Load the GeoJSON and create an object.
- * function preload() {
- * myData = loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get data about the most recent earthquake.
- * let quake = myData.features[0].properties;
- *
- * // Draw a circle based on the earthquake's magnitude.
- * circle(50, 50, quake.mag * 10);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(11);
- *
- * // Display the earthquake's location.
- * text(quake.place, 5, 80, 100);
- *
- * describe(`A white circle on a gray background. The text "${quake.place}" is written beneath the circle.`);
- * }
- *
- *
- * let bigQuake;
- *
- * // Load the GeoJSON and preprocess it.
- * function preload() {
- * loadJSON(
- * 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
- * handleData
- * );
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Draw a circle based on the earthquake's magnitude.
- * circle(50, 50, bigQuake.mag * 10);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(11);
- *
- * // Display the earthquake's location.
- * text(bigQuake.place, 5, 80, 100);
- *
- * describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
- * }
- *
- * // Find the biggest recent earthquake.
- * function handleData(data) {
- * let maxMag = 0;
- * // Iterate over the earthquakes array.
- * for (let quake of data.features) {
- * // Reassign bigQuake if a larger
- * // magnitude quake is found.
- * if (quake.properties.mag > maxMag) {
- * bigQuake = quake.properties;
- * }
- * }
- * }
- *
- *
- * let bigQuake;
- *
- * // Load the GeoJSON and preprocess it.
- * function preload() {
- * loadJSON(
- * 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
- * handleData,
- * handleError
- * );
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Draw a circle based on the earthquake's magnitude.
- * circle(50, 50, bigQuake.mag * 10);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(11);
- *
- * // Display the earthquake's location.
- * text(bigQuake.place, 5, 80, 100);
- *
- * describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
- * }
- *
- * // Find the biggest recent earthquake.
- * function handleData(data) {
- * let maxMag = 0;
- * // Iterate over the earthquakes array.
- * for (let quake of data.features) {
- * // Reassign bigQuake if a larger
- * // magnitude quake is found.
- * if (quake.properties.mag > maxMag) {
- * bigQuake = quake.properties;
- * }
- * }
- * }
- *
- * // Log any errors to the console.
- * function handleError(error) {
- * console.log('Oops!', error);
- * }
- *
- *
+ * let myData;
+ *
+ * // Load the JSON and create an object.
+ * function preload() {
+ * myData = loadJSON('assets/data.json');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the circle.
+ * fill(myData.color);
+ * noStroke();
+ *
+ * // Draw the circle.
+ * circle(myData.x, myData.y, myData.d);
+ *
+ * describe('A pink circle on a gray background.');
+ * }
+ *
+ *
+ * let myData;
+ *
+ * // Load the JSON and create an object.
+ * function preload() {
+ * myData = loadJSON('assets/data.json');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.Color object and make it transparent.
+ * let c = color(myData.color);
+ * c.setAlpha(80);
+ *
+ * // Style the circles.
+ * fill(c);
+ * noStroke();
+ *
+ * // Iterate over the myData.bubbles array.
+ * for (let b of myData.bubbles) {
+ * // Draw a circle for each bubble.
+ * circle(b.x, b.y, b.d);
+ * }
+ *
+ * describe('Several pink bubbles floating in a blue sky.');
+ * }
+ *
+ *
+ * let myData;
+ *
+ * // Load the GeoJSON and create an object.
+ * function preload() {
+ * myData = loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get data about the most recent earthquake.
+ * let quake = myData.features[0].properties;
+ *
+ * // Draw a circle based on the earthquake's magnitude.
+ * circle(50, 50, quake.mag * 10);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(11);
+ *
+ * // Display the earthquake's location.
+ * text(quake.place, 5, 80, 100);
+ *
+ * describe(`A white circle on a gray background. The text "${quake.place}" is written beneath the circle.`);
+ * }
+ *
+ *
+ * let bigQuake;
+ *
+ * // Load the GeoJSON and preprocess it.
+ * function preload() {
+ * loadJSON(
+ * 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
+ * handleData
+ * );
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw a circle based on the earthquake's magnitude.
+ * circle(50, 50, bigQuake.mag * 10);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(11);
+ *
+ * // Display the earthquake's location.
+ * text(bigQuake.place, 5, 80, 100);
+ *
+ * describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
+ * }
+ *
+ * // Find the biggest recent earthquake.
+ * function handleData(data) {
+ * let maxMag = 0;
+ * // Iterate over the earthquakes array.
+ * for (let quake of data.features) {
+ * // Reassign bigQuake if a larger
+ * // magnitude quake is found.
+ * if (quake.properties.mag > maxMag) {
+ * bigQuake = quake.properties;
+ * }
+ * }
+ * }
+ *
+ *
+ * let bigQuake;
+ *
+ * // Load the GeoJSON and preprocess it.
+ * function preload() {
+ * loadJSON(
+ * 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson',
+ * handleData,
+ * handleError
+ * );
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Draw a circle based on the earthquake's magnitude.
+ * circle(50, 50, bigQuake.mag * 10);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(11);
+ *
+ * // Display the earthquake's location.
+ * text(bigQuake.place, 5, 80, 100);
+ *
+ * describe(`A white circle on a gray background. The text "${bigQuake.place}" is written beneath the circle.`);
+ * }
+ *
+ * // Find the biggest recent earthquake.
+ * function handleData(data) {
+ * let maxMag = 0;
+ * // Iterate over the earthquakes array.
+ * for (let quake of data.features) {
+ * // Reassign bigQuake if a larger
+ * // magnitude quake is found.
+ * if (quake.properties.mag > maxMag) {
+ * bigQuake = quake.properties;
+ * }
+ * }
+ * }
+ *
+ * // Log any errors to the console.
+ * function handleError(error) {
+ * console.log('Oops!', error);
+ * }
+ *
+ *
- * let myData;
- *
- * // Load the text and create an array.
- * function preload() {
- * myData = loadStrings('assets/test.txt');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Select a random line from the text.
- * let phrase = random(myData);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display the text.
- * text(phrase, 10, 50, 90);
- *
- * describe(`The text "${phrase}" written in black on a gray background.`);
- * }
- *
- *
- * let lastLine;
- *
- * // Load the text and preprocess it.
- * function preload() {
- * loadStrings('assets/test.txt', handleData);
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display the text.
- * text(lastLine, 10, 50, 90);
- *
- * describe('The text "I talk like an orange" written in black on a gray background.');
- * }
- *
- * // Select the last line from the text.
- * function handleData(data) {
- * lastLine = data[data.length - 1];
- * }
- *
- *
- * let lastLine;
- *
- * // Load the text and preprocess it.
- * function preload() {
- * loadStrings('assets/test.txt', handleData, handleError);
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display the text.
- * text(lastLine, 10, 50, 90);
- *
- * describe('The text "I talk like an orange" written in black on a gray background.');
- * }
- *
- * // Select the last line from the text.
- * function handleData(data) {
- * lastLine = data[data.length - 1];
- * }
- *
- * // Log any errors to the console.
- * function handleError(error) {
- * console.error('Oops!', error);
- * }
- *
- *
+ * let myData;
+ *
+ * // Load the text and create an array.
+ * function preload() {
+ * myData = loadStrings('assets/test.txt');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Select a random line from the text.
+ * let phrase = random(myData);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display the text.
+ * text(phrase, 10, 50, 90);
+ *
+ * describe(`The text "${phrase}" written in black on a gray background.`);
+ * }
+ *
+ *
+ * let lastLine;
+ *
+ * // Load the text and preprocess it.
+ * function preload() {
+ * loadStrings('assets/test.txt', handleData);
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display the text.
+ * text(lastLine, 10, 50, 90);
+ *
+ * describe('The text "I talk like an orange" written in black on a gray background.');
+ * }
+ *
+ * // Select the last line from the text.
+ * function handleData(data) {
+ * lastLine = data[data.length - 1];
+ * }
+ *
+ *
+ * let lastLine;
+ *
+ * // Load the text and preprocess it.
+ * function preload() {
+ * loadStrings('assets/test.txt', handleData, handleError);
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display the text.
+ * text(lastLine, 10, 50, 90);
+ *
+ * describe('The text "I talk like an orange" written in black on a gray background.');
+ * }
+ *
+ * // Select the last line from the text.
+ * function handleData(data) {
+ * lastLine = data[data.length - 1];
+ * }
+ *
+ * // Log any errors to the console.
+ * function handleError(error) {
+ * console.error('Oops!', error);
+ * }
+ *
+ *
+ * // Given the following CSV file called "mammals.csv"
+ * // located in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * //the file can be remote
+ * //table = loadTable("http://p5js.org/reference/assets/mammals.csv",
+ * // "csv", "header");
+ * }
+ *
+ * function setup() {
+ * //count the columns
+ * print(table.getRowCount() + ' total rows in table');
+ * print(table.getColumnCount() + ' total columns in table');
+ *
+ * print(table.getColumn('name'));
+ * //["Goat", "Leopard", "Zebra"]
+ *
+ * //cycle through the table
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print(table.getString(r, c));
+ * }
+ * describe(`randomly generated text from a file,
+ * for example "i smell like butter"`);
+ * }
+ *
+ *
- * // Given the following CSV file called "mammals.csv"
- * // located in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * //the file can be remote
- * //table = loadTable("http://p5js.org/reference/assets/mammals.csv",
- * // "csv", "header");
- * }
- *
- * function setup() {
- * //count the columns
- * print(table.getRowCount() + ' total rows in table');
- * print(table.getColumnCount() + ' total columns in table');
- *
- * print(table.getColumn('name'));
- * //["Goat", "Leopard", "Zebra"]
- *
- * //cycle through the table
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++) {
- * print(table.getString(r, c));
- * }
- * describe(`randomly generated text from a file,
- * for example "i smell like butter"`);
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array with all mammal tags.
+ * let mammals = myXML.getChildren('mammal');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the mammals array.
+ * for (let i = 0; i < mammals.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Get the mammal's common name.
+ * let name = mammals[i].getContent();
+ *
+ * // Display the mammal's name.
+ * text(name, 20, y);
+ * }
+ *
+ * describe(
+ * 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * let lastMammal;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * loadXML('assets/animals.xml', handleData);
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(16);
+ *
+ * // Display the content of the last mammal element.
+ * text(lastMammal, 50, 50);
+ *
+ * describe('The word "Zebra" written in black on a gray background.');
+ * }
+ *
+ * // Get the content of the last mammal element.
+ * function handleData(data) {
+ * // Get an array with all mammal elements.
+ * let mammals = data.getChildren('mammal');
+ *
+ * // Get the content of the last mammal.
+ * lastMammal = mammals[mammals.length - 1].getContent();
+ * }
+ *
+ *
+ * let lastMammal;
+ *
+ * // Load the XML and preprocess it.
+ * function preload() {
+ * loadXML('assets/animals.xml', handleData, handleError);
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(16);
+ *
+ * // Display the content of the last mammal element.
+ * text(lastMammal, 50, 50);
+ *
+ * describe('The word "Zebra" written in black on a gray background.');
+ * }
+ *
+ * // Get the content of the last mammal element.
+ * function handleData(data) {
+ * // Get an array with all mammal elements.
+ * let mammals = data.getChildren('mammal');
+ *
+ * // Get the content of the last mammal.
+ * lastMammal = mammals[mammals.length - 1].getContent();
+ * }
+ *
+ * // Log any errors to the console.
+ * function handleError(error) {
+ * console.error('Oops!', error);
+ * }
+ *
+ *
+ * let data;
+ *
+ * function preload() {
+ * data = loadBytes('assets/mammals.xml');
+ * }
+ *
+ * function setup() {
+ * for (let i = 0; i < 5; i++) {
+ * console.log(data.bytes[i].toString(16));
+ * }
+ * describe('no image displayed');
+ * }
+ *
httpDo(path, 'GET')
. The 'binary' datatype will return
+ * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
+ * which can be used to initialize typed arrays (such as Uint8Array).
+ *
+ * @method httpGet
+ * @param {String} path name of the file or url to load
+ * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer",
+ * "xml", or "text"
+ * @param {Object|Boolean} [data] param data passed sent with request
+ * @param {Function} [callback] function to be executed after
+ * httpGet() completes, data is passed in
+ * as first argument
+ * @param {Function} [errorCallback] function to be executed if
+ * there is an error, response is passed
+ * in as first argument
+ * @return {Promise} A promise that resolves with the data when the operation
+ * completes successfully or rejects with the error after
+ * one occurs.
+ * @example
+ *
+ * // Examples use USGS Earthquake API:
+ * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
+ * let earthquakes;
+ * function preload() {
+ * // Get the most recent earthquake in the database
+ * let url =
+ 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
+ * 'format=geojson&limit=1&orderby=time';
+ * httpGet(url, 'json', function(response) {
+ * // when the HTTP request completes, populate the variable that holds the
+ * // earthquake data used in the visualization.
+ * earthquakes = response;
+ * });
+ * }
+ *
+ * function draw() {
+ * if (!earthquakes) {
+ * // Wait until the earthquake data has loaded before drawing.
+ * return;
+ * }
+ * background(200);
+ * // Get the magnitude and name of the earthquake out of the loaded JSON
+ * let earthquakeMag = earthquakes.features[0].properties.mag;
+ * let earthquakeName = earthquakes.features[0].properties.place;
+ * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
+ * textAlign(CENTER);
+ * text(earthquakeName, 0, height - 30, width, 30);
+ * noLoop();
+ * }
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array with all mammal tags.
- * let mammals = myXML.getChildren('mammal');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the mammals array.
- * for (let i = 0; i < mammals.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Get the mammal's common name.
- * let name = mammals[i].getContent();
- *
- * // Display the mammal's name.
- * text(name, 20, y);
- * }
- *
- * describe(
- * 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
- * let lastMammal;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * loadXML('assets/animals.xml', handleData);
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(16);
- *
- * // Display the content of the last mammal element.
- * text(lastMammal, 50, 50);
- *
- * describe('The word "Zebra" written in black on a gray background.');
- * }
- *
- * // Get the content of the last mammal element.
- * function handleData(data) {
- * // Get an array with all mammal elements.
- * let mammals = data.getChildren('mammal');
- *
- * // Get the content of the last mammal.
- * lastMammal = mammals[mammals.length - 1].getContent();
- * }
- *
- *
- * let lastMammal;
- *
- * // Load the XML and preprocess it.
- * function preload() {
- * loadXML('assets/animals.xml', handleData, handleError);
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(16);
- *
- * // Display the content of the last mammal element.
- * text(lastMammal, 50, 50);
- *
- * describe('The word "Zebra" written in black on a gray background.');
- * }
- *
- * // Get the content of the last mammal element.
- * function handleData(data) {
- * // Get an array with all mammal elements.
- * let mammals = data.getChildren('mammal');
- *
- * // Get the content of the last mammal.
- * lastMammal = mammals[mammals.length - 1].getContent();
- * }
- *
- * // Log any errors to the console.
- * function handleError(error) {
- * console.error('Oops!', error);
- * }
- *
- * httpDo(path, 'POST')
.
+ *
+ * @method httpPost
+ * @param {String} path name of the file or url to load
+ * @param {String} [datatype] "json", "jsonp", "xml", or "text".
+ * If omitted, httpPost() will guess.
+ * @param {Object|Boolean} [data] param data passed sent with request
+ * @param {Function} [callback] function to be executed after
+ * httpPost() completes, data is passed in
+ * as first argument
+ * @param {Function} [errorCallback] function to be executed if
+ * there is an error, response is passed
+ * in as first argument
+ * @return {Promise} A promise that resolves with the data when the operation
+ * completes successfully or rejects with the error after
+ * one occurs.
+ *
+ * @example
+ *
+ * // Examples use jsonplaceholder.typicode.com for a Mock Data API
+ *
+ * let url = 'https://jsonplaceholder.typicode.com/posts';
+ * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' };
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * }
+ *
+ * function mousePressed() {
+ * httpPost(url, 'json', postData, function(result) {
+ * strokeWeight(2);
+ * text(result.body, mouseX, mouseY);
+ * });
+ * }
+ *
+ *
+ * let url = 'ttps://invalidURL'; // A bad URL that will cause errors
+ * let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' };
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ * background(200);
+ * }
+ *
+ * function mousePressed() {
+ * httpPost(
+ * url,
+ * 'json',
+ * postData,
+ * function(result) {
+ * // ... won't be called
+ * },
+ * function(error) {
+ * strokeWeight(2);
+ * text(error.toString(), mouseX, mouseY);
+ * }
+ * );
+ * }
+ *
+ * // Examples use USGS Earthquake API:
+ * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
+ *
+ * // displays an animation of all USGS earthquakes
+ * let earthquakes;
+ * let eqFeatureIndex = 0;
+ *
+ * function preload() {
+ * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
+ * httpDo(
+ * url,
+ * {
+ * method: 'GET',
+ * // Other Request options, like special headers for apis
+ * headers: { authorization: 'Bearer secretKey' }
+ * },
+ * function(res) {
+ * earthquakes = res;
+ * }
+ * );
+ * }
+ *
+ * function draw() {
+ * // wait until the data is loaded
+ * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
+ * return;
+ * }
+ * clear();
+ *
+ * let feature = earthquakes.features[eqFeatureIndex];
+ * let mag = feature.properties.mag;
+ * let rad = mag / 11 * ((width + height) / 2);
+ * fill(255, 0, 0, 100);
+ * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);
+ *
+ * if (eqFeatureIndex >= earthquakes.features.length) {
+ * eqFeatureIndex = 0;
+ * } else {
+ * eqFeatureIndex += 1;
+ * }
+ * }
+ *
+ *
- * let data;
- *
- * function preload() {
- * data = loadBytes('assets/mammals.xml');
- * }
- *
- * function setup() {
- * for (let i = 0; i < 5; i++) {
- * console.log(data.bytes[i].toString(16));
- * }
- * describe('no image displayed');
- * }
- *
httpDo(path, 'GET')
. The 'binary' datatype will return
- * a Blob object, and the 'arrayBuffer' datatype will return an ArrayBuffer
- * which can be used to initialize typed arrays (such as Uint8Array).
- *
- * @method httpGet
- * @param {String} path name of the file or url to load
- * @param {String} [datatype] "json", "jsonp", "binary", "arrayBuffer",
- * "xml", or "text"
- * @param {Object|Boolean} [data] param data passed sent with request
- * @param {Function} [callback] function to be executed after
- * httpGet() completes, data is passed in
- * as first argument
- * @param {Function} [errorCallback] function to be executed if
- * there is an error, response is passed
- * in as first argument
- * @return {Promise} A promise that resolves with the data when the operation
- * completes successfully or rejects with the error after
- * one occurs.
- * @example
- *
- * // Examples use USGS Earthquake API:
- * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
- * let earthquakes;
- * function preload() {
- * // Get the most recent earthquake in the database
- * let url =
- 'https://earthquake.usgs.gov/fdsnws/event/1/query?' +
- * 'format=geojson&limit=1&orderby=time';
- * httpGet(url, 'json', function(response) {
- * // when the HTTP request completes, populate the variable that holds the
- * // earthquake data used in the visualization.
- * earthquakes = response;
- * });
- * }
- *
- * function draw() {
- * if (!earthquakes) {
- * // Wait until the earthquake data has loaded before drawing.
- * return;
- * }
- * background(200);
- * // Get the magnitude and name of the earthquake out of the loaded JSON
- * let earthquakeMag = earthquakes.features[0].properties.mag;
- * let earthquakeName = earthquakes.features[0].properties.place;
- * ellipse(width / 2, height / 2, earthquakeMag * 10, earthquakeMag * 10);
- * textAlign(CENTER);
- * text(earthquakeName, 0, height - 30, width, 30);
- * noLoop();
- * }
- *
httpDo(path, 'POST')
.
- *
- * @method httpPost
- * @param {String} path name of the file or url to load
- * @param {String} [datatype] "json", "jsonp", "xml", or "text".
- * If omitted, httpPost() will guess.
- * @param {Object|Boolean} [data] param data passed sent with request
- * @param {Function} [callback] function to be executed after
- * httpPost() completes, data is passed in
- * as first argument
- * @param {Function} [errorCallback] function to be executed if
- * there is an error, response is passed
- * in as first argument
- * @return {Promise} A promise that resolves with the data when the operation
- * completes successfully or rejects with the error after
- * one occurs.
- *
- * @example
- *
- * // Examples use jsonplaceholder.typicode.com for a Mock Data API
- *
- * let url = 'https://jsonplaceholder.typicode.com/posts';
- * let postData = { userId: 1, title: 'p5 Clicked!', body: 'p5.js is very cool.' };
- *
- * function setup() {
- * createCanvas(100, 100);
- * background(200);
- * }
- *
- * function mousePressed() {
- * httpPost(url, 'json', postData, function(result) {
- * strokeWeight(2);
- * text(result.body, mouseX, mouseY);
- * });
- * }
- *
- *
- * let url = 'ttps://invalidURL'; // A bad URL that will cause errors
- * let postData = { title: 'p5 Clicked!', body: 'p5.js is very cool.' };
- *
- * function setup() {
- * createCanvas(100, 100);
- * background(200);
- * }
- *
- * function mousePressed() {
- * httpPost(
- * url,
- * 'json',
- * postData,
- * function(result) {
- * // ... won't be called
- * },
- * function(error) {
- * strokeWeight(2);
- * text(error.toString(), mouseX, mouseY);
- * }
- * );
- * }
- *
- * // Examples use USGS Earthquake API:
- * // https://earthquake.usgs.gov/fdsnws/event/1/#methods
- *
- * // displays an animation of all USGS earthquakes
- * let earthquakes;
- * let eqFeatureIndex = 0;
- *
- * function preload() {
- * let url = 'https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson';
- * httpDo(
- * url,
- * {
- * method: 'GET',
- * // Other Request options, like special headers for apis
- * headers: { authorization: 'Bearer secretKey' }
- * },
- * function(res) {
- * earthquakes = res;
- * }
- * );
- * }
- *
- * function draw() {
- * // wait until the data is loaded
- * if (!earthquakes || !earthquakes.features[eqFeatureIndex]) {
- * return;
- * }
- * clear();
- *
- * let feature = earthquakes.features[eqFeatureIndex];
- * let mag = feature.properties.mag;
- * let rad = mag / 11 * ((width + height) / 2);
- * fill(255, 0, 0, 100);
- * ellipse(width / 2 + random(-2, 2), height / 2 + random(-2, 2), rad, rad);
- *
- * if (eqFeatureIndex >= earthquakes.features.length) {
- * eqFeatureIndex = 0;
- * } else {
- * eqFeatureIndex += 1;
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create a p5.PrintWriter object.
- * let myWriter = createWriter('xo.txt');
- *
- * // Add some lines to the print stream.
- * myWriter.print('XOO');
- * myWriter.print('OXO');
- * myWriter.print('OOX');
- *
- * // Save the file and close the print stream.
- * myWriter.close();
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create a p5.PrintWriter object.
- * // Use the file format .csv.
- * let myWriter = createWriter('mauna_loa_co2', 'csv');
- *
- * // Add some lines to the print stream.
- * myWriter.print('date,ppm_co2');
- * myWriter.print('1960-01-01,316.43');
- * myWriter.print('1970-01-01,325.06');
- * myWriter.print('1980-01-01,337.9');
- * myWriter.print('1990-01-01,353.86');
- * myWriter.print('2000-01-01,369.45');
- * myWriter.print('2020-01-01,413.61');
- *
- * // Save the file and close the print stream.
- * myWriter.close();
- * }
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create a p5.PrintWriter object.
+ * let myWriter = createWriter('xo.txt');
+ *
+ * // Add some lines to the print stream.
+ * myWriter.print('XOO');
+ * myWriter.print('OXO');
+ * myWriter.print('OOX');
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create a p5.PrintWriter object.
+ * // Use the file format .csv.
+ * let myWriter = createWriter('mauna_loa_co2', 'csv');
+ *
+ * // Add some lines to the print stream.
+ * myWriter.print('date,ppm_co2');
+ * myWriter.print('1960-01-01,316.43');
+ * myWriter.print('1970-01-01,325.06');
+ * myWriter.print('1980-01-01,337.9');
+ * myWriter.print('1990-01-01,353.86');
+ * myWriter.print('2000-01-01,369.45');
+ * myWriter.print('2020-01-01,413.61');
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * // Create a p5.PrintWriter object.
- * let myWriter = createWriter('xo.txt');
- *
- * // Add some lines to the print stream.
- * myWriter.print('XOO');
- * myWriter.print('OXO');
- * myWriter.print('OOX');
- *
- * // Save the file and close the print stream.
- * myWriter.close();
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * // Create a p5.PrintWriter object.
+ * let myWriter = createWriter('numbers.txt');
+ *
+ * // Add some data to the print stream.
+ * myWriter.write('1,2,3,');
+ * myWriter.write(['4', '5', '6']);
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * // Create a p5.PrintWriter object.
+ * let myWriter = createWriter('numbers.txt');
+ *
+ * // Add some data to the print stream.
+ * myWriter.print('1,2,3,');
+ * myWriter.print(['4', '5', '6']);
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * // Create a p5.PrintWriter object.
+ * let myWriter = createWriter('numbers.txt');
+ *
+ * // Add some data to the print stream.
+ * myWriter.print('Hello p5*js!');
+ *
+ * // Clear the print stream.
+ * myWriter.clear();
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * // Create a p5.PrintWriter object.
+ * let myWriter = createWriter('cat.txt');
+ *
+ * // Add some data to the print stream.
+ * // ASCII art courtesy Wikipedia:
+ * // https://en.wikipedia.org/wiki/ASCII_art
+ * myWriter.print(' (\\_/) ');
+ * myWriter.print("(='.'=)");
+ * myWriter.print('(")_(")');
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ *
+ * true
indicates that the
+ * output will be optimized for filesize,
+ * rather than readability.
+ *
+ * @example
+ *
+ * // Saves the canvas as an image
+ * cnv = createCanvas(300, 300);
+ * save(cnv, 'myCanvas.jpg');
+ *
+ * // Saves the canvas as an image by default
+ * save('myCanvas.jpg');
+ * describe('An example for saving a canvas as an image.');
+ *
+ * // Saves p5.Image as an image
+ * img = createImage(10, 10);
+ * save(img, 'myImage.png');
+ * describe('An example for saving a p5.Image element as an image.');
+ *
+ * // Saves p5.Renderer object as an image
+ * obj = createGraphics(100, 100);
+ * save(obj, 'myObject.png');
+ * describe('An example for saving a p5.Renderer element.');
+ *
+ * let myTable = new p5.Table();
+ * // Saves table as html file
+ * save(myTable, 'myTable.html');
+ *
+ * // Comma Separated Values
+ * save(myTable, 'myTable.csv');
+ *
+ * // Tab Separated Values
+ * save(myTable, 'myTable.tsv');
+ *
+ * describe(`An example showing how to save a table in formats of
+ * HTML, CSV and TSV.`);
+ *
+ * let myJSON = { a: 1, b: true };
+ *
+ * // Saves pretty JSON
+ * save(myJSON, 'my.json');
+ *
+ * // Optimizes JSON filesize
+ * save(myJSON, 'my.json', true);
+ *
+ * describe('An example for saving JSON to a txt file with some extra arguments.');
+ *
+ * // Saves array of strings to text file with line breaks after each item
+ * let arrayOfStrings = ['a', 'b'];
+ * save(arrayOfStrings, 'my.txt');
+ * describe(`An example for saving an array of strings to text file
+ * with line breaks.`);
+ *
* function setup() {
@@ -1710,29 +2021,92 @@ p5.PrintWriter = function (filename, extension) {
*
* // Save the file when the user double-clicks.
* function doubleClicked() {
- * // Create a p5.PrintWriter object.
- * let myWriter = createWriter('numbers.txt');
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create an object.
+ * let data = { x: mouseX, y: mouseY };
*
- * // Add some data to the print stream.
- * myWriter.print('Hello p5*js!');
+ * // Save the JSON file.
+ * saveJSON(data, 'state.json');
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
*
- * // Save the file and close the print stream.
- * myWriter.close();
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create an object.
+ * let data = { x: mouseX, y: mouseY };
+ *
+ * // Save the JSON file and reduce its size.
+ * saveJSON(data, 'state.json', true);
+ * }
* }
*
*
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create an array.
+ * // ASCII art courtesy Wikipedia:
+ * // https://en.wikipedia.org/wiki/ASCII_art
+ * let data = [' (\\_/) ', "(='.'=)", '(")_(")'];
+ *
+ * // Save the text file.
+ * saveStrings(data, 'cat', 'txt');
+ * }
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
+ * // Create an array.
+ * // +--+
+ * // / /|
+ * // +--+ +
+ * // | |/
+ * // +--+
+ * let data = [' +--+', ' / /|', '+--+ +', '| |/', '+--+'];
+ *
+ * // Save the text file.
+ * // Use CRLF for line endings.
+ * saveStrings(data, 'box', 'txt', true);
+ * }
* }
*
* true
indicates that the
- * output will be optimized for filesize,
- * rather than readability.
- *
- * @example
- *
- * // Saves the canvas as an image
- * cnv = createCanvas(300, 300);
- * save(cnv, 'myCanvas.jpg');
- *
- * // Saves the canvas as an image by default
- * save('myCanvas.jpg');
- * describe('An example for saving a canvas as an image.');
- *
- * // Saves p5.Image as an image
- * img = createImage(10, 10);
- * save(img, 'myImage.png');
- * describe('An example for saving a p5.Image element as an image.');
- *
- * // Saves p5.Renderer object as an image
- * obj = createGraphics(100, 100);
- * save(obj, 'myObject.png');
- * describe('An example for saving a p5.Renderer element.');
- *
- * let myTable = new p5.Table();
- * // Saves table as html file
- * save(myTable, 'myTable.html');
- *
- * // Comma Separated Values
- * save(myTable, 'myTable.csv');
- *
- * // Tab Separated Values
- * save(myTable, 'myTable.tsv');
- *
- * describe(`An example showing how to save a table in formats of
- * HTML, CSV and TSV.`);
- *
- * let myJSON = { a: 1, b: true };
- *
- * // Saves pretty JSON
- * save(myJSON, 'my.json');
- *
- * // Optimizes JSON filesize
- * save(myJSON, 'my.json', true);
- *
- * describe('An example for saving JSON to a txt file with some extra arguments.');
- *
- * // Saves array of strings to text file with line breaks after each item
- * let arrayOfStrings = ['a', 'b'];
- * save(arrayOfStrings, 'my.txt');
- * describe(`An example for saving an array of strings to text file
- * with line breaks.`);
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an array.
- * let data = [1, 2, 3];
- *
- * // Save the JSON file.
- * saveJSON(data, 'numbers.json');
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an object.
- * let data = { x: mouseX, y: mouseY };
- *
- * // Save the JSON file.
- * saveJSON(data, 'state.json');
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an object.
- * let data = { x: mouseX, y: mouseY };
- *
- * // Save the JSON file and reduce its size.
- * saveJSON(data, 'state.json', true);
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an array.
- * let data = ['0', '01', '011'];
- *
- * // Save the text file.
- * saveStrings(data, 'data.txt');
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an array.
- * // ASCII art courtesy Wikipedia:
- * // https://en.wikipedia.org/wiki/ASCII_art
- * let data = [' (\\_/) ', "(='.'=)", '(")_(")'];
- *
- * // Save the text file.
- * saveStrings(data, 'cat', 'txt');
- * }
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * if (mouseX > 0 && mouseX < 100 && mouseY > 0 && mouseY < 100) {
- * // Create an array.
- * // +--+
- * // / /|
- * // +--+ +
- * // | |/
- * // +--+
- * let data = [' +--+', ' / /|', '+--+ +', '| |/', '+--+'];
- *
- * // Save the text file.
- * // Use CRLF for line endings.
- * saveStrings(data, 'box', 'txt', true);
- * }
- * }
- *
- *
- * let table;
- *
- * function setup() {
- * table = new p5.Table();
- *
- * table.addColumn('id');
- * table.addColumn('species');
- * table.addColumn('name');
- *
- * let newRow = table.addRow();
- * newRow.setNum('id', table.getRowCount() - 1);
- * newRow.setString('species', 'Panthera leo');
- * newRow.setString('name', 'Lion');
- *
- * // To save, un-comment next line then click 'run'
- * // saveTable(table, 'new.csv');
- *
- * describe('no image displayed');
- * }
- *
- * // Saves the following to a file called 'new.csv':
- * // id,species,name
- * // 0,Panthera leo,Lion
- *
+ * let table;
+ *
+ * function setup() {
+ * table = new p5.Table();
+ *
+ * table.addColumn('id');
+ * table.addColumn('species');
+ * table.addColumn('name');
+ *
+ * let newRow = table.addRow();
+ * newRow.setNum('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Panthera leo');
+ * newRow.setString('name', 'Lion');
+ *
+ * // To save, un-comment next line then click 'run'
+ * // saveTable(table, 'new.csv');
+ *
+ * describe('no image displayed');
+ * }
+ *
+ * // Saves the following to a file called 'new.csv':
+ * // id,species,name
+ * // 0,Panthera leo,Lion
+ *
${e}`); - pWriter.print(' | '); + } else { + // otherwise, make HTML + pWriter.print(''); + pWriter.print(''); + let str = ' '; + pWriter.print(str); + pWriter.print(''); + + pWriter.print(''); + pWriter.print('
${e}`); + pWriter.print(' | '); + } + pWriter.print('
${htmlEntry}`); - pWriter.print(' | '); + // make rows + for (let row = 0; row < table.rows.length; row++) { + pWriter.print('
${htmlEntry}`); + pWriter.print(' | '); + } + pWriter.print('
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //add a row
- * let newRow = table.addRow();
- * newRow.setString('id', table.getRowCount() - 1);
- * newRow.setString('species', 'Canis Lupus');
- * newRow.setString('name', 'Wolf');
- *
- * //print the results
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++)
- * print(table.getString(r, c));
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add a row
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Canis Lupus');
+ * newRow.setString('name', 'Wolf');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //remove the first row
- * table.removeRow(0);
- *
- * //print the results
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++)
- * print(table.getString(r, c));
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //remove the first row
+ * table.removeRow(0);
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let row = table.getRow(1);
- * //print it column by column
- * //note: a row is an object, not an array
- * for (let c = 0; c < table.getColumnCount(); c++) {
- * print(row.getString(c));
- * }
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let row = table.getRow(1);
+ * //print it column by column
+ * //note: a row is an object, not an array
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print(row.getString(c));
+ * }
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- *
- * //warning: rows is an array of objects
- * for (let r = 0; r < rows.length; r++) {
- * rows[r].set('name', 'Unicorn');
- * }
- *
- * //print the results
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++)
- * print(table.getString(r, c));
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ *
+ * //warning: rows is an array of objects
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].set('name', 'Unicorn');
+ * }
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //find the animal named zebra
- * let row = table.findRow('Zebra', 'name');
- * //find the corresponding species
- * print(row.getString('species'));
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //find the animal named zebra
+ * let row = table.findRow('Zebra', 'name');
+ * //find the corresponding species
+ * print(row.getString('species'));
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //add another goat
- * let newRow = table.addRow();
- * newRow.setString('id', table.getRowCount() - 1);
- * newRow.setString('species', 'Scape Goat');
- * newRow.setString('name', 'Goat');
- *
- * //find the rows containing animals named Goat
- * let rows = table.findRows('Goat', 'name');
- * print(rows.length + ' Goats found');
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add another goat
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Scape Goat');
+ * newRow.setString('name', 'Goat');
+ *
+ * //find the rows containing animals named Goat
+ * let rows = table.findRows('Goat', 'name');
+ * print(rows.length + ' Goats found');
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //Search using specified regex on a given column, return TableRow object
- * let mammal = table.matchRow(new RegExp('ant'), 1);
- * print(mammal.getString(1));
- * //Output "Panthera pardus"
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //Search using specified regex on a given column, return TableRow object
+ * let mammal = table.matchRow(new RegExp('ant'), 1);
+ * print(mammal.getString(1));
+ * //Output "Panthera pardus"
+ * }
+ *
+ *
- * let table;
- *
- * function setup() {
- * table = new p5.Table();
- *
- * table.addColumn('name');
- * table.addColumn('type');
- *
- * let newRow = table.addRow();
- * newRow.setString('name', 'Lion');
- * newRow.setString('type', 'Mammal');
- *
- * newRow = table.addRow();
- * newRow.setString('name', 'Snake');
- * newRow.setString('type', 'Reptile');
- *
- * newRow = table.addRow();
- * newRow.setString('name', 'Mosquito');
- * newRow.setString('type', 'Insect');
- *
- * newRow = table.addRow();
- * newRow.setString('name', 'Lizard');
- * newRow.setString('type', 'Reptile');
- *
- * let rows = table.matchRows('R.*', 'type');
- * for (let i = 0; i < rows.length; i++) {
- * print(rows[i].getString('name') + ': ' + rows[i].getString('type'));
- * }
- * }
- * // Sketch prints:
- * // Snake: Reptile
- * // Lizard: Reptile
- *
- *
+ * let table;
+ *
+ * function setup() {
+ * table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', 'Lion');
+ * newRow.setString('type', 'Mammal');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Snake');
+ * newRow.setString('type', 'Reptile');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Mosquito');
+ * newRow.setString('type', 'Insect');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', 'Lizard');
+ * newRow.setString('type', 'Reptile');
+ *
+ * let rows = table.matchRows('R.*', 'type');
+ * for (let i = 0; i < rows.length; i++) {
+ * print(rows[i].getString('name') + ': ' + rows[i].getString('type'));
+ * }
+ * }
+ * // Sketch prints:
+ * // Snake: Reptile
+ * // Lizard: Reptile
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //getColumn returns an array that can be printed directly
- * print(table.getColumn('species'));
- * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //getColumn returns an array that can be printed directly
+ * print(table.getColumn('species'));
+ * //outputs ["Capra hircus", "Panthera pardus", "Equus zebra"]
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * table.clearRows();
- * print(table.getRowCount() + ' total rows in table');
- * print(table.getColumnCount() + ' total columns in table');
- * describe('no image displayed');
- * }
- *
- *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * table.addColumn('carnivore');
- * table.set(0, 'carnivore', 'no');
- * table.set(1, 'carnivore', 'yes');
- * table.set(2, 'carnivore', 'no');
- *
- * //print the results
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++)
- * print(table.getString(r, c));
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.clearRows();
+ * print(table.getRowCount() + ' total rows in table');
+ * print(table.getColumnCount() + ' total columns in table');
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // given the cvs file "blobs.csv" in /assets directory
- * // ID, Name, Flavor, Shape, Color
- * // Blob1, Blobby, Sweet, Blob, Pink
- * // Blob2, Saddy, Savory, Blob, Blue
- *
- * let table;
- *
- * function preload() {
- * table = loadTable('assets/blobs.csv');
- * }
- *
- * function setup() {
- * createCanvas(200, 100);
- * textAlign(CENTER);
- * background(255);
- * }
- *
- * function draw() {
- * let numOfColumn = table.getColumnCount();
- * text('There are ' + numOfColumn + ' columns in the table.', 100, 50);
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.addColumn('carnivore');
+ * table.set(0, 'carnivore', 'no');
+ * table.set(1, 'carnivore', 'yes');
+ * table.set(2, 'carnivore', 'no');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // given the cvs file "blobs.csv" in /assets directory
- * //
- * // ID, Name, Flavor, Shape, Color
- * // Blob1, Blobby, Sweet, Blob, Pink
- * // Blob2, Saddy, Savory, Blob, Blue
- *
- * let table;
- *
- * function preload() {
- * table = loadTable('assets/blobs.csv');
- * }
- *
- * function setup() {
- * createCanvas(200, 100);
- * textAlign(CENTER);
- * background(255);
- * }
- *
- * function draw() {
- * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50);
- * }
- *
- *
+ * // given the cvs file "blobs.csv" in /assets directory
+ * // ID, Name, Flavor, Shape, Color
+ * // Blob1, Blobby, Sweet, Blob, Pink
+ * // Blob2, Saddy, Savory, Blob, Blue
+ *
+ * let table;
+ *
+ * function preload() {
+ * table = loadTable('assets/blobs.csv');
+ * }
+ *
+ * function setup() {
+ * createCanvas(200, 100);
+ * textAlign(CENTER);
+ * background(255);
+ * }
+ *
+ * function draw() {
+ * let numOfColumn = table.getColumnCount();
+ * text('There are ' + numOfColumn + ' columns in the table.', 100, 50);
+ * }
+ *
+ *
- * function setup() {
- * let table = new p5.Table();
- *
- * table.addColumn('name');
- * table.addColumn('type');
- *
- * let newRow = table.addRow();
- * newRow.setString('name', ' $Lion ,');
- * newRow.setString('type', ',,,Mammal');
- *
- * newRow = table.addRow();
- * newRow.setString('name', '$Snake ');
- * newRow.setString('type', ',,,Reptile');
- *
- * table.removeTokens(',$ ');
- * print(table.getArray());
- * }
- *
- * // prints:
- * // 0 "Lion" "Mamal"
- * // 1 "Snake" "Reptile"
- *
+ * // given the cvs file "blobs.csv" in /assets directory
+ * //
+ * // ID, Name, Flavor, Shape, Color
+ * // Blob1, Blobby, Sweet, Blob, Pink
+ * // Blob2, Saddy, Savory, Blob, Blue
+ *
+ * let table;
+ *
+ * function preload() {
+ * table = loadTable('assets/blobs.csv');
+ * }
+ *
+ * function setup() {
+ * createCanvas(200, 100);
+ * textAlign(CENTER);
+ * background(255);
+ * }
+ *
+ * function draw() {
+ * text('There are ' + table.getRowCount() + ' rows in the table.', 100, 50);
+ * }
+ *
+ *
+ * function setup() {
+ * let table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', ' $Lion ,');
+ * newRow.setString('type', ',,,Mammal');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', '$Snake ');
+ * newRow.setString('type', ',,,Reptile');
+ *
+ * table.removeTokens(',$ ');
+ * print(table.getArray());
+ * }
+ *
+ * // prints:
+ * // 0 "Lion" "Mamal"
+ * // 1 "Snake" "Reptile"
+ *
- * function setup() {
- * let table = new p5.Table();
- *
- * table.addColumn('name');
- * table.addColumn('type');
- *
- * let newRow = table.addRow();
- * newRow.setString('name', ' Lion ,');
- * newRow.setString('type', ' Mammal ');
- *
- * newRow = table.addRow();
- * newRow.setString('name', ' Snake ');
- * newRow.setString('type', ' Reptile ');
- *
- * table.trim();
- * print(table.getArray());
- * }
- *
- * // prints:
- * // 0 "Lion" "Mamal"
- * // 1 "Snake" "Reptile"
- *
+ * function setup() {
+ * let table = new p5.Table();
+ *
+ * table.addColumn('name');
+ * table.addColumn('type');
+ *
+ * let newRow = table.addRow();
+ * newRow.setString('name', ' Lion ,');
+ * newRow.setString('type', ' Mammal ');
+ *
+ * newRow = table.addRow();
+ * newRow.setString('name', ' Snake ');
+ * newRow.setString('type', ' Reptile ');
+ *
+ * table.trim();
+ * print(table.getArray());
+ * }
+ *
+ * // prints:
+ * // 0 "Lion" "Mamal"
+ * // 1 "Snake" "Reptile"
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * table.removeColumn('id');
- * print(table.getColumnCount());
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.removeColumn('id');
+ * print(table.getColumnCount());
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * table.set(0, 'species', 'Canis Lupus');
- * table.set(0, 'name', 'Wolf');
- *
- * //print the results
- * for (let r = 0; r < table.getRowCount(); r++)
- * for (let c = 0; c < table.getColumnCount(); c++)
- * print(table.getString(r, c));
- *
- * describe('no image displayed');
- * }
- *
- *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * table.setNum(1, 'id', 1);
- *
- * print(table.getColumn(0));
- * //["0", 1, "2"]
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.set(0, 'species', 'Canis Lupus');
+ * table.set(0, 'name', 'Wolf');
+ *
+ * //print the results
+ * for (let r = 0; r < table.getRowCount(); r++)
+ * for (let c = 0; c < table.getColumnCount(); c++)
+ * print(table.getString(r, c));
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //add a row
- * let newRow = table.addRow();
- * newRow.setString('id', table.getRowCount() - 1);
- * newRow.setString('species', 'Canis Lupus');
- * newRow.setString('name', 'Wolf');
- *
- * print(table.getArray());
- *
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * table.setNum(1, 'id', 1);
+ *
+ * print(table.getColumn(0));
+ * //["0", 1, "2"]
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * print(table.get(0, 1));
- * //Capra hircus
- * print(table.get(0, 'species'));
- * //Capra hircus
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //add a row
+ * let newRow = table.addRow();
+ * newRow.setString('id', table.getRowCount() - 1);
+ * newRow.setString('species', 'Canis Lupus');
+ * newRow.setString('name', 'Wolf');
+ *
+ * print(table.getArray());
+ *
+ * describe('no image displayed');
+ * }
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * print(table.getNum(1, 0) + 100);
- * //id 1 + 100 = 101
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.get(0, 1));
+ * //Capra hircus
+ * print(table.get(0, 'species'));
+ * //Capra hircus
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * // table is comma separated value "CSV"
- * // and has specifiying header for column labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * print(table.getString(0, 0)); // 0
- * print(table.getString(0, 1)); // Capra hircus
- * print(table.getString(0, 2)); // Goat
- * print(table.getString(1, 0)); // 1
- * print(table.getString(1, 1)); // Panthera pardus
- * print(table.getString(1, 2)); // Leopard
- * print(table.getString(2, 0)); // 2
- * print(table.getString(2, 1)); // Equus zebra
- * print(table.getString(2, 2)); // Zebra
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.getNum(1, 0) + 100);
+ * //id 1 + 100 = 101
+ * describe('no image displayed');
+ * }
+ *
+ *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * // table is comma separated value "CSV"
+ * // and has specifiying header for column labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * print(table.getString(0, 0)); // 0
+ * print(table.getString(0, 1)); // Capra hircus
+ * print(table.getString(0, 2)); // Goat
+ * print(table.getString(1, 0)); // 1
+ * print(table.getString(1, 1)); // Panthera pardus
+ * print(table.getString(1, 2)); // Leopard
+ * print(table.getString(2, 0)); // 2
+ * print(table.getString(2, 1)); // Equus zebra
+ * print(table.getString(2, 2)); // Zebra
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let tableObject = table.getObject();
- *
- * print(tableObject);
- * //outputs an object
- *
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let tableObject = table.getObject();
+ *
+ * print(tableObject);
+ * //outputs an object
+ *
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leoperd
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * // table is comma separated value "CSV"
- * // and has specifiying header for column labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let tableArray = table.getArray();
- * for (let i = 0; i < tableArray.length; i++) {
- * print(tableArray[i]);
- * }
- * describe('no image displayed');
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leoperd
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * // table is comma separated value "CSV"
+ * // and has specifiying header for column labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let tableArray = table.getArray();
+ * for (let i = 0; i < tableArray.length; i++) {
+ * print(tableArray[i]);
+ * }
+ * describe('no image displayed');
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv"
- * // in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * //print the column names
- * for (let c = 0; c < table.getColumnCount(); c++) {
- * print('column ' + c + ' is named ' + table.columns[c]);
- * }
- * }
- *
- *
+ * // Given the CSV file "mammals.csv"
+ * // in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * //print the column names
+ * for (let c = 0; c < table.getColumnCount(); c++) {
+ * print('column ' + c + ' is named ' + table.columns[c]);
+ * }
+ * }
+ *
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- * for (let r = 0; r < rows.length; r++) {
- * rows[r].set('name', 'Unicorn');
- * }
- *
- * //print the results
- * print(table.getArray());
- *
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].set('name', 'Unicorn');
+ * }
+ *
+ * //print the results
+ * print(table.getArray());
+ *
+ * describe('no image displayed');
+ * }
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- * for (let r = 0; r < rows.length; r++) {
- * rows[r].setNum('id', r + 10);
- * }
- *
- * print(table.getArray());
- *
- * describe('no image displayed');
- * }
- *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- * for (let r = 0; r < rows.length; r++) {
- * let name = rows[r].getString('name');
- * rows[r].setString('name', 'A ' + name + ' named George');
- * }
- *
- * print(table.getArray());
- *
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * rows[r].setNum('id', r + 10);
+ * }
+ *
+ * print(table.getArray());
+ *
+ * describe('no image displayed');
+ * }
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let names = [];
- * let rows = table.getRows();
- * for (let r = 0; r < rows.length; r++) {
- * names.push(rows[r].get('name'));
- * }
- *
- * print(names);
- *
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * let name = rows[r].getString('name');
+ * rows[r].setString('name', 'A ' + name + ' named George');
+ * }
+ *
+ * print(table.getArray());
+ *
+ * describe('no image displayed');
+ * }
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- * let minId = Infinity;
- * let maxId = -Infinity;
- * for (let r = 0; r < rows.length; r++) {
- * let id = rows[r].getNum('id');
- * minId = min(minId, id);
- * maxId = min(maxId, id);
- * }
- * print('minimum id = ' + minId + ', maximum id = ' + maxId);
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let names = [];
+ * let rows = table.getRows();
+ * for (let r = 0; r < rows.length; r++) {
+ * names.push(rows[r].get('name'));
+ * }
+ *
+ * print(names);
+ *
+ * describe('no image displayed');
+ * }
+ *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * let minId = Infinity;
+ * let maxId = -Infinity;
+ * for (let r = 0; r < rows.length; r++) {
+ * let id = rows[r].getNum('id');
+ * minId = min(minId, id);
+ * maxId = min(maxId, id);
+ * }
+ * print('minimum id = ' + minId + ', maximum id = ' + maxId);
+ * describe('no image displayed');
+ * }
+ *
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
- * //
- * // id,species,name
- * // 0,Capra hircus,Goat
- * // 1,Panthera pardus,Leopard
- * // 2,Equus zebra,Zebra
- *
- * let table;
- *
- * function preload() {
- * //my table is comma separated value "csv"
- * //and has a header specifying the columns labels
- * table = loadTable('assets/mammals.csv', 'csv', 'header');
- * }
- *
- * function setup() {
- * let rows = table.getRows();
- * let longest = '';
- * for (let r = 0; r < rows.length; r++) {
- * let species = rows[r].getString('species');
- * if (longest.length < species.length) {
- * longest = species;
- * }
- * }
- *
- * print('longest: ' + longest);
- *
- * describe('no image displayed');
- * }
- *
+ * // Given the CSV file "mammals.csv" in the project's "assets" folder:
+ * //
+ * // id,species,name
+ * // 0,Capra hircus,Goat
+ * // 1,Panthera pardus,Leopard
+ * // 2,Equus zebra,Zebra
+ *
+ * let table;
+ *
+ * function preload() {
+ * //my table is comma separated value "csv"
+ * //and has a header specifying the columns labels
+ * table = loadTable('assets/mammals.csv', 'csv', 'header');
+ * }
+ *
+ * function setup() {
+ * let rows = table.getRows();
+ * let longest = '';
+ * for (let r = 0; r < rows.length; r++) {
+ * let species = rows[r].getString('species');
+ * if (longest.length < species.length) {
+ * longest = species;
+ * }
+ * }
+ *
+ * print('longest: ' + longest);
+ *
+ * describe('no image displayed');
+ * }
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array with all mammal tags.
- * let mammals = myXML.getChildren('mammal');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the mammals array.
- * for (let i = 0; i < mammals.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Get the mammal's common name.
- * let name = mammals[i].getContent();
- *
- * // Display the mammal's name.
- * text(name, 20, y);
- * }
- *
- * describe(
- * 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array with all mammal tags.
+ * let mammals = myXML.getChildren('mammal');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the mammals array.
+ * for (let i = 0; i < mammals.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Get the mammal's common name.
+ * let name = mammals[i].getContent();
+ *
+ * // Display the mammal's name.
+ * text(name, 20, y);
+ * }
+ *
+ * describe(
+ * 'The words "Goat", "Leopard", and "Zebra" written on three separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array with all mammal elements.
- * let mammals = myXML.getChildren('mammal');
- *
- * // Get the first mammal element.
- * let firstMammal = mammals[0];
- *
- * // Get the parent element.
- * let parent = firstMammal.getParent();
- *
- * // Get the parent element's name.
- * let name = parent.getName();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the parent element's name.
- * text(name, 50, 50);
- *
- * describe('The word "animals" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array with all mammal elements.
+ * let mammals = myXML.getChildren('mammal');
+ *
+ * // Get the first mammal element.
+ * let firstMammal = mammals[0];
+ *
+ * // Get the parent element.
+ * let parent = firstMammal.getParent();
+ *
+ * // Get the parent element's name.
+ * let name = parent.getName();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the parent element's name.
+ * text(name, 50, 50);
+ *
+ * describe('The word "animals" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array with all mammal elements.
- * let mammals = myXML.getChildren('mammal');
- *
- * // Get the first mammal element.
- * let firstMammal = mammals[0];
- *
- * // Get the mammal element's name.
- * let name = firstMammal.getName();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's name.
- * text(name, 50, 50);
- *
- * describe('The word "mammal" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array with all mammal elements.
+ * let mammals = myXML.getChildren('mammal');
+ *
+ * // Get the first mammal element.
+ * let firstMammal = mammals[0];
+ *
+ * // Get the mammal element's name.
+ * let name = firstMammal.getName();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's name.
+ * text(name, 50, 50);
+ *
+ * describe('The word "mammal" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the element's original name.
- * let oldName = myXML.getName();
- *
- * // Set the element's name.
- * myXML.setName('monsters');
- *
- * // Get the element's new name.
- * let newName = myXML.getName();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's names.
- * text(oldName, 50, 33);
- * text(newName, 50, 67);
- *
- * describe(
- * 'The words "animals" and "monsters" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the element's original name.
+ * let oldName = myXML.getName();
+ *
+ * // Set the element's name.
+ * myXML.setName('monsters');
+ *
+ * // Get the element's new name.
+ * let newName = myXML.getName();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's names.
+ * text(oldName, 50, 33);
+ * text(newName, 50, 67);
+ *
+ * describe(
+ * 'The words "animals" and "monsters" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Check whether the element has child elements.
- * let isParent = myXML.hasChildren();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Style the text.
- * if (isParent === true) {
- * text('Parent', 50, 50);
- * } else {
- * text('Not Parent', 50, 50);
- * }
- *
- * describe('The word "Parent" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Check whether the element has child elements.
+ * let isParent = myXML.hasChildren();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Style the text.
+ * if (isParent === true) {
+ * text('Parent', 50, 50);
+ * } else {
+ * text('Not Parent', 50, 50);
+ * }
+ *
+ * describe('The word "Parent" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the names of the element's children as an array.
- * let children = myXML.listChildren();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < children.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the child element's name.
- * text(children[i], 10, y);
- * }
- *
- * describe(
- * 'The words "mammal", "mammal", "mammal", and "reptile" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the names of the element's children as an array.
+ * let children = myXML.listChildren();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < children.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the child element's name.
+ * text(children[i], 10, y);
+ * }
+ *
+ * describe(
+ * 'The words "mammal", "mammal", "mammal", and "reptile" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array of the child elements.
- * let children = myXML.getChildren();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < children.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 20;
- *
- * // Get the child element's content.
- * let content = children[i].getContent();
- *
- * // Display the child element's content.
- * text(content, 10, y);
- * }
- *
- * describe(
- * 'The words "Goat", "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get an array of the child elements
- * // that are mammals.
- * let children = myXML.getChildren('mammal');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < children.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 20;
- *
- * // Get the child element's content.
- * let content = children[i].getContent();
- *
- * // Display the child element's content.
- * text(content, 10, y);
- * }
- *
- * describe(
- * 'The words "Goat", "Leopard", and "Zebra" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array of the child elements.
+ * let children = myXML.getChildren();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < children.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 20;
+ *
+ * // Get the child element's content.
+ * let content = children[i].getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 10, y);
+ * }
+ *
+ * describe(
+ * 'The words "Goat", "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get an array of the child elements
+ * // that are mammals.
+ * let children = myXML.getChildren('mammal');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < children.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 20;
+ *
+ * // Get the child element's content.
+ * let content = children[i].getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 10, y);
+ * }
+ *
+ * describe(
+ * 'The words "Goat", "Leopard", and "Zebra" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first child element that is a mammal.
- * let goat = myXML.getChild('mammal');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Get the child element's content.
- * let content = goat.getContent();
- *
- * // Display the child element's content.
- * text(content, 50, 50);
- *
- * describe('The word "Goat" written in black on a gray background.');
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the child element at index 1.
- * let leopard = myXML.getChild(1);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Get the child element's content.
- * let content = leopard.getContent();
- *
- * // Display the child element's content.
- * text(content, 50, 50);
- *
- * describe('The word "Leopard" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first child element that is a mammal.
+ * let goat = myXML.getChild('mammal');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Get the child element's content.
+ * let content = goat.getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 50, 50);
+ *
+ * describe('The word "Goat" written in black on a gray background.');
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the child element at index 1.
+ * let leopard = myXML.getChild(1);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Get the child element's content.
+ * let content = leopard.getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 50, 50);
+ *
+ * describe('The word "Leopard" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a new p5.XML object.
- * let newAnimal = new p5.XML();
- *
- * // Set its properties.
- * newAnimal.setName('hydrozoa');
- * newAnimal.setAttribute('id', 4);
- * newAnimal.setAttribute('species', 'Physalia physalis');
- * newAnimal.setContent('Bluebottle');
- *
- * // Add the child element.
- * myXML.addChild(newAnimal);
- *
- * // Get the first child element that is a hydrozoa.
- * let blueBottle = myXML.getChild('hydrozoa');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Get the child element's content.
- * let content = blueBottle.getContent();
- *
- * // Display the child element's content.
- * text(content, 50, 50);
- *
- * describe('The word "Bluebottle" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a new p5.XML object.
+ * let newAnimal = new p5.XML();
+ *
+ * // Set its properties.
+ * newAnimal.setName('hydrozoa');
+ * newAnimal.setAttribute('id', 4);
+ * newAnimal.setAttribute('species', 'Physalia physalis');
+ * newAnimal.setContent('Bluebottle');
+ *
+ * // Add the child element.
+ * myXML.addChild(newAnimal);
+ *
+ * // Get the first child element that is a hydrozoa.
+ * let blueBottle = myXML.getChild('hydrozoa');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Get the child element's content.
+ * let content = blueBottle.getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 50, 50);
+ *
+ * describe('The word "Bluebottle" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Remove the first mammal element.
- * myXML.removeChild('mammal');
- *
- * // Get an array of child elements.
- * let children = myXML.getChildren();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < children.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Get the child element's content.
- * let content = children[i].getContent();
- *
- * // Display the child element's content.
- * text(content, 10, y);
- * }
- *
- * describe(
- * 'The words "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Remove the element at index 2.
- * myXML.removeChild(2);
- *
- * // Get an array of child elements.
- * let children = myXML.getChildren();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < children.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Get the child element's content.
- * let content = children[i].getContent();
- *
- * // Display the child element's content.
- * text(content, 10, y);
- * }
- *
- * describe(
- * 'The words "Goat", "Leopard", and "Turtle" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Remove the first mammal element.
+ * myXML.removeChild('mammal');
+ *
+ * // Get an array of child elements.
+ * let children = myXML.getChildren();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < children.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Get the child element's content.
+ * let content = children[i].getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 10, y);
+ * }
+ *
+ * describe(
+ * 'The words "Leopard", "Zebra", and "Turtle" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Remove the element at index 2.
+ * myXML.removeChild(2);
+ *
+ * // Get an array of child elements.
+ * let children = myXML.getChildren();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < children.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Get the child element's content.
+ * let content = children[i].getContent();
+ *
+ * // Display the child element's content.
+ * text(content, 10, y);
+ * }
+ *
+ * describe(
+ * 'The words "Goat", "Leopard", and "Turtle" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first child element.
+ * let first = myXML.getChild(0);
+ *
+ * // Get the number of attributes.
+ * let numAttributes = first.getAttributeCount();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the number of attributes.
+ * text(numAttributes, 50, 50);
+ *
+ * describe('The number "2" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first child element.
- * let first = myXML.getChild(0);
- *
- * // Get the number of attributes.
- * let numAttributes = first.getAttributeCount();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the number of attributes.
- * text(numAttributes, 50, 50);
- *
- * describe('The number "2" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first child element.
+ * let first = myXML.getChild(0);
+ *
+ * // Get the number of attributes.
+ * let attributes = first.listAttributes();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's attributes.
+ * text(attributes, 50, 50);
+ *
+ * describe('The text "id,species" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first child element.
- * let first = myXML.getChild(0);
- *
- * // Get the number of attributes.
- * let attributes = first.listAttributes();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's attributes.
- * text(attributes, 50, 50);
- *
- * describe('The text "id,species" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first mammal child element.
+ * let mammal = myXML.getChild('mammal');
+ *
+ * // Check whether the element has an
+ * // species attribute.
+ * let hasSpecies = mammal.hasAttribute('species');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display whether the element has a species attribute.
+ * if (hasSpecies === true) {
+ * text('Species', 50, 50);
+ * } else {
+ * text('No species', 50, 50);
+ * }
+ *
+ * describe('The text "Species" written in black on a gray background.');
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first mammal child element.
- * let mammal = myXML.getChild('mammal');
- *
- * // Check whether the element has an
- * // species attribute.
- * let hasSpecies = mammal.hasAttribute('species');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display whether the element has a species attribute.
- * if (hasSpecies === true) {
- * text('Species', 50, 50);
- * } else {
- * text('No species', 50, 50);
- * }
- *
- * describe('The text "Species" written in black on a gray background.');
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Get the reptile's ID.
+ * let id = reptile.getNum('id');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the ID attribute.
+ * text(`${content} is ${id + 1}th`, 5, 50, 90);
+ *
+ * describe(`The text "${content} is ${id + 1}th" written in black on a gray background.`);
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Get the reptile's size.
+ * let weight = reptile.getNum('weight', 135);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the ID attribute.
+ * text(`${content} is ${weight}kg`, 5, 50, 90);
+ *
+ * describe(
+ * `The text "${content} is ${weight}kg" written in black on a gray background.`
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Get the reptile's ID.
- * let id = reptile.getNum('id');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the ID attribute.
- * text(`${content} is ${id + 1}th`, 5, 50, 90);
- *
- * describe(`The text "${content} is ${id + 1}th" written in black on a gray background.`);
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Get the reptile's size.
- * let weight = reptile.getNum('weight', 135);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the ID attribute.
- * text(`${content} is ${weight}kg`, 5, 50, 90);
- *
- * describe(
- * `The text "${content} is ${weight}kg" written in black on a gray background.`
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Get the reptile's species.
+ * let species = reptile.getString('species');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the species attribute.
+ * text(`${content}: ${species}`, 5, 50, 90);
+ *
+ * describe(`The text "${content}: ${species}" written in black on a gray background.`);
+ * }
+ *
+ *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Get the reptile's color.
+ * let attribute = reptile.getString('color', 'green');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ * fill(attribute);
+ *
+ * // Display the element's content.
+ * text(content, 50, 50);
+ *
+ * describe(`The text "${content}" written in green on a gray background.`);
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Get the reptile's species.
- * let species = reptile.getString('species');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the species attribute.
- * text(`${content}: ${species}`, 5, 50, 90);
- *
- * describe(`The text "${content}: ${species}" written in black on a gray background.`);
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Get the reptile's color.
- * let attribute = reptile.getString('color', 'green');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- * fill(attribute);
- *
- * // Display the element's content.
- * text(content, 50, 50);
- *
- * describe(`The text "${content}" written in green on a gray background.`);
- * }
- *
- *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Set the reptile's color.
- * reptile.setAttribute('color', 'green');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Get the reptile's color.
- * let attribute = reptile.getString('color');
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's content.
- * text(`${content} is ${attribute}`, 5, 50, 90);
- *
- * describe(
- * `The text "${content} is ${attribute}" written in green on a gray background.`
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Set the reptile's color.
+ * reptile.setAttribute('color', 'green');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Get the reptile's color.
+ * let attribute = reptile.getString('color');
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's content.
+ * text(`${content} is ${attribute}`, 5, 50, 90);
+ *
+ * describe(
+ * `The text "${content} is ${attribute}" written in green on a gray background.`
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's content.
- * let content = reptile.getContent();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's content.
- * text(content, 5, 50, 90);
- *
- * describe(`The text "${content}" written in green on a gray background.`);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a p5.XML object.
- * let blankSpace = new p5.XML();
- *
- * // Get the element's content and use a default value.
- * let content = blankSpace.getContent('Your name');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's content.
- * text(content, 5, 50, 90);
- *
- * describe(`The text "${content}" written in green on a gray background.`);
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's content.
+ * let content = reptile.getContent();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's content.
+ * text(content, 5, 50, 90);
+ *
+ * describe(`The text "${content}" written in green on a gray background.`);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a p5.XML object.
+ * let blankSpace = new p5.XML();
+ *
+ * // Get the element's content and use a default value.
+ * let content = blankSpace.getContent('Your name');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's content.
+ * text(content, 5, 50, 90);
+ *
+ * describe(`The text "${content}" written in green on a gray background.`);
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the first reptile child element.
- * let reptile = myXML.getChild('reptile');
- *
- * // Get the reptile's original content.
- * let oldContent = reptile.getContent();
- *
- * // Set the reptile's content.
- * reptile.setContent('Loggerhead');
- *
- * // Get the reptile's new content.
- * let newContent = reptile.getContent();
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(14);
- *
- * // Display the element's old and new content.
- * text(`${oldContent}: ${newContent}`, 5, 50, 90);
- *
- * describe(
- * `The text "${oldContent}: ${newContent}" written in green on a gray background.`
- * );
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the first reptile child element.
+ * let reptile = myXML.getChild('reptile');
+ *
+ * // Get the reptile's original content.
+ * let oldContent = reptile.getContent();
+ *
+ * // Set the reptile's content.
+ * reptile.setContent('Loggerhead');
+ *
+ * // Get the reptile's new content.
+ * let newContent = reptile.getContent();
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(14);
+ *
+ * // Display the element's old and new content.
+ * text(`${oldContent}: ${newContent}`, 5, 50, 90);
+ *
+ * describe(
+ * `The text "${oldContent}: ${newContent}" written in green on a gray background.`
+ * );
+ * }
+ *
+ *
- * let myXML;
- *
- * // Load the XML and create a p5.XML object.
- * function preload() {
- * myXML = loadXML('assets/animals.xml');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Display instructions.
- * text('Double-click to save', 5, 50, 90);
- *
- * describe('The text "Double-click to save" written in black on a gray background.');
- * }
- *
- * // Save the file when the user double-clicks.
- * function doubleClicked() {
- * // Create a p5.PrintWriter object.
- * // Use the file format .xml.
- * let myWriter = createWriter('animals', 'xml');
- *
- * // Serialize the XML data to a string.
- * let data = myXML.serialize();
- *
- * // Write the data to the print stream.
- * myWriter.write(data);
- *
- * // Save the file and close the print stream.
- * myWriter.close();
- * }
- *
- *
+ * let myXML;
+ *
+ * // Load the XML and create a p5.XML object.
+ * function preload() {
+ * myXML = loadXML('assets/animals.xml');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Display instructions.
+ * text('Double-click to save', 5, 50, 90);
+ *
+ * describe('The text "Double-click to save" written in black on a gray background.');
+ * }
+ *
+ * // Save the file when the user double-clicks.
+ * function doubleClicked() {
+ * // Create a p5.PrintWriter object.
+ * // Use the file format .xml.
+ * let myWriter = createWriter('animals', 'xml');
+ *
+ * // Serialize the XML data to a string.
+ * let data = myXML.serialize();
+ *
+ * // Write the data to the print stream.
+ * myWriter.write(data);
+ *
+ * // Save the file and close the print stream.
+ * myWriter.close();
+ * }
+ *
+ *
+ * function setup() {
+ * let myArray = ['Mango', 'Apple', 'Papaya'];
+ * print(myArray); // ['Mango', 'Apple', 'Papaya']
+ *
+ * append(myArray, 'Peach');
+ * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach']
+ * }
+ *
- * function setup() {
- * let myArray = ['Mango', 'Apple', 'Papaya'];
- * print(myArray); // ['Mango', 'Apple', 'Papaya']
- *
- * append(myArray, 'Peach');
- * print(myArray); // ['Mango', 'Apple', 'Papaya', 'Peach']
- * }
- *
+ * let src = ['A', 'B', 'C'];
+ * let dst = [1, 2, 3];
+ * let srcPosition = 1;
+ * let dstPosition = 0;
+ * let length = 2;
+ *
+ * print(src); // ['A', 'B', 'C']
+ * print(dst); // [ 1 , 2 , 3 ]
+ *
+ * arrayCopy(src, srcPosition, dst, dstPosition, length);
+ * print(dst); // ['B', 'C', 3]
+ *
- * let src = ['A', 'B', 'C'];
- * let dst = [1, 2, 3];
- * let srcPosition = 1;
- * let dstPosition = 0;
- * let length = 2;
- *
- * print(src); // ['A', 'B', 'C']
- * print(dst); // [ 1 , 2 , 3 ]
- *
- * arrayCopy(src, srcPosition, dst, dstPosition, length);
- * print(dst); // ['B', 'C', 3]
- *
+ * function setup() {
+ * let arr1 = ['A', 'B', 'C'];
+ * let arr2 = [1, 2, 3];
+ *
+ * print(arr1); // ['A','B','C']
+ * print(arr2); // [1,2,3]
+ *
+ * let arr3 = concat(arr1, arr2);
+ *
+ * print(arr1); // ['A','B','C']
+ * print(arr2); // [1, 2, 3]
+ * print(arr3); // ['A','B','C', 1, 2, 3]
+ * }
+ *
- * function setup() {
- * let arr1 = ['A', 'B', 'C'];
- * let arr2 = [1, 2, 3];
- *
- * print(arr1); // ['A','B','C']
- * print(arr2); // [1,2,3]
- *
- * let arr3 = concat(arr1, arr2);
- *
- * print(arr1); // ['A','B','C']
- * print(arr2); // [1, 2, 3]
- * print(arr3); // ['A','B','C', 1, 2, 3]
- * }
- *
+ * function setup() {
+ * let myArray = ['A', 'B', 'C'];
+ * print(myArray); // ['A','B','C']
+ *
+ * reverse(myArray);
+ * print(myArray); // ['C','B','A']
+ * }
+ *
- * function setup() {
- * let myArray = ['A', 'B', 'C'];
- * print(myArray); // ['A','B','C']
- *
- * reverse(myArray);
- * print(myArray); // ['C','B','A']
- * }
- *
+ * function setup() {
+ * let myArray = ['A', 'B', 'C'];
+ * print(myArray); // ['A', 'B', 'C']
+ * let newArray = shorten(myArray);
+ * print(myArray); // ['A','B','C']
+ * print(newArray); // ['A','B']
+ * }
+ *
- * function setup() {
- * let myArray = ['A', 'B', 'C'];
- * print(myArray); // ['A', 'B', 'C']
- * let newArray = shorten(myArray);
- * print(myArray); // ['A','B','C']
- * print(newArray); // ['A','B']
- * }
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of colors.
+ * let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
+ *
+ * // Create a shuffled copy of the array.
+ * let shuffledColors = shuffle(colors);
+ *
+ * // Draw a row of circles using the original array.
+ * for (let i = 0; i < colors.length; i += 1) {
+ * // Calculate the x-coordinate.
+ * let x = (i + 1) * 12.5;
+ *
+ * // Style the circle.
+ * let c = colors[i];
+ * fill(c);
+ *
+ * // Draw the circle.
+ * circle(x, 33, 10);
+ * }
+ *
+ * // Draw a row of circles using the original array.
+ * for (let i = 0; i < shuffledColors.length; i += 1) {
+ * // Calculate the x-coordinate.
+ * let x = (i + 1) * 12.5;
+ *
+ * // Style the circle.
+ * let c = shuffledColors[i];
+ * fill(c);
+ *
+ * // Draw the circle.
+ * circle(x, 67, 10);
+ * }
+ *
+ * describe(
+ * 'Two rows of circles on a gray background. The top row follows the color sequence ROYGBIV. The bottom row has all the same colors but they are shuffled.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of colors.
+ * let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
+ *
+ * // Shuffle the array.
+ * shuffle(colors, true);
+ *
+ * // Draw a row of circles using the original array.
+ * for (let i = 0; i < colors.length; i += 1) {
+ * // Calculate the x-coordinate.
+ * let x = (i + 1) * 12.5;
+ *
+ * // Style the circle.
+ * let c = colors[i];
+ * fill(c);
+ *
+ * // Draw the circle.
+ * circle(x, 50, 10);
+ * }
+ *
+ * describe(
+ * 'A row of colorful circles on a gray background. Their sequence changes each time the sketch runs.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of colors.
- * let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
- *
- * // Create a shuffled copy of the array.
- * let shuffledColors = shuffle(colors);
- *
- * // Draw a row of circles using the original array.
- * for (let i = 0; i < colors.length; i += 1) {
- * // Calculate the x-coordinate.
- * let x = (i + 1) * 12.5;
- *
- * // Style the circle.
- * let c = colors[i];
- * fill(c);
- *
- * // Draw the circle.
- * circle(x, 33, 10);
- * }
- *
- * // Draw a row of circles using the original array.
- * for (let i = 0; i < shuffledColors.length; i += 1) {
- * // Calculate the x-coordinate.
- * let x = (i + 1) * 12.5;
- *
- * // Style the circle.
- * let c = shuffledColors[i];
- * fill(c);
- *
- * // Draw the circle.
- * circle(x, 67, 10);
- * }
- *
- * describe(
- * 'Two rows of circles on a gray background. The top row follows the color sequence ROYGBIV. The bottom row has all the same colors but they are shuffled.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of colors.
- * let colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
- *
- * // Shuffle the array.
- * shuffle(colors, true);
- *
- * // Draw a row of circles using the original array.
- * for (let i = 0; i < colors.length; i += 1) {
- * // Calculate the x-coordinate.
- * let x = (i + 1) * 12.5;
- *
- * // Style the circle.
- * let c = colors[i];
- * fill(c);
- *
- * // Draw the circle.
- * circle(x, 50, 10);
- * }
- *
- * describe(
- * 'A row of colorful circles on a gray background. Their sequence changes each time the sketch runs.'
- * );
- * }
- *
- *
+ * function setup() {
+ * let words = ['banana', 'apple', 'pear', 'lime'];
+ * print(words); // ['banana', 'apple', 'pear', 'lime']
+ * let count = 4; // length of array
+ *
+ * words = sort(words, count);
+ * print(words); // ['apple', 'banana', 'lime', 'pear']
+ * }
+ *
+ * function setup() {
+ * let numbers = [2, 6, 1, 5, 14, 9, 8, 12];
+ * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]
+ * let count = 5; // Less than the length of the array
+ *
+ * numbers = sort(numbers, count);
+ * print(numbers); // [1,2,5,6,14,9,8,12]
+ * }
+ *
- * function setup() {
- * let words = ['banana', 'apple', 'pear', 'lime'];
- * print(words); // ['banana', 'apple', 'pear', 'lime']
- * let count = 4; // length of array
- *
- * words = sort(words, count);
- * print(words); // ['apple', 'banana', 'lime', 'pear']
- * }
- *
- * function setup() {
- * let numbers = [2, 6, 1, 5, 14, 9, 8, 12];
- * print(numbers); // [2, 6, 1, 5, 14, 9, 8, 12]
- * let count = 5; // Less than the length of the array
- *
- * numbers = sort(numbers, count);
- * print(numbers); // [1,2,5,6,14,9,8,12]
- * }
- *
+ * function setup() {
+ * let myArray = [0, 1, 2, 3, 4];
+ * let insArray = ['A', 'B', 'C'];
+ * print(myArray); // [0, 1, 2, 3, 4]
+ * print(insArray); // ['A','B','C']
+ *
+ * splice(myArray, insArray, 3);
+ * print(myArray); // [0,1,2,'A','B','C',3,4]
+ * }
+ *
- * function setup() {
- * let myArray = [0, 1, 2, 3, 4];
- * let insArray = ['A', 'B', 'C'];
- * print(myArray); // [0, 1, 2, 3, 4]
- * print(insArray); // ['A','B','C']
- *
- * splice(myArray, insArray, 3);
- * print(myArray); // [0,1,2,'A','B','C',3,4]
- * }
- *
+ * function setup() {
+ * let myArray = [1, 2, 3, 4, 5];
+ * print(myArray); // [1, 2, 3, 4, 5]
+ *
+ * let sub1 = subset(myArray, 0, 3);
+ * let sub2 = subset(myArray, 2, 2);
+ * print(sub1); // [1,2,3]
+ * print(sub2); // [3,4]
+ * }
+ *
- * function setup() {
- * let myArray = [1, 2, 3, 4, 5];
- * print(myArray); // [1, 2, 3, 4, 5]
- *
- * let sub1 = subset(myArray, 0, 3);
- * let sub2 = subset(myArray, 2, 2);
- * print(sub1); // [1,2,3]
- * print(sub2); // [3,4]
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = '12.3';
- *
- * // Convert the string to a number.
- * let converted = float(original);
- *
- * // Double the converted value.
- * let twice = converted * 2;
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(12);
- *
- * // Display the original and converted values.
- * text(`${original} × 2 = ${twice}`, 50, 50);
- *
- * describe('The text "12.3 × 2 = 24.6" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of strings.
- * let original = ['60', '30', '15'];
- *
- * // Convert the strings to numbers.
- * let diameters = float(original);
- *
- * for (let d of diameters) {
- * // Draw a circle.
- * circle(50, 50, d);
- * }
- *
- * describe('Three white, concentric circles on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a Boolean variable.
- * let original = false;
- *
- * // Convert the Boolean to an integer.
- * let converted = int(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "false : 0" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = '12.34';
- *
- * // Convert the string to an integer.
- * let converted = int(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Display the original and converted values.
- * text(`${original} ≈ ${converted}`, 50, 50);
- *
- * describe('The text "12.34 ≈ 12" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a decimal number variable.
- * let original = 12.34;
- *
- * // Convert the decimal number to an integer.
- * let converted = int(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Display the original and converted values.
- * text(`${original} ≈ ${converted}`, 50, 50);
- *
- * describe('The text "12.34 ≈ 12" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of strings.
- * let original = ['60', '30', '15'];
- *
- * // Convert the strings to integers.
- * let diameters = int(original);
- *
- * for (let d of diameters) {
- * // Draw a circle.
- * circle(50, 50, d);
- * }
- *
- * describe('Three white, concentric circles on a gray background.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = '12.3';
+ *
+ * // Convert the string to a number.
+ * let converted = float(original);
+ *
+ * // Double the converted value.
+ * let twice = converted * 2;
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(12);
+ *
+ * // Display the original and converted values.
+ * text(`${original} × 2 = ${twice}`, 50, 50);
+ *
+ * describe('The text "12.3 × 2 = 24.6" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of strings.
+ * let original = ['60', '30', '15'];
+ *
+ * // Convert the strings to numbers.
+ * let diameters = float(original);
+ *
+ * for (let d of diameters) {
+ * // Draw a circle.
+ * circle(50, 50, d);
+ * }
+ *
+ * describe('Three white, concentric circles on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a Boolean variable.
- * let original = false;
- *
- * // Convert the Boolean to a string.
- * let converted = str(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "false : false" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 123;
- *
- * // Convert the number to a string.
- * let converted = str(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} = ${converted}`, 50, 50);
- *
- * describe('The text "123 = 123" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of numbers.
- * let original = [12, 34, 56];
- *
- * // Convert the numbers to strings.
- * let strings = str(original);
- *
- * // Create an empty string variable.
- * let final = '';
- *
- * // Concatenate all the strings.
- * for (let s of strings) {
- * final += s;
- * }
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the concatenated string.
- * text(final, 50, 50);
- *
- * describe('The text "123456" written in black on a gray background.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a Boolean variable.
+ * let original = false;
+ *
+ * // Convert the Boolean to an integer.
+ * let converted = int(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "false : 0" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = '12.34';
+ *
+ * // Convert the string to an integer.
+ * let converted = int(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Display the original and converted values.
+ * text(`${original} ≈ ${converted}`, 50, 50);
+ *
+ * describe('The text "12.34 ≈ 12" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a decimal number variable.
+ * let original = 12.34;
+ *
+ * // Convert the decimal number to an integer.
+ * let converted = int(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Display the original and converted values.
+ * text(`${original} ≈ ${converted}`, 50, 50);
+ *
+ * describe('The text "12.34 ≈ 12" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of strings.
+ * let original = ['60', '30', '15'];
+ *
+ * // Convert the strings to integers.
+ * let diameters = int(original);
+ *
+ * for (let d of diameters) {
+ * // Draw a circle.
+ * circle(50, 50, d);
+ * }
+ *
+ * describe('Three white, concentric circles on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 0;
- *
- * // Convert the number to a Boolean value.
- * let converted = boolean(original);
- *
- * // Style the circle based on the converted value.
- * if (converted === true) {
- * fill('blue');
- * } else {
- * fill('red');
- * }
- *
- * // Draw the circle.
- * circle(50, 50, 40);
- *
- * describe('A red circle on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = 'true';
- *
- * // Convert the string to a Boolean value.
- * let converted = boolean(original);
- *
- * // Style the circle based on the converted value.
- * if (converted === true) {
- * fill('blue');
- * } else {
- * fill('red');
- * }
- *
- * // Draw the circle.
- * circle(50, 50, 40);
- *
- * describe('A blue circle on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of values.
- * let original = [0, 'hi', 123, 'true'];
- *
- * // Convert the array to a Boolean values.
- * let converted = boolean(original);
- *
- * // Iterate over the array of converted Boolean values.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Style the circle based on the converted value.
- * if (converted[i] === true) {
- * fill('blue');
- * } else {
- * fill('red');
- * }
- *
- * // Calculate the x-coordinate.
- * let x = (i + 1) * 20;
- *
- * // Draw the circle.
- * circle(x, 50, 15);
- * }
- *
- * describe(
- * 'A row of circles on a gray background. The two circles on the left are red and the two on the right are blue.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a Boolean variable.
+ * let original = false;
+ *
+ * // Convert the Boolean to a string.
+ * let converted = str(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "false : false" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 123;
+ *
+ * // Convert the number to a string.
+ * let converted = str(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} = ${converted}`, 50, 50);
+ *
+ * describe('The text "123 = 123" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of numbers.
+ * let original = [12, 34, 56];
+ *
+ * // Convert the numbers to strings.
+ * let strings = str(original);
+ *
+ * // Create an empty string variable.
+ * let final = '';
+ *
+ * // Concatenate all the strings.
+ * for (let s of strings) {
+ * final += s;
+ * }
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the concatenated string.
+ * text(final, 50, 50);
+ *
+ * describe('The text "123456" written in black on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a Boolean variable.
- * let original = true;
- *
- * // Convert the Boolean to its byte value.
- * let converted = byte(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "true : 1" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = '256';
- *
- * // Convert the string to its byte value.
- * let converted = byte(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "256 : 0" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 256;
- *
- * // Convert the number to its byte value.
- * let converted = byte(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "256 : 0" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of values.
- * let original = [false, '64', 383];
- *
- * // Convert the array elements to their byte values.
- * let converted = byte(original);
- *
- * // Iterate over the converted array elements.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Style the circle.
- * fill(converted[i]);
- *
- * // Calculate the x-coordinate.
- * let x = (i + 1) * 25;
- *
- * // Draw the circle.
- * circle(x, 50, 20);
- * }
- *
- * describe(
- * 'Three gray circles on a gray background. The circles get lighter from left to right.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 0;
+ *
+ * // Convert the number to a Boolean value.
+ * let converted = boolean(original);
+ *
+ * // Style the circle based on the converted value.
+ * if (converted === true) {
+ * fill('blue');
+ * } else {
+ * fill('red');
+ * }
+ *
+ * // Draw the circle.
+ * circle(50, 50, 40);
+ *
+ * describe('A red circle on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = 'true';
+ *
+ * // Convert the string to a Boolean value.
+ * let converted = boolean(original);
+ *
+ * // Style the circle based on the converted value.
+ * if (converted === true) {
+ * fill('blue');
+ * } else {
+ * fill('red');
+ * }
+ *
+ * // Draw the circle.
+ * circle(50, 50, 40);
+ *
+ * describe('A blue circle on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of values.
+ * let original = [0, 'hi', 123, 'true'];
+ *
+ * // Convert the array to a Boolean values.
+ * let converted = boolean(original);
+ *
+ * // Iterate over the array of converted Boolean values.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Style the circle based on the converted value.
+ * if (converted[i] === true) {
+ * fill('blue');
+ * } else {
+ * fill('red');
+ * }
+ *
+ * // Calculate the x-coordinate.
+ * let x = (i + 1) * 20;
+ *
+ * // Draw the circle.
+ * circle(x, 50, 15);
+ * }
+ *
+ * describe(
+ * 'A row of circles on a gray background. The two circles on the left are red and the two on the right are blue.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 65;
- *
- * // Convert the number to a char.
- * let converted = char(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "65 : A" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = '65';
- *
- * // Convert the string to a char.
- * let converted = char(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "65 : A" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of numbers.
- * let original = ['65', 66, '67'];
- *
- * // Convert the string to a char.
- * let converted = char(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Iterate over elements of the converted array.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the original and converted values.
- * text(`${original[i]} : ${converted[i]}`, 50, y);
- * }
- *
- * describe(
- * 'The text "65 : A", "66 : B", and "67 : C" written on three separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a Boolean variable.
+ * let original = true;
+ *
+ * // Convert the Boolean to its byte value.
+ * let converted = byte(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "true : 1" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = '256';
+ *
+ * // Convert the string to its byte value.
+ * let converted = byte(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "256 : 0" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 256;
+ *
+ * // Convert the number to its byte value.
+ * let converted = byte(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "256 : 0" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of values.
+ * let original = [false, '64', 383];
+ *
+ * // Convert the array elements to their byte values.
+ * let converted = byte(original);
+ *
+ * // Iterate over the converted array elements.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Style the circle.
+ * fill(converted[i]);
+ *
+ * // Calculate the x-coordinate.
+ * let x = (i + 1) * 25;
+ *
+ * // Draw the circle.
+ * circle(x, 50, 20);
+ * }
+ *
+ * describe(
+ * 'Three gray circles on a gray background. The circles get lighter from left to right.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let original = 'A';
- *
- * // Convert the string to a number.
- * let converted = unchar(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} : ${converted}`, 50, 50);
- *
- * describe('The text "A : 65" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of characters.
- * let original = ['A', 'B', 'C'];
- *
- * // Convert the string to a number.
- * let converted = unchar(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Iterate over elements of the converted array.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the original and converted values.
- * text(`${original[i]} : ${converted[i]}`, 50, y);
- * }
- *
- * describe(
- * 'The text "A : 65", "B : 66", and "C :67" written on three separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 65;
+ *
+ * // Convert the number to a char.
+ * let converted = char(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "65 : A" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = '65';
+ *
+ * // Convert the string to a char.
+ * let converted = char(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "65 : A" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of numbers.
+ * let original = ['65', 66, '67'];
+ *
+ * // Convert the string to a char.
+ * let converted = char(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Iterate over elements of the converted array.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the original and converted values.
+ * text(`${original[i]} : ${converted[i]}`, 50, y);
+ * }
+ *
+ * describe(
+ * 'The text "65 : A", "66 : B", and "67 : C" written on three separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 20;
- *
- * // Convert the number to a hex string.
- * let converted = hex(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Display the original and converted values.
- * text(`${original} = ${converted}`, 50, 50);
- *
- * describe('The text "20 = 00000014" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let original = 20;
- *
- * // Convert the number to a hex string.
- * // Only display two hex digits.
- * let converted = hex(original, 2);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} = ${converted}`, 50, 50);
- *
- * describe('The text "20 = 14" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of numbers.
- * let original = [1, 10, 100];
- *
- * // Convert the numbers to hex strings.
- * // Only use two hex digits.
- * let converted = hex(original, 2);
- *
- * // Style the text.
- * textAlign(RIGHT, CENTER);
- * textSize(16);
- *
- * // Iterate over the converted values.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the original and converted values.
- * text(`${ original[i]} = ${converted[i]}`, 75, y);
- * }
- *
- * describe(
- * 'The text "1 = 01", "10 = 0A", and "100 = 64" written on three separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let original = 'A';
+ *
+ * // Convert the string to a number.
+ * let converted = unchar(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} : ${converted}`, 50, 50);
+ *
+ * describe('The text "A : 65" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of characters.
+ * let original = ['A', 'B', 'C'];
+ *
+ * // Convert the string to a number.
+ * let converted = unchar(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Iterate over elements of the converted array.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the original and converted values.
+ * text(`${original[i]} : ${converted[i]}`, 50, y);
+ * }
+ *
+ * describe(
+ * 'The text "A : 65", "B : 66", and "C :67" written on three separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 20;
+ *
+ * // Convert the number to a hex string.
+ * let converted = hex(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Display the original and converted values.
+ * text(`${original} = ${converted}`, 50, 50);
+ *
+ * describe('The text "20 = 00000014" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let original = 20;
+ *
+ * // Convert the number to a hex string.
+ * // Only display two hex digits.
+ * let converted = hex(original, 2);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} = ${converted}`, 50, 50);
+ *
+ * describe('The text "20 = 14" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of numbers.
+ * let original = [1, 10, 100];
+ *
+ * // Convert the numbers to hex strings.
+ * // Only use two hex digits.
+ * let converted = hex(original, 2);
+ *
+ * // Style the text.
+ * textAlign(RIGHT, CENTER);
+ * textSize(16);
+ *
+ * // Iterate over the converted values.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the original and converted values.
+ * text(`${ original[i]} = ${converted[i]}`, 75, y);
+ * }
+ *
+ * describe(
+ * 'The text "1 = 01", "10 = 0A", and "100 = 64" written on three separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a a hex string variable
+ * let original = 'FF';
+ *
+ * // Convert the hex string to a number.
+ * let converted = unhex(original);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the original and converted values.
+ * text(`${original} = ${converted}`, 50, 50);
+ *
+ * describe('The text "FF = 255" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of numbers.
+ * let original = ['00', '80', 'FF'];
+ *
+ * // Convert the numbers to hex strings.
+ * // Only use two hex digits.
+ * let converted = unhex(original, 2);
+ *
+ * // Style the text.
+ * textAlign(RIGHT, CENTER);
+ * textSize(16);
+ *
+ * // Iterate over the converted values.
+ * for (let i = 0; i < converted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the original and converted values.
+ * text(`${ original[i]} = ${converted[i]}`, 80, y);
+ * }
+ *
+ * describe(
+ * 'The text "00 = 0", "80 = 128", and "FF = 255" written on three separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a a hex string variable
- * let original = 'FF';
- *
- * // Convert the hex string to a number.
- * let converted = unhex(original);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the original and converted values.
- * text(`${original} = ${converted}`, 50, 50);
- *
- * describe('The text "FF = 255" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of numbers.
- * let original = ['00', '80', 'FF'];
- *
- * // Convert the numbers to hex strings.
- * // Only use two hex digits.
- * let converted = unhex(original, 2);
- *
- * // Style the text.
- * textAlign(RIGHT, CENTER);
- * textSize(16);
- *
- * // Iterate over the converted values.
- * for (let i = 0; i < converted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the original and converted values.
- * text(`${ original[i]} = ${converted[i]}`, 80, y);
- * }
- *
- * describe(
- * 'The text "00 = 0", "80 = 128", and "FF = 255" written on three separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of strings.
+ * let myWords = ['one', 'two', 'three'];
+ *
+ * // Create a combined string
+ * let combined = join(myWords, ' : ');
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ *
+ * // Display the combined string.
+ * text(combined, 50, 50);
+ *
+ * describe('The text "one : two : three" written in black on a gray canvas.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of strings.
- * let myWords = ['one', 'two', 'three'];
- *
- * // Create a combined string
- * let combined = join(myWords, ' : ');
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- *
- * // Display the combined string.
- * text(combined, 50, 50);
- *
- * describe('The text "one : two : three" written in black on a gray canvas.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'Hello, p5*js!';
- *
- * // Match the characters that are lowercase
- * // letters followed by digits.
- * let matches = match(string, '[a-z][0-9]');
- *
- * // Print the matches array to the console:
- * // ['p5']
- * print(matches);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the matches.
- * text(matches, 50, 50);
- *
- * describe('The text "p5" written in black on a gray canvas.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'Hello, p5*js!';
+ *
+ * // Match the characters that are lowercase
+ * // letters followed by digits.
+ * let matches = match(string, '[a-z][0-9]');
+ *
+ * // Print the matches array to the console:
+ * // ['p5']
+ * print(matches);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the matches.
+ * text(matches, 50, 50);
+ *
+ * describe('The text "p5" written in black on a gray canvas.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'p5*js is easier than abc123';
- *
- * // Match the character sequences that are
- * // lowercase letters followed by digits.
- * let matches = matchAll(string, '[a-z][0-9]');
- *
- * // Print the matches array to the console:
- * // [['p5'], ['c1']]
- * print(matches);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Iterate over the matches array.
- * for (let i = 0; i < matches.length; i += 1) {
- *
- * // Calculate the y-coordainate.
- * let y = (i + 1) * 33;
- *
- * // Display the match.
- * text(matches[i], 50, y);
- * }
- *
- * describe(
- * 'The text "p5" and "c1" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'p5*js is easier than abc123';
+ *
+ * // Match the character sequences that are
+ * // lowercase letters followed by digits.
+ * let matches = matchAll(string, '[a-z][0-9]');
+ *
+ * // Print the matches array to the console:
+ * // [['p5'], ['c1']]
+ * print(matches);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Iterate over the matches array.
+ * for (let i = 0; i < matches.length; i += 1) {
+ *
+ * // Calculate the y-coordainate.
+ * let y = (i + 1) * 33;
+ *
+ * // Display the match.
+ * text(matches[i], 50, y);
+ * }
+ *
+ * describe(
+ * 'The text "p5" and "c1" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(16);
- *
- * // Create a number variable.
- * let number = 123.45;
- *
- * // Display the number as a string.
- * let formatted = nf(number);
- * text(formatted, 20, 25);
- *
- * // Display the number with four digits
- * // to the left of the decimal.
- * let left = nf(number, 4);
- * text(left, 20, 50);
- *
- * // Display the number with four digits
- * // to the left of the decimal and one
- * // to the right.
- * let right = nf(number, 4, 1);
- * text(right, 20, 75);
- *
- * describe(
- * 'The numbers "123.45", "0123.45", and "0123.5" written on three separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(16);
+ *
+ * // Create a number variable.
+ * let number = 123.45;
+ *
+ * // Display the number as a string.
+ * let formatted = nf(number);
+ * text(formatted, 20, 25);
+ *
+ * // Display the number with four digits
+ * // to the left of the decimal.
+ * let left = nf(number, 4);
+ * text(left, 20, 50);
+ *
+ * // Display the number with four digits
+ * // to the left of the decimal and one
+ * // to the right.
+ * let right = nf(number, 4, 1);
+ * text(right, 20, 75);
+ *
+ * describe(
+ * 'The numbers "123.45", "0123.45", and "0123.5" written on three separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(16);
- *
- * // Create a number variable.
- * let number = 12345;
- *
- * // Display the number as a string.
- * let commas = nfc(number);
- * text(commas, 15, 33);
- *
- * // Display the number with four digits
- * // to the left of the decimal.
- * let decimals = nfc(number, 2);
- * text(decimals, 15, 67);
- *
- * describe(
- * 'The numbers "12,345" and "12,345.00" written on separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of numbers.
- * let numbers = [12345, 6789];
- *
- * // Convert the numbers to formatted strings.
- * let formatted = nfc(numbers);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < formatted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 33;
- *
- * // Display the original and formatted numbers.
- * text(`${numbers[i]} : ${formatted[i]}`, 50, y);
- * }
- *
- * describe(
- * 'The text "12345 : 12,345" and "6789 : 6,789" written on two separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(16);
+ *
+ * // Create a number variable.
+ * let number = 12345;
+ *
+ * // Display the number as a string.
+ * let commas = nfc(number);
+ * text(commas, 15, 33);
+ *
+ * // Display the number with four digits
+ * // to the left of the decimal.
+ * let decimals = nfc(number, 2);
+ * text(decimals, 15, 67);
+ *
+ * describe(
+ * 'The numbers "12,345" and "12,345.00" written on separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of numbers.
+ * let numbers = [12345, 6789];
+ *
+ * // Convert the numbers to formatted strings.
+ * let formatted = nfc(numbers);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < formatted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 33;
+ *
+ * // Display the original and formatted numbers.
+ * text(`${numbers[i]} : ${formatted[i]}`, 50, y);
+ * }
+ *
+ * describe(
+ * 'The text "12345 : 12,345" and "6789 : 6,789" written on two separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create number variables.
- * let positive = 123;
- * let negative = -123;
- *
- * // Convert the positive number to a formatted string.
- * let p = nfp(positive);
- *
- * // Convert the negative number to a formatted string
- * // with four digits to the left of the decimal
- * // and two digits to the right of the decimal.
- * let n = nfp(negative, 4, 2);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Display the original and formatted numbers.
- * text(`${positive} : ${p}`, 50, 33);
- * text(`${negative} : ${n}`, 50, 67);
- *
- * describe(
- * 'The text "123 : +123" and "-123 : -123.00" written on separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create number variables.
- * let numbers = [123, -4.56];
- *
- * // Convert the numbers to formatted strings
- * // with four digits to the left of the decimal
- * // and one digit to the right of the decimal.
- * let formatted = nfp(numbers, 4, 1);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(14);
- *
- * // Iterate over the array.
- * for (let i = 0; i < formatted.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 33;
- *
- * // Display the original and formatted numbers.
- * text(`${numbers[i]} : ${formatted[i]}`, 50, y);
- * }
- *
- * describe(
- * 'The text "123 : +0123.0" and "-4.56 : 00-4.6" written on separate lines. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create number variables.
+ * let positive = 123;
+ * let negative = -123;
+ *
+ * // Convert the positive number to a formatted string.
+ * let p = nfp(positive);
+ *
+ * // Convert the negative number to a formatted string
+ * // with four digits to the left of the decimal
+ * // and two digits to the right of the decimal.
+ * let n = nfp(negative, 4, 2);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Display the original and formatted numbers.
+ * text(`${positive} : ${p}`, 50, 33);
+ * text(`${negative} : ${n}`, 50, 67);
+ *
+ * describe(
+ * 'The text "123 : +123" and "-123 : -123.00" written on separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create number variables.
+ * let numbers = [123, -4.56];
+ *
+ * // Convert the numbers to formatted strings
+ * // with four digits to the left of the decimal
+ * // and one digit to the right of the decimal.
+ * let formatted = nfp(numbers, 4, 1);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(14);
+ *
+ * // Iterate over the array.
+ * for (let i = 0; i < formatted.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 33;
+ *
+ * // Display the original and formatted numbers.
+ * text(`${numbers[i]} : ${formatted[i]}`, 50, y);
+ * }
+ *
+ * describe(
+ * 'The text "123 : +0123.0" and "-4.56 : 00-4.6" written on separate lines. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create number variables.
+ * let positive = 123;
+ * let negative = -123;
+ *
+ * // Convert the positive number to a formatted string.
+ * let formatted = nfs(positive);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(16);
+ *
+ * // Display the negative number and the formatted positive number.
+ * text(negative, 50, 33);
+ * text(formatted, 50, 67);
+ *
+ * describe(
+ * 'The numbers -123 and 123 written on separate lines. The numbers align vertically. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a number variable.
+ * let number = 123.45;
+ *
+ * // Convert the positive number to a formatted string.
+ * // Use four digits to the left of the decimal and
+ * // one digit to the right.
+ * let formatted = nfs(number, 4, 1);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(16);
+ *
+ * // Display a negative version of the number and
+ * // the formatted positive version.
+ * text('-0123.5', 50, 33);
+ * text(formatted, 50, 67);
+ *
+ * describe(
+ * 'The numbers "-0123.5" and "0123.5" written on separate lines. The numbers align vertically. The text is in black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create number variables.
- * let positive = 123;
- * let negative = -123;
- *
- * // Convert the positive number to a formatted string.
- * let formatted = nfs(positive);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(16);
- *
- * // Display the negative number and the formatted positive number.
- * text(negative, 50, 33);
- * text(formatted, 50, 67);
- *
- * describe(
- * 'The numbers -123 and 123 written on separate lines. The numbers align vertically. The text is in black on a gray background.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a number variable.
- * let number = 123.45;
- *
- * // Convert the positive number to a formatted string.
- * // Use four digits to the left of the decimal and
- * // one digit to the right.
- * let formatted = nfs(number, 4, 1);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(16);
- *
- * // Display a negative version of the number and
- * // the formatted positive version.
- * text('-0123.5', 50, 33);
- * text(formatted, 50, 67);
- *
- * describe(
- * 'The numbers "-0123.5" and "0123.5" written on separate lines. The numbers align vertically. The text is in black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'rock...paper...scissors';
+ *
+ * // Split the string at each ...
+ * let words = split(string, '...');
+ *
+ * // Print the array to the console:
+ * // ["rock", "paper", "scissors"]
+ * print(words);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(16);
+ *
+ * // Iterate over the words array.
+ * for (let i = 0; i < words.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 25;
+ *
+ * // Display the word.
+ * text(words[i], 50, y);
+ * }
+ *
+ * describe(
+ * 'The words "rock", "paper", and "scissors" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'rock...paper...scissors';
- *
- * // Split the string at each ...
- * let words = split(string, '...');
- *
- * // Print the array to the console:
- * // ["rock", "paper", "scissors"]
- * print(words);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(16);
- *
- * // Iterate over the words array.
- * for (let i = 0; i < words.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 25;
- *
- * // Display the word.
- * text(words[i], 50, y);
- * }
- *
- * describe(
- * 'The words "rock", "paper", and "scissors" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'rock paper scissors shoot';
+ *
+ * // Split the string at each space.
+ * let words = splitTokens(string);
+ *
+ * // Print the array to the console.
+ * print(words);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Iterate over the words array.
+ * for (let i = 0; i < words.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 20;
+ *
+ * // Display the word.
+ * text(words[i], 50, y);
+ * }
+ *
+ * describe(
+ * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'rock...paper...scissors...shoot';
+ *
+ * // Split the string at each ...
+ * let words = splitTokens(string, '...');
+ *
+ * // Print the array to the console.
+ * print(words);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Iterate over the words array.
+ * for (let i = 0; i < words.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 20;
+ *
+ * // Display the word.
+ * text(words[i], 50, y);
+ * }
+ *
+ * describe(
+ * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = 'rock;paper,scissors...shoot';
+ *
+ * // Split the string at each semicolon, comma, or ...
+ * let words = splitTokens(string, [';', ',', '...']);
+ *
+ * // Print the array to the console.
+ * print(words);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(12);
+ *
+ * // Iterate over the words array.
+ * for (let i = 0; i < words.length; i += 1) {
+ *
+ * // Calculate the y-coordinate.
+ * let y = (i + 1) * 20;
+ *
+ * // Display the word.
+ * text(words[i], 50, y);
+ * }
+ *
+ * describe(
+ * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'rock paper scissors shoot';
- *
- * // Split the string at each space.
- * let words = splitTokens(string);
- *
- * // Print the array to the console.
- * print(words);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Iterate over the words array.
- * for (let i = 0; i < words.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 20;
- *
- * // Display the word.
- * text(words[i], 50, y);
- * }
- *
- * describe(
- * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'rock...paper...scissors...shoot';
- *
- * // Split the string at each ...
- * let words = splitTokens(string, '...');
- *
- * // Print the array to the console.
- * print(words);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Iterate over the words array.
- * for (let i = 0; i < words.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 20;
- *
- * // Display the word.
- * text(words[i], 50, y);
- * }
- *
- * describe(
- * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = 'rock;paper,scissors...shoot';
- *
- * // Split the string at each semicolon, comma, or ...
- * let words = splitTokens(string, [';', ',', '...']);
- *
- * // Print the array to the console.
- * print(words);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(12);
- *
- * // Iterate over the words array.
- * for (let i = 0; i < words.length; i += 1) {
- *
- * // Calculate the y-coordinate.
- * let y = (i + 1) * 20;
- *
- * // Display the word.
- * text(words[i], 50, y);
- * }
- *
- * describe(
- * 'The words "rock", "paper", "scissors", and "shoot" written on separate lines. The text is black on a gray background.'
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create a string variable.
+ * let string = ' p5*js ';
+ *
+ * // Trim the whitespace.
+ * let trimmed = trim(string);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textSize(16);
+ *
+ * // Display the text.
+ * text(`Hello, ${trimmed}!`, 50, 50);
+ *
+ * describe('The text "Hello, p5*js!" written in black on a gray background.');
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Create an array of strings.
+ * let strings = [' wide ', '\n open ', '\n spaces '];
+ *
+ * // Trim the whitespace.
+ * let trimmed = trim(strings);
+ *
+ * // Style the text.
+ * textAlign(CENTER, CENTER);
+ * textFont('Courier New');
+ * textSize(10);
+ *
+ * // Display the text.
+ * text(`${trimmed[0]} ${trimmed[1]} ${trimmed[2]}`, 50, 50);
+ *
+ * describe('The text "wide open spaces" written in black on a gray background.');
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create a string variable.
- * let string = ' p5*js ';
- *
- * // Trim the whitespace.
- * let trimmed = trim(string);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textSize(16);
- *
- * // Display the text.
- * text(`Hello, ${trimmed}!`, 50, 50);
- *
- * describe('The text "Hello, p5*js!" written in black on a gray background.');
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Create an array of strings.
- * let strings = [' wide ', '\n open ', '\n spaces '];
- *
- * // Trim the whitespace.
- * let trimmed = trim(strings);
- *
- * // Style the text.
- * textAlign(CENTER, CENTER);
- * textFont('Courier New');
- * textSize(10);
- *
- * // Display the text.
- * text(`${trimmed[0]} ${trimmed[1]} ${trimmed[2]}`, 50, 50);
- *
- * describe('The text "wide open spaces" written in black on a gray background.');
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current day.
+ * let d = day();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the day.
+ * text(`Current day: ${d}`, 20, 50, 60);
+ *
+ * describe(`The text 'Current day: ${d}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current day.
- * let d = day();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the day.
- * text(`Current day: ${d}`, 20, 50, 60);
- *
- * describe(`The text 'Current day: ${d}' written in black on a gray background.`);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current hour.
+ * let h = hour();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the hour.
+ * text(`Current hour: ${h}`, 20, 50, 60);
+ *
+ * describe(`The text 'Current hour: ${h}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current hour.
- * let h = hour();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the hour.
- * text(`Current hour: ${h}`, 20, 50, 60);
- *
- * describe(`The text 'Current hour: ${h}' written in black on a gray background.`);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current minute.
+ * let m = minute();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the minute.
+ * text(`Current minute: ${m}`, 10, 50, 80);
+ *
+ * describe(`The text 'Current minute: ${m}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current minute.
- * let m = minute();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the minute.
- * text(`Current minute: ${m}`, 10, 50, 80);
- *
- * describe(`The text 'Current minute: ${m}' written in black on a gray background.`);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the number of milliseconds the sketch has run.
+ * let ms = millis();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(10);
+ * textFont('Courier New');
+ *
+ * // Display how long it took setup() to be called.
+ * text(`Startup time: ${round(ms, 2)} ms`, 5, 50, 90);
+ *
+ * describe(
+ * `The text 'Startup time: ${round(ms, 2)} ms' written in black on a gray background.`
+ * );
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('The text "Running time: S sec" written in black on a gray background. The number S increases as the sketch runs.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Get the number of seconds the sketch has run.
+ * let s = millis() / 1000;
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(10);
+ * textFont('Courier New');
+ *
+ * // Display how long the sketch has run.
+ * text(`Running time: ${nf(s, 1, 1)} sec`, 5, 50, 90);
+ * }
+ *
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * describe('A white circle oscillates left and right on a gray background.');
+ * }
+ *
+ * function draw() {
+ * background(200);
+ *
+ * // Get the number of seconds the sketch has run.
+ * let s = millis() / 1000;
+ *
+ * // Calculate an x-coordinate.
+ * let x = 30 * sin(s) + 50;
+ *
+ * // Draw the circle.
+ * circle(x, 50, 30);
+ * }
+ *
+ *
+ * // Load the GeoJSON.
+ * function preload() {
+ * loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
+ * }
+ *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the number of milliseconds the sketch has run.
+ * let ms = millis();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textFont('Courier New');
+ * textSize(11);
+ *
+ * // Display how long it took to load the data.
+ * text(`It took ${round(ms, 2)} ms to load the data`, 5, 50, 100);
+ *
+ * describe(
+ * `The text "It took ${round(ms, 2)} ms to load the data" written in black on a gray background.`
+ * );
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the number of milliseconds the sketch has run.
- * let ms = millis();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(10);
- * textFont('Courier New');
- *
- * // Display how long it took setup() to be called.
- * text(`Startup time: ${round(ms, 2)} ms`, 5, 50, 90);
- *
- * describe(
- * `The text 'Startup time: ${round(ms, 2)} ms' written in black on a gray background.`
- * );
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('The text "Running time: S sec" written in black on a gray background. The number S increases as the sketch runs.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Get the number of seconds the sketch has run.
- * let s = millis() / 1000;
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(10);
- * textFont('Courier New');
- *
- * // Display how long the sketch has run.
- * text(`Running time: ${nf(s, 1, 1)} sec`, 5, 50, 90);
- * }
- *
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * describe('A white circle oscillates left and right on a gray background.');
- * }
- *
- * function draw() {
- * background(200);
- *
- * // Get the number of seconds the sketch has run.
- * let s = millis() / 1000;
- *
- * // Calculate an x-coordinate.
- * let x = 30 * sin(s) + 50;
- *
- * // Draw the circle.
- * circle(x, 50, 30);
- * }
- *
- *
- * // Load the GeoJSON.
- * function preload() {
- * loadJSON('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson');
- * }
- *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the number of milliseconds the sketch has run.
- * let ms = millis();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textFont('Courier New');
- * textSize(11);
- *
- * // Display how long it took to load the data.
- * text(`It took ${round(ms, 2)} ms to load the data`, 5, 50, 100);
- *
- * describe(
- * `The text "It took ${round(ms, 2)} ms to load the data" written in black on a gray background.`
- * );
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current month.
+ * let m = month();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the month.
+ * text(`Current month: ${m}`, 10, 50, 80);
+ *
+ * describe(`The text 'Current month: ${m}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current month.
- * let m = month();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the month.
- * text(`Current month: ${m}`, 10, 50, 80);
- *
- * describe(`The text 'Current month: ${m}' written in black on a gray background.`);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current second.
+ * let s = second();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the second.
+ * text(`Current second: ${s}`, 10, 50, 80);
+ *
+ * describe(`The text 'Current second: ${s}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current second.
- * let s = second();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the second.
- * text(`Current second: ${s}`, 10, 50, 80);
- *
- * describe(`The text 'Current second: ${s}' written in black on a gray background.`);
- * }
- *
- *
+ * function setup() {
+ * createCanvas(100, 100);
+ *
+ * background(200);
+ *
+ * // Get the current year.
+ * let y = year();
+ *
+ * // Style the text.
+ * textAlign(LEFT, CENTER);
+ * textSize(12);
+ * textFont('Courier New');
+ *
+ * // Display the year.
+ * text(`Current year: ${y}`, 10, 50, 80);
+ *
+ * describe(`The text 'Current year: ${y}' written in black on a gray background.`);
+ * }
+ *
+ *
- * function setup() {
- * createCanvas(100, 100);
- *
- * background(200);
- *
- * // Get the current year.
- * let y = year();
- *
- * // Style the text.
- * textAlign(LEFT, CENTER);
- * textSize(12);
- * textFont('Courier New');
- *
- * // Display the year.
- * text(`Current year: ${y}`, 10, 50, 80);
- *
- * describe(`The text 'Current year: ${y}' written in black on a gray background.`);
- * }
- *
- *