fetch(url)
.then(response => response.text())
.then(text => {
// Remove the unwanted part of the response and parse JSON
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
let parsedData = rows.map(row => row.c.map(cell => cell ? cell.v : ''));
return parsedData;
}
function displayData() {
let x = sheetData.length;
// color on basis of value
//for (let i=1;i<sheetData.length;i++)
//{
//console.log(i);
var col1 = map(sheetData[x-1][0],1,3,0,150);
var col2 = map(sheetData[x-1][1],1,3,0,255);
var col3 = map(sheetData[x-1][2],1,3,0,255);
var col4 = map(sheetData[x-1][3],1,3,0,255);
var col5 = map(sheetData[x-1][4],1,3,0,255);
var col6 = map(sheetData[x-1][5],1,3,0,255);
var col7 = map(sheetData[x-1][6],1,3,0,255);
var col8 = map(sheetData[x-1][7],1,3,0,255);
var col9 = map(sheetData[x-1][8],1,3,0,255);
var col10 = map(sheetData[x-1][9],1,3,0,255);
var col11 = map(sheetData[x-1][10],1,3,0,255);
var col12 = map(sheetData[x-1][11],1,3,0,255);
var col13 = map(sheetData[x-1][12],1,3,0,255);
var col14 = map(sheetData[x-1][13],1,3,0,255);
var col15 = map(sheetData[x-1][14],1,3,0,255);
var col16 = map(sheetData[x-1][15],1,3,0,255);
var col17 = map(sheetData[x-1][16],1,3,0,255);
var col18 = map(sheetData[x-1][17],1,4,0,255);
// Character generation
//noStroke();
fill(col1,col2,col3);
circle(400,200,200); //Face
fill(col4,col5,col6);
ellipse(370,175,30,50); //Eyeleft
ellipse(430,175,30,50); //Eyeright
fill(col7,col8,col9);
rect(370,235,60,20); //Mouth
fill(col10,col11,col2);
square(250,300,300); //Body
fill(col13,col14,col5);
triangle(350,600,320,780,380,780); //Legleft
triangle(450,600,420,780,480,780); //Legright
fill(col16,col17,col8);
triangle(250,300,100,470,150,500); //Armleft
triangle(550,300,700,470,650,500); //Armleft
// }
}
rewrite the ps5js code to take multiple data from the sheet and create multiple characters based on the sheet
Assistant
To handle multiple rows from the Google Sheet and create multiple characters, you can iterate over each row in your sheetData and create a character for each.
Here's how you might modify your displayData function to achieve this:
javascript
User
let sheetData = [];
function setup() {
createCanvas(2000, 2000);
fetchData(); // Fetch data once on setup
noLoop(); // No need for continuous drawing
}
function displayData() {
const characterSpacing = 1000; // Distance between characters
let offsetX = 1, offsetY = 0;
let canvasWidth = 2000;
sheetData.forEach((data, index) => {
// Calculate starting position for each character
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 800; // Move to a new row on canvas if it reaches edge
}
code
let col1 = map(data[0], 1, 3, 0, 150);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation
fill(col1, col2, col3);
circle(offsetX + 400, offsetY + 200, 200); // Face
fill(col4, col5, col6);
ellipse(offsetX + 370, offsetY + 175, 30, 50); // Eye left
ellipse(offsetX + 430, offsetY + 175, 30, 50); // Eye right
fill(col7, col8, col9);
rect(offsetX + 370, offsetY + 235, 60, 20); // Mouth
fill(col10, col11, col2);
square(offsetX + 250, offsetY + 300, 300); // Body
fill(col13, col14, col5);
triangle(offsetX + 350, offsetY + 600, offsetX + 320, offsetY + 780, offsetX + 380, offsetY + 780); // Leg left
triangle(offsetX + 450, offsetY + 600, offsetX + 420, offsetY + 780, offsetX + 480, offsetY + 780); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 250, offsetY + 300, offsetX + 100, offsetY + 470, offsetX + 150, offsetY + 500); // Arm left
triangle(offsetX + 550, offsetY + 300, offsetX + 700, offsetY + 470, offsetX + 650, offsetY + 500); // Arm right
offsetX += characterSpacing;
Assistant
To modify the code to scale characters to three times smaller, highlight the last character for 10 seconds, make characters move, and display the row count, follow these steps:
Scaling Characters: We can achieve by adjusting the dimensions and positions to 1/3rd.
Highlight the Last Character: We can use a different color scheme for the last character and use setTimeout for timing.
Animating Characters: We'll use some basic movement logic to animate characters within the canvas.
Display Row Count: Use text() to display the row count at the top of the canvas.
Here's how you can implement these features:
javascript
User
text(Row Count:${sheetData.length},10,30);
shows an error - SyntaxError: missing ) after argument list
at /sketch.js:43:8
Assistant
It looks like there's a syntax error in how the text() function's argument is constructed. You need to include the string within quotes and ensure template literals are correctly formatted using backticks (`) instead of double quotes.
Here's the corrected line of code for the text() function:
javascript
text(`Row Count: ${sheetData.length}`, 10, 30);
The backticks allow the use of template literals, enabling you to interpolate variables directly into the string by wrapping them in ${}.
Make sure you replace the problematic line in your code with the corrected one above, and the issue should be resolved.
User
text(Row Count (sheetData.length), 10, 30);
SyntaxError: missing ) after argument list
correct the error
Assistant
It seems you've encountered a syntax error due to the way the text() function argument is formatted. When using string concatenation or interpolation in JavaScript, the syntax needs to be correct.
Here's how to fix it:
javascript
text("Row Count: " + sheetData.length, 10, 30);
Alternatively, you can use a template literal for more readability:
javascript
text(`Row Count: ${sheetData.length}`, 10, 30);
Both of these methods correctly format the string that will be displayed. The first method uses classic string concatenation using the + operator, while the second method uses template literals, which allow you to embed expressions inside a string. Make sure to use backticks (`) for template literals if you choose the second approach.
User
what is this - fill(highlight ? 255 : col1, highlight ? 0 : col2, highlight ? 0 : col3); , doing in above code
is using a ternary operator to conditionally set the fill color of the character's face based on whether it needs to be highlighted. Here's a breakdown of how it works:
Ternary Operator: This operator is a shorthand for an if-else statement. The general syntax is condition ? value_if_true : value_if_false.
Highlighting Logic:
highlight ? 255 : col1: This sets the red color component. If highlight is true, it uses 255, which is maximum intensity for red, making that part of the color brighter. If highlight is false, it uses col1, which is the normal color value calculated from the sheet data.
highlight ? 0 : col2: This sets the green color component. If highlight is true, it uses 0, making green value minimal and therefore making the appearance more red. If highlight is false, it uses col2.
highlight ? 0 : col3: This sets the blue color component. Similarly, if highlight is true, it uses 0, making the appearance more red by minimizing blue, else it uses col3.
In essence, when highlight is true (i.e., the character should be highlighted), the face of the character is filled with a bright red color (255, 0, 0). Otherwise, it uses the regular colors calculated from the sheet data (col1, col2, col3).
This technique allows you to easily toggle the character's appearance between two states: highlighted and normal.
User
let sheetData = [];
function setup() {
createCanvas(2000, 2000);
fetchData(); // Fetch data once on setup
noLoop(); // No need for continuous drawing
}
function displayData() {
const characterSpacing = 1000; // Distance between characters
let offsetX = 1, offsetY = 0;
let canvasWidth = 2000;
sheetData.forEach((data, index) => {
// Calculate starting position for each character
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 800; // Move to a new row on canvas if it reaches edge
}
let col1 = map(data[0], 1, 3, 0, 150);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
offsetX += characterSpacing;
});
}
rewrite the p5js code to scale the character to 6 times smaller and highlight the last character from the data for 10 seconds while giving the row count on the top of canvas.
Assistant
To adjust the code to scale the characters down to 1/6th of their original size, highlight the last character for 10 seconds, and display the row count at the top of the canvas, you can follow these steps:
Scale down the dimensions and positions of each character by a factor of 6.
Use a highlighting mechanism for the last character.
Display the row count using the text() function at the top of the canvas.
Here's how you might implement these adjustments:
javascript
User
let sheetData = [];
let lastCharacterStartTime = null;
let highlightDuration = 10000; // 10 seconds in milliseconds
function setup() {
createCanvas(2000, 2000);
textSize(32);
fetchData(); // Fetch data once on setup
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 166; // 1/6th of the original spacing
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
sheetData.forEach((data, index) => {
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 133; // Move to the next row
}
code
Assistant
To make the last character vibrate for 20 seconds instead of changing its face color to red, you would need to modify the position of the last character slightly and rapidly over time. This can be achieved by adding a small random offset to its position coordinates while still respecting the original positions set for each character.
Here's how you can implement the vibration effect for the last character:
javascript
User
let sheetData = [];
let lastCharacterStartTime = null;
let highlightDuration = 10000; // 10 seconds in milliseconds
function setup() {
createCanvas(2000, 2000);
textSize(32);
fetchData(); // Fetch data once on setup
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ‘’));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 166; // 1/6th of the original spacing
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
To adjust the code such that no special action (like highlighting) is taken on the last character and the character generation starts from row 1, you need to:
Remove the logic that changes the color or any special behavior for the last character.
Ensure that character generation consistently starts with the first row in the data.
Here's how you can modify your code accordingly:
javascript
User
let sheetData = [];
let lastCharacterStartTime = null;
function setup() {
createCanvas(2000, 2000);
textSize(16);
fetchData(); // Fetch data once on setup
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 100; // character spacing
let offsetX = 0, offsetY = 30; // character position
let canvasWidth = 2000;
sheetData.forEach((data, index) => {
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 130; // Move to the next row
}
code
// Calculate the colors from data
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 4, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation
fill(col1, col2, col3);
circle(offsetX + 67, offsetY + 33, 33); // Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Arm right
offsetX += characterSpacing;
Assistant
To exclude the first row of data (row 0) from being processed for character generation, you should adjust the loop to start from the second row. Here's how you can make the necessary changes to the code with comments highlighting where the change occurs:
javascript
User
let sheetData = [];
let lastCharacterStartTime = null;
function setup() {
createCanvas(2000, 2000);
textSize(16);
fetchData(); // Fetch data once on setup
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ‘’));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 100; // character spacing
let offsetX = 0, offsetY = 30; // character position
let canvasWidth = 2000;
// Skip the first row by starting index at 1
for (let index = 1; index < sheetData.length; index++) {
let data = sheetData[index];
code
Assistant
To highlight the last character, you can add a mechanism to check if the current character being drawn is the last one and then apply a temporary highlighting effect, such as a unique color or a vibration effect, for a set duration. Here’s how you can modify the code to highlight the last character for a short period:
Define Highlight Duration: Determine the duration for which you wish to highlight the character.
Highlight Logic: Within each iteration, check if the current character is the last one, and, if so, apply special effects.
Here's the revised version of your code with these changes:
javascript
Not yet included in a published release.
let sheetData = [];
function setup() {
createCanvas(2000, 2000);
fetchData(); // Fetch data once on setup
noLoop(); // No need for continuous drawing
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
const characterSpacing = 200; // Distance between characters
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
sheetData.forEach((data, index) => {
// Calculate starting position for each character
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 400; // Move to a new row on canvas if it reaches edge
}
let col1 = map(data[0], 1, 3, 0, 150);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation
fill(col1, col2, col3);
circle(offsetX + 400, offsetY + 200, 200); // Face
fill(col4, col5, col6);
ellipse(offsetX + 370, offsetY + 175, 30, 50); // Eye left
ellipse(offsetX + 430, offsetY + 175, 30, 50); // Eye right
fill(col7, col8, col9);
rect(offsetX + 370, offsetY + 235, 60, 20); // Mouth
fill(col10, col11, col2);
square(offsetX + 250, offsetY + 300, 300); // Body
fill(col13, col14, col5);
triangle(offsetX + 350, offsetY + 600, offsetX + 320, offsetY + 780, offsetX + 380, offsetY + 780); // Leg left
triangle(offsetX + 450, offsetY + 600, offsetX + 420, offsetY + 780, offsetX + 480, offsetY + 780); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 250, offsetY + 300, offsetX + 100, offsetY + 470, offsetX + 150, offsetY + 500); // Arm left
triangle(offsetX + 550, offsetY + 300, offsetX + 700, offsetY + 470, offsetX + 650, offsetY + 500); // Arm right
offsetX += characterSpacing;
});
}
Changes and Explanation:
No Loop: Removed the continuous loop by using noLoop(). fetchData is called once during setup(), and data is displayed once fetching is complete.
Character Placement: Calculated character placement (offsetX, offsetY) to ensure characters don't overlap and align correctly. This places characters in a grid format.
Iterating Over Data: Used forEach to go through each row of data and create a character for each.
Redrawing: draw() function is not needed as we don't need continuous updates after the initial render.
Make sure that your Google Sheet has data in the format expected and that each character's attributes (like color codes) are correctly formatted in the sheet. This function assumes all data rows are similar in length. Modify the color mapping ranges (like 1 to 3) according to your actual data range for more realistic colors.
});
}
rewrite the p5js code to scale the character to 3 times smaller and highlight the character from the end row for 10 seconds and make characters move in a the canvas while giving the row count on the top of canvas.
let sheetData = [];
let lastCharacterStartTime = null;
let movementSpeed = 1;
function setup() {
createCanvas(2000, 2000);
textSize(32);
fill(0);
fetchData(); // Fetch data once on setup
noLoop(); // No need for continuous drawing until data is fetched
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
lastCharacterStartTime = millis(); // Record start time
loop(); // Start the draw loop once data is ready
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function draw() {
background(255);
const characterSpacing = 333; // 1/3rd of the original spacing
let offsetX = movementSpeed;
let offsetY = 0;
let canvasWidth = 2000;
// Display row count
fill(0);
text(`Row Count: ${sheetData.length}`, 10, 30);
sheetData.forEach((data, index) => {
// Calculate starting position for each character
if (offsetX + characterSpacing > canvasWidth) {
offsetX = movementSpeed; // Reset offset to create a loop moving effect
offsetY += 267; // 1/3rd of the original row height
}
let isLastCharacter = (index === sheetData.length - 1);
let highlight = isLastCharacter && millis() - lastCharacterStartTime < 10000;
let col1 = map(data[0], 1, 3, 0, 150);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
fill(highlight ? 255 : col1, highlight ? 0 : col2, highlight ? 0 : col3);
// Character generation
circle(offsetX + 133, offsetY + 67, 67); // Scaled Face (200/3)
fill(col4, col5, col6);
ellipse(offsetX + 123, offsetY + 58, 10, 17); // Scaled Eye left
ellipse(offsetX + 143, offsetY + 58, 10, 17); // Scaled Eye right
fill(col7, col8, col9);
rect(offsetX + 123, offsetY + 78, 20, 7); // Scaled Mouth
fill(col10, col11, col2);
square(offsetX + 83, offsetY + 100, 100); // Scaled Body
fill(col13, col14, col5);
triangle(offsetX + 117, offsetY + 200, offsetX + 107, offsetY + 260, offsetX + 127, offsetY + 260); // Scaled Leg Left
triangle(offsetX + 150, offsetY + 200, offsetX + 140, offsetY + 260, offsetX + 160, offsetY + 260); // Scaled Leg Right
fill(col16, col17, col8);
triangle(offsetX + 83, offsetY + 100, offsetX + 33, offsetY + 157, offsetX + 50, offsetY + 167); // Scaled Arm Left
triangle(offsetX + 183, offsetY + 100, offsetX + 233, offsetY + 157, offsetX + 217, offsetY + 167); // Scaled Arm Right
offsetX += characterSpacing;
});
// Change direction if characters hit the edge of the canvas
if (offsetX > canvasWidth - characterSpacing || offsetX < 0) {
movementSpeed *= -1;
}
}
Key Changes:
Scale Characters: All character dimensions and placements are divided by 3.
Row Count: Displays the row count using text().
Highlighting Last Character: Uses millis() to highlight the last character for 10 seconds.
Animation: The draw() loop is utilized for movement, changing the offsetX based on a movementSpeed variable to animate the characters. Adjust the logic to create the desired effect of "movement".
This code assumes the Google Sheet contains appropriate numeric data in the columns corresponding to the indexed positions in the data array. You might want to tailor data mapping based on the actual range and meaning of your data if different.
let sheetData = [];
let lastCharacterStartTime = null;
let highlightDuration = 10000; // 10 seconds in milliseconds
function setup() {
createCanvas(2000, 2000);
textSize(32);
fetchData(); // Fetch data once on setup
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
lastCharacterStartTime = millis(); // Record start time for highlighting
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 166; // 1/6th of the original spacing
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
// Display row count
fill(0);
text(`Row Count: ${sheetData.length}`, 10, 30);
sheetData.forEach((data, index) => {
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 133; // Move to the next row
}
let isLastCharacter = (index === sheetData.length - 1);
let highlight = isLastCharacter && (millis() - lastCharacterStartTime < highlightDuration);
let col1 = map(data[0], 1, 3, 0, 150);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Highlight color scheme
let faceColor = highlight ? [255, 0, 0] : [col1, col2, col3];
// Character generation - scaled to 1/6th
fill(...faceColor);
circle(offsetX + 67, offsetY + 33, 33); // Scaled Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Scaled Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Scaled Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Scaled Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Scaled Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Scaled Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Scaled Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Scaled Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Scaled Arm right
offsetX += characterSpacing;
});
}
Key Adjustments:
Scale Factor: Dimensions and positions are divided by 6 to scale the character down to one-sixth its original size.
Highlight Logic: Uses a red color for the face of the last character for 10 seconds.
Display Row Count: Added text() to display row count at the top of the canvas.
This code assumes your Google Sheet provides numbers that can be mapped within the specified ranges. You should adjust the ranges as needed based on the data values you have.
let isLastCharacter = (index === sheetData.length - 1);
let highlight = isLastCharacter && (millis() - lastCharacterStartTime < highlightDuration);
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Highlight color scheme
let faceColor = highlight ? [255, 0, 0] : [col1, col2, col3];
// Character generation - scaled to 1/6th
fill(faceColor);
circle(offsetX + 67, offsetY + 33, 33); // Scaled Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Scaled Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Scaled Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Scaled Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Scaled Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Scaled Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Scaled Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Scaled Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Scaled Arm right
offsetX += characterSpacing;
});
}
Insteading of Highlighting the last character's face to red , can the last character vibrate alone for 20 seconds.
let sheetData = [];
let lastCharacterStartTime = null;
let vibrationDuration = 20000; // 20 seconds in milliseconds
function setup() {
createCanvas(2000, 2000);
textSize(32);
fetchData(); // Fetch data once on setup
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
lastCharacterStartTime = millis(); // Record start time for vibration
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 166; // 1/6th of the original spacing
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
// Display row count
fill(0);
text("Row Count: " + sheetData.length, 10, 30);
sheetData.forEach((data, index) => {
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 133; // Move to the next row
}
// Check if this is the last character
let isLastCharacter = (index === sheetData.length - 1);
let shouldVibrate = isLastCharacter && (millis() - lastCharacterStartTime < vibrationDuration);
// Apply a small random offset for vibration if it's the last character
let vibrationOffsetX = shouldVibrate ? random(-3, 3) : 0;
let vibrationOffsetY = shouldVibrate ? random(-3, 3) : 0;
// Color mapping
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation - scaled to 1/6th
fill(col1, col2, col3);
circle(offsetX + 67 + vibrationOffsetX, offsetY + 33 + vibrationOffsetY, 33); // Scaled Face
fill(col4, col5, col6);
ellipse(offsetX + 62 + vibrationOffsetX, offsetY + 29 + vibrationOffsetY, 5, 8); // Scaled Eye left
ellipse(offsetX + 72 + vibrationOffsetX, offsetY + 29 + vibrationOffsetY, 5, 8); // Scaled Eye right
fill(col7, col8, col9);
rect(offsetX + 62 + vibrationOffsetX, offsetY + 39 + vibrationOffsetY, 10, 3); // Scaled Mouth
fill(col10, col11, col2);
square(offsetX + 42 + vibrationOffsetX, offsetY + 50 + vibrationOffsetY, 50); // Scaled Body
fill(col13, col14, col5);
triangle(offsetX + 58 + vibrationOffsetX, offsetY + 100 + vibrationOffsetY, offsetX + 53 + vibrationOffsetX, offsetY + 130 + vibrationOffsetY, offsetX + 63 + vibrationOffsetX, offsetY + 130 + vibrationOffsetY); // Scaled Leg left
triangle(offsetX + 75 + vibrationOffsetX, offsetY + 100 + vibrationOffsetY, offsetX + 70 + vibrationOffsetX, offsetY + 130 + vibrationOffsetY, offsetX + 80 + vibrationOffsetX, offsetY + 130 + vibrationOffsetY); // Scaled Leg right
fill(col16, col17, col8);
triangle(offsetX + 42 + vibrationOffsetX, offsetY + 50 + vibrationOffsetY, offsetX + 17 + vibrationOffsetX, offsetY + 78 + vibrationOffsetY, offsetX + 25 + vibrationOffsetX, offsetY + 83 + vibrationOffsetY); // Scaled Arm left
triangle(offsetX + 92 + vibrationOffsetX, offsetY + 50 + vibrationOffsetY, offsetX + 117 + vibrationOffsetX, offsetY + 78 + vibrationOffsetY, offsetX + 108 + vibrationOffsetX, offsetY + 83 + vibrationOffsetY); // Scaled Arm right
offsetX += characterSpacing;
});
}
Key Changes:
Vibration Effect:
Conditional logic checks whether the current character is the last character and if the vibration duration has not yet passed.
Applies a small random offset to the coordinates using random(-3, 3), which gives a small jitter effect. This is done for both the x and y direction, simulating vibration.
Increased Vibration Duration: The duration is increased to 20 seconds.
This setup will cause the last character to vibrate independently of others for 20 seconds without requiring additional animations for the rest of the characters.
offsetX += characterSpacing;
});
}
Insteading of Highlighting the last character’s face to red , do nothing. The character making should start from row 1.
let sheetData = [];
let lastCharacterStartTime = null;
function setup() {
createCanvas(2000, 2000);
textSize(32);
fetchData(); // Fetch data once on setup
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 166; // 1/6th of the original spacing
let offsetX = 0, offsetY = 0;
let canvasWidth = 2000;
// Display row count
fill(0);
text("Row Count: " + sheetData.length, 10, 30);
sheetData.forEach((data, index) => {
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 133; // Move to the next row
}
// Calculate the colors from data
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 3, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation - scaled to 1/6th
fill(col1, col2, col3);
circle(offsetX + 67, offsetY + 33, 33); // Scaled Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Scaled Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Scaled Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Scaled Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Scaled Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Scaled Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Scaled Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Scaled Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Scaled Arm right
offsetX += characterSpacing;
});
}
Key Points:
Removed Special Highlighting: The highlight logic was removed, ensuring that the last character is drawn the same as others.
Consistent Character Generation: The loop iterates over each row to create a character, starting from row 1 to accommodate all data consistently.
This code now generates and displays characters based on each row of data in the sheet, without any special handling for the last character. Additionally, it starts rendering from the first row of data as intended.
});
}
in this code the row 0 data should be excluded. Highlight the changes made
let sheetData = [];
let lastCharacterStartTime = null;
function setup() {
createCanvas(2000, 2000);
textSize(16);
fetchData(); // Fetch data once on setup
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 100; // character spacing
let offsetX = 0, offsetY = 30; // character position
let canvasWidth = 2000;
// Display row count (excluding the header row)
fill(0);
text("Total Count: " + (sheetData.length - 1), 10, 30);
// Skip the first row by starting index at 1
for (let index = 1; index < sheetData.length; index++) {
let data = sheetData[index];
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 130; // Move to the next row
}
// Calculate the colors from data
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 4, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation
fill(col1, col2, col3);
circle(offsetX + 67, offsetY + 33, 33); // Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Arm right
offsetX += characterSpacing;
}
}
Key Changes Highlighted:
Skip the First Row: Changed the loop to start from index 1 (for (let index = 1; index < sheetData.length; index++)) to exclude the first row, assuming the first row is a header.
Preserve Processing Logic: All subsequent rows are processed in the same manner, starting from the second data row.
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 130; // Move to the next row
}
// Calculate the colors from data
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 4, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Character generation
fill(col1, col2, col3);
circle(offsetX + 67, offsetY + 33, 33); // Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Arm right
offsetX += characterSpacing;
}
}
How can I highlight the last row for sometime in this code?
let sheetData = [];
let lastCharacterStartTime = null;
const highlightDuration = 5000; // Highlight for 5 seconds
function setup() {
createCanvas(2000, 2000);
textSize(16);
fetchData(); // Fetch data once on setup
}
function fetchData() {
const url = 'https://docs.google.com/spreadsheets/d/1PROO0XgjFGxjJl1NLWkkUYuVxSVvBMLtkfs0rBz9RZg/gviz/tq?tqx=out:json';
fetch(url)
.then(response => response.text())
.then(text => {
const json = JSON.parse(text.substring(47, text.length - 2));
sheetData = parseJSON(json);
// Record the start time for the last character highlighting
lastCharacterStartTime = millis();
displayData();
})
.catch(error => console.error('Error fetching data:', error));
}
function parseJSON(json) {
let rows = json.table.rows;
return rows.map(row => row.c.map(cell => cell ? cell.v : ''));
}
function displayData() {
background(255); // Clear the canvas
const characterSpacing = 100; // character spacing
let offsetX = 0, offsetY = 30; // character position
let canvasWidth = 2000;
// Display row count (excluding the header row)
fill(0);
text("Total Count: " + (sheetData.length - 1), 10, 30);
for (let index = 1; index < sheetData.length; index++) {
let data = sheetData[index];
if (offsetX + characterSpacing > canvasWidth) {
offsetX = 0;
offsetY += 130; // Move to the next row
}
// Determine if this is the last row and if the highlight time is still active
const isLastRow = index === sheetData.length - 1;
const shouldHighlight = isLastRow && (millis() - lastCharacterStartTime < highlightDuration);
// Calculate the colors from data
let col1 = map(data[0], 1, 3, 0, 255);
let col2 = map(data[1], 1, 3, 0, 255);
let col3 = map(data[2], 1, 3, 0, 255);
let col4 = map(data[3], 1, 3, 0, 255);
let col5 = map(data[4], 1, 3, 0, 255);
let col6 = map(data[5], 1, 3, 0, 255);
let col7 = map(data[6], 1, 3, 0, 255);
let col8 = map(data[7], 1, 3, 0, 255);
let col9 = map(data[8], 1, 3, 0, 255);
let col10 = map(data[9], 1, 3, 0, 255);
let col11 = map(data[10], 1, 3, 0, 255);
let col12 = map(data[11], 1, 3, 0, 255);
let col13 = map(data[12], 1, 3, 0, 255);
let col14 = map(data[13], 1, 3, 0, 255);
let col15 = map(data[14], 1, 3, 0, 255);
let col16 = map(data[15], 1, 3, 0, 255);
let col17 = map(data[16], 1, 4, 0, 255);
let col18 = map(data[17], 1, 4, 0, 255);
// Use a highlight color if this is the last row being highlighted
if (shouldHighlight) {
fill(255, 0, 0); // Red color for highlighting
} else {
fill(col1, col2, col3);
}
// Character generation
circle(offsetX + 67, offsetY + 33, 33); // Face
fill(col4, col5, col6);
ellipse(offsetX + 62, offsetY + 29, 5, 8); // Eye left
ellipse(offsetX + 72, offsetY + 29, 5, 8); // Eye right
fill(col7, col8, col9);
rect(offsetX + 62, offsetY + 39, 10, 3); // Mouth
fill(col10, col11, col2);
square(offsetX + 42, offsetY + 50, 50); // Body
fill(col13, col14, col5);
triangle(offsetX + 58, offsetY + 100, offsetX + 53, offsetY + 130, offsetX + 63, offsetY + 130); // Leg left
triangle(offsetX + 75, offsetY + 100, offsetX + 70, offsetY + 130, offsetX + 80, offsetY + 130); // Leg right
fill(col16, col17, col8);
triangle(offsetX + 42, offsetY + 50, offsetX + 17, offsetY + 78, offsetX + 25, offsetY + 83); // Arm left
triangle(offsetX + 92, offsetY + 50, offsetX + 117, offsetY + 78, offsetX + 108, offsetY + 83); // Arm right
offsetX += characterSpacing;
}
// Redraw the data to apply the highlight effect again, if any
if (millis() - lastCharacterStartTime < highlightDuration) {
requestAnimationFrame(displayData);
}
}
Explanation of Changes:
Highlight Duration: Defined highlightDuration as 5000 milliseconds (5 seconds) to control how long the last row should be highlighted.
Highlight Logic:
Checks if it is the last row and if the time since lastCharacterStartTime is within the highlightDuration.
Applies a red (255, 0, 0) color fill to the face of the character if it should be highlighted.
Continuous Redraw: Repeatedly calls displayData using requestAnimationFrame while the highlight duration is in effect, to achieve the effect of updating the canvas for the specified time period.