Skip to content

Commit

Permalink
Stylistic tweaks to example codes (#149)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Daniel Shiffman <[email protected]>
  • Loading branch information
3 people authored Jun 21, 2024
1 parent ee4a246 commit bd76ae4
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions examples/bodyPose-blazePose-skeleton/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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();
}

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++) {
Expand Down
4 changes: 2 additions & 2 deletions examples/bodyPose-skeleton/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ 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();
}

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++) {
Expand Down
6 changes: 3 additions & 3 deletions examples/faceMesh-bounding-box/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions examples/imageClassifier-single-image/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/imageClassifier-teachable-machine/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions examples/imageClassifier-webcam/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
14 changes: 7 additions & 7 deletions examples/sentiment/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit bd76ae4

Please sign in to comment.