From bd76ae4e3a88ef9f041b0af9a4e533b4f0bb7795 Mon Sep 17 00:00:00 2001 From: Gottfried Haider Date: Fri, 21 Jun 2024 22:37:56 +0800 Subject: [PATCH] Stylistic tweaks to example codes (#149) This is largely about normalizing the comment style (space after slashes, capitalization) *within individual files* - since those instantly jump at the reader. This is also bringing some tweaks made to the docsify MD files back to the examples (ImageClassfier). Co-authored-by: ziyuan-linn Co-authored-by: Daniel Shiffman --- examples/bodyPose-blazePose-skeleton/sketch.js | 4 ++-- examples/bodyPose-skeleton/sketch.js | 4 ++-- examples/faceMesh-bounding-box/sketch.js | 6 +++--- examples/imageClassifier-single-image/sketch.js | 4 ++-- .../imageClassifier-teachable-machine/sketch.js | 2 +- examples/imageClassifier-webcam/sketch.js | 8 ++++---- examples/sentiment/sketch.js | 14 +++++++------- 7 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/bodyPose-blazePose-skeleton/sketch.js b/examples/bodyPose-blazePose-skeleton/sketch.js index 1447cf2d..509043ee 100644 --- a/examples/bodyPose-blazePose-skeleton/sketch.js +++ b/examples/bodyPose-blazePose-skeleton/sketch.js @@ -26,7 +26,7 @@ function setup() { // Start detecting poses in the webcam video bodyPose.detectStart(video, gotPoses); - //get the skeleton connection information + // Get the skeleton connection information connections = bodyPose.getSkeleton(); } @@ -34,7 +34,7 @@ function draw() { // Draw the webcam video image(video, 0, 0, width, height); - //draw the skeleton connections + // Draw the skeleton connections for (let i = 0; i < poses.length; i++) { let pose = poses[i]; for (let j = 0; j < connections.length; j++) { diff --git a/examples/bodyPose-skeleton/sketch.js b/examples/bodyPose-skeleton/sketch.js index f3eb42e5..18527d2d 100644 --- a/examples/bodyPose-skeleton/sketch.js +++ b/examples/bodyPose-skeleton/sketch.js @@ -26,7 +26,7 @@ function setup() { // Start detecting poses in the webcam video bodyPose.detectStart(video, gotPoses); - //get the skeleton connection information + // Get the skeleton connection information connections = bodyPose.getSkeleton(); } @@ -34,7 +34,7 @@ function draw() { // Draw the webcam video image(video, 0, 0, width, height); - //draw the skeleton connections + // Draw the skeleton connections for (let i = 0; i < poses.length; i++) { let pose = poses[i]; for (let j = 0; j < connections.length; j++) { diff --git a/examples/faceMesh-bounding-box/sketch.js b/examples/faceMesh-bounding-box/sketch.js index 39f8d424..baf5a795 100644 --- a/examples/faceMesh-bounding-box/sketch.js +++ b/examples/faceMesh-bounding-box/sketch.js @@ -26,10 +26,10 @@ function setup() { } function draw() { - // draw the webcam video + // Draw the webcam video image(video, 0, 0, width, height); - // draw the faces' bounding boxes + // Draw the faces' bounding boxes for (let i = 0; i < faces.length; i++) { let face = faces[i]; let x = face.box.xMin; @@ -44,7 +44,7 @@ function draw() { rect(x, y, w, h); text(i, x, y - 10); - // draw the center of the face + // Draw the center of the face noStroke(); fill(255, 0, 0); circle(centerX, centerY, 10); diff --git a/examples/imageClassifier-single-image/sketch.js b/examples/imageClassifier-single-image/sketch.js index eb45f85a..1f5dd0d5 100644 --- a/examples/imageClassifier-single-image/sketch.js +++ b/examples/imageClassifier-single-image/sketch.js @@ -27,9 +27,9 @@ function setup() { image(img, 0, 0, width, height); } -// A function to run when we get any errors and the results +// Callback function for when classification has finished function gotResult(results) { - // The results are in an array ordered by confidence, print in console + // The results are in an array ordered by confidence console.log(results); // Display the results on the canvas diff --git a/examples/imageClassifier-teachable-machine/sketch.js b/examples/imageClassifier-teachable-machine/sketch.js index 09bf74d9..b59731aa 100644 --- a/examples/imageClassifier-teachable-machine/sketch.js +++ b/examples/imageClassifier-teachable-machine/sketch.js @@ -45,6 +45,6 @@ function draw() { // A function to run when we get the results function gotResult(results) { - // update label variable which is displayed on the canvas + // Update label variable which is displayed on the canvas label = results[0].label; } diff --git a/examples/imageClassifier-webcam/sketch.js b/examples/imageClassifier-webcam/sketch.js index 4775ace5..101c2194 100644 --- a/examples/imageClassifier-webcam/sketch.js +++ b/examples/imageClassifier-webcam/sketch.js @@ -31,17 +31,17 @@ function setup() { } function draw() { - //Each video frame is painted on the canvas + // Each video frame is painted on the canvas image(video, 0, 0); - //Printing class with the highest probability on the canvas + // Printing class with the highest probability on the canvas fill(255); textSize(32); text(label, 20, 50); } -// A function to run when we get the results and any errors +// Callback function for when classification has finished function gotResult(results) { - //update label variable which is displayed on the canvas + // Update label variable which is displayed on the canvas label = results[0].label; } diff --git a/examples/sentiment/sketch.js b/examples/sentiment/sketch.js index fcc6fa97..a674557b 100644 --- a/examples/sentiment/sketch.js +++ b/examples/sentiment/sketch.js @@ -12,37 +12,37 @@ let inputBox; let sentimentResult; function preload() { + // Initialize the sentiment analysis model sentiment = ml5.sentiment("MovieReviews"); } function setup() { noCanvas(); - // initialize sentiment analysis model - // setup the html dom elements + // Setup the DOM elements inputBox = createInput("Today is the happiest day and is full of rainbows!"); inputBox.attribute("size", "75"); submitBtn = createButton("submit"); sentimentResult = createP("Sentiment confidence:"); - // predicting the sentiment when submit button is pressed + // Start predicting when the submit button is pressed submitBtn.mousePressed(getSentiment); } function getSentiment() { - // get the values from the input + // Use the value of the input box let text = inputBox.value(); - // make the prediction + // Start making the prediction sentiment.predict(text, gotResult); } function gotResult(prediction) { - // display sentiment result on html page + // Display sentiment result via the DOM sentimentResult.html("Sentiment confidence: " + prediction.confidence); } -// predicting the sentiment when 'Enter' key is pressed +// Start predicting when the Enter key is pressed function keyPressed() { if (keyCode == ENTER) { getSentiment();