Skip to content

Commit 85d996f

Browse files
authored
Merge pull request #7638 from perminder-17/patch-1
loadbytes, loadTable and some minor fixes with other modified functions.
2 parents 6bc7526 + 6622093 commit 85d996f

File tree

5 files changed

+567
-409
lines changed

5 files changed

+567
-409
lines changed

src/io/files.js

Lines changed: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -486,33 +486,27 @@ function files(p5, fn){
486486
* @example
487487
* <div class='norender'>
488488
* <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-
*
497489
* let table;
498490
*
499491
* 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+
* }
516510
* }
517511
* </code>
518512
* </div>
@@ -754,19 +748,30 @@ function files(p5, fn){
754748
* @returns {Promise<Uint8Array>} a Uint8Array containing the loaded buffer
755749
*
756750
* @example
757-
* <div class='norender'><code>
751+
*
752+
* <div>
753+
* <code>
758754
* let data;
759755
*
760756
* 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
762759
*
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
767767
* }
768-
* </code></div>
768+
*
769+
* describe('no image displayed, displays first 5 bytes of mammals.xml in hexadecimal format');
770+
* }
771+
* </code>
772+
* </div>
769773
*/
774+
770775
fn.loadBytes = async function (path, successCallback, errorCallback) {
771776
try{
772777
let { data } = await request(path, 'arrayBuffer');

0 commit comments

Comments
 (0)