xxxxxxxxxx
102
//Batool Al Tameemi, Intro To Im
//Assignment 5: Datasets and visualization
let table; // Declare a variable to hold the CSV data
let artistData = []; // Initialize an array to store artist data
function preload() {
// Load your CSV file
table = loadTable('artists.csv', 'csv', 'header');
}
function setup() {
createCanvas(800, 600);
noLoop();
// Define the box parameters
let boxX = 50;
let boxY = 50;
let boxWidth = width - 2 * boxX;
let boxHeight = height - 2 * boxY;
// Extract artist data from the CSV
for (let i = 0; i < table.getRowCount(); i++) {
let row = table.getRow(i);
let artistName = row.get('Name');
let nationality = row.get('Nationality');
let status = row.get('Status');
if (artistName && nationality) {
artistData.push({ name: artistName, nationality, status, x: 0, y: 0 });
}
}
// Draw a box
noFill();
stroke(0);
rect(boxX, boxY, boxWidth, boxHeight);
// Display artist names with the specified conditions
textSize(12);
textAlign(LEFT, TOP);
for (let artist of artistData) {
let x = random(boxX, boxX + boxWidth - textWidth(artist.name));
let y = random(boxY, boxY + boxHeight - textAscent());
// Check for overlap with existing text
let overlapping = false;
for (let existing of artistData) {
if (artist !== existing) {
let d = dist(x, y, existing.x, existing.y);
if (d < 20) {
overlapping = true;
break;
}
}
}
// Set text color based on conditions
if (artist.nationality !== 'American') {
fill(192, 192, 192); // Silver
} else if (artist.status === 'Dead') {
fill(255, 215, 0); // Gold
} else {
fill(0); // Default text color
}
// If not overlapping, display the text
if (!overlapping) {
text(artist.name, x, y);
artist.x = x;
artist.y = y;
}
}
}
function draw() {
textSize(30);
textAlign(CENTER, CENTER);
fill(random(0,255)); // Set text color to black
// Set the built-in font
textFont("Georgia");
stroke(color(255));
// Calculate the center of the canvas
let centerX = width / 2;
let centerY = height / 2;
// Use frameCount to create a continuously changing color
let hue = (frameCount * 2) % 360; // Adjust the factor for color speed
let textColor = color(0);
fill(textColor);
// Display the text at the center of the screen
text("Postcards from ", centerX, centerY - 90);
textSize(160);
text("MoMA", centerX, centerY);
}