Skip to content

Commit

Permalink
Add canvas resizing functionality for responsive design
Browse files Browse the repository at this point in the history
- Implement windowResized() function to handle window size changes
- Adjust canvas size dynamically to fill the browser window
- Ensure proper display of simulation elements after resizing
  • Loading branch information
parsaa74 committed Oct 11, 2024
1 parent 58de9eb commit 21e7e60
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ const socialDistancingRadius = 50;
const interactionRadius = 30;

function setup() {
createCanvas(800, 600);
// Create a responsive canvas that fills the browser window
let canvas = createCanvas(windowWidth, windowHeight);
canvas.style('display', 'block'); // Removes the scrollbars
textAlign(CENTER, CENTER);
}

Expand Down Expand Up @@ -73,4 +75,9 @@ function displayLonelinessMetric() {
textSize(16);
text(`Loneliness Score: ${lonelinessScore.toFixed(2)}`, width / 2, height - 40);
text(`People: ${people.length}`, width / 2, height - 20);
}

// Add this function to handle window resizing
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}

0 comments on commit 21e7e60

Please sign in to comment.