@@ -486,33 +486,27 @@ function files(p5, fn){
486
486
* @example
487
487
* <div class='norender'>
488
488
* <code>
489
- * // Given the following CSV file called "mammals.csv"
490
- * // located in the project's "assets" folder:
491
- * //
492
- * // id,species,name
493
- * // 0,Capra hircus,Goat
494
- * // 1,Panthera pardus,Leopard
495
- * // 2,Equus zebra,Zebra
496
- *
497
489
* let table;
498
490
*
499
491
* async function setup() {
500
- * table = await loadTable('assets/mammals.csv', 'csv', 'header');
501
- *
502
- * //count the columns
503
- * print(table.getRowCount() + ' total rows in table');
504
- * print(table.getColumnCount() + ' total columns in table');
505
- *
506
- * print(table.getColumn('name'));
507
- * //["Goat", "Leopard", "Zebra"]
508
- *
509
- * //cycle through the table
510
- * for (let r = 0; r < table.getRowCount(); r++)
511
- * for (let c = 0; c < table.getColumnCount(); c++) {
512
- * print(table.getString(r, c));
513
- * }
514
- * describe(`randomly generated text from a file,
515
- * for example "i smell like butter"`);
492
+ * // Create a 200x200 canvas
493
+ * createCanvas(200, 200);
494
+ *
495
+ * // Load the CSV file with a header row
496
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
497
+ *
498
+ * // Get the second row (index 1)
499
+ * let row = table.getRow(1);
500
+ *
501
+ * // Set text properties
502
+ * fill(0); // Set text color to black
503
+ * textSize(16); // Adjust text size as needed
504
+ *
505
+ * // Display each column value in the row on the canvas.
506
+ * // Using an offset for y-position so each value appears on a new line.
507
+ * for (let c = 0; c < table.getColumnCount(); c++) {
508
+ * text(row.getString(c), 10, 30 + c * 20);
509
+ * }
516
510
* }
517
511
* </code>
518
512
* </div>
@@ -754,19 +748,30 @@ function files(p5, fn){
754
748
* @returns {Promise<Uint8Array> } a Uint8Array containing the loaded buffer
755
749
*
756
750
* @example
757
- * <div class='norender'><code>
751
+ *
752
+ * <div>
753
+ * <code>
758
754
* let data;
759
755
*
760
756
* async function setup() {
761
- * data = await loadBytes('assets/mammals.xml');
757
+ * createCanvas(100, 100); // Create a canvas
758
+ * data = await loadBytes('assets/mammals.xml'); // Load the bytes from the XML file
762
759
*
763
- * for (let i = 0; i < 5; i++) {
764
- * console.log(data.bytes[i].toString(16));
765
- * }
766
- * describe('no image displayed');
760
+ * background(255); // Set a white background
761
+ * fill(0); // Set text color to black
762
+ *
763
+ * // Display the first 5 byte values on the canvas in hexadecimal format
764
+ * for (let i = 0; i < 5; i++) {
765
+ * let byteHex = data[i].toString(16);
766
+ * text(byteHex, 10, 18 * (i + 1)); // Adjust spacing as needed
767
767
* }
768
- * </code></div>
768
+ *
769
+ * describe('no image displayed, displays first 5 bytes of mammals.xml in hexadecimal format');
770
+ * }
771
+ * </code>
772
+ * </div>
769
773
*/
774
+
770
775
fn . loadBytes = async function ( path , successCallback , errorCallback ) {
771
776
try {
772
777
let { data } = await request ( path , 'arrayBuffer' ) ;
0 commit comments