xxxxxxxxxx
let headCenterX, headCenterY;
let headWidth, headHeight;
let shapes = []; // Array to store geometric shapes
let ralewayFont; // Declare a variable to store the Raleway font
function preload() {
// Load the Raleway font
ralewayFont = loadFont ('Raleway-Bold.ttf')
}
function setup() {
createCanvas(800, 1200);
background(255, 0, 0); // Red background
// Head silhouette parameters
headCenterX = width / 2;
headCenterY = height / 2;
headWidth = 500;
headHeight = 700;
// Create and store random shapes
for (let i = 0; i < 500; i++) {
shapes.push(createRandomShape(true)); // Shapes inside the head (white shapes)
}
for (let i = 0; i < 300; i++) {
shapes.push(createRandomShape(false)); // Shapes outside the head (black shapes)
}
drawShapes(); // Initial drawing
// Text on the poster
addText();
}
function createRandomShape(inside) {
let shapeSize = random(10, 50);
let x = random(headCenterX - headWidth / 2, headCenterX + headWidth / 2);
let y = random(headCenterY - headHeight / 2, headCenterY + headHeight / 2);
// Check if the point is inside or outside the head using the ellipse equation
let ellipseCondition =
sq((x - headCenterX) / (headWidth / 2)) +
sq((y - headCenterY) / (headHeight / 2));
if ((inside && ellipseCondition <= 1) || (!inside && ellipseCondition > 1)) {
return {
x: x,
y: y,
size: shapeSize,
type: random() < 0.5 ? "circle" : "square",
color: inside ? 255 : 0, // White inside the head, black outside
};
} else {
return createRandomShape(inside); // Call again if the shape is not in the correct position
}
}
function drawShapes() {
noStroke(); // Disable stroke for shapes
for (let shape of shapes) {
fill(shape.color);
if (shape.type === "circle") {
ellipse(shape.x, shape.y, shape.size);
} else {
rect(shape.x - shape.size / 2, shape.y - shape.size / 2, shape.size, shape.size);
}
}
}
// Function to add text
function addText() {
fill(0); // Black text
textAlign(CENTER, CENTER);
// Set the font to Raleway
textFont(ralewayFont);
// Main title
textSize(32);
text("The Scientific Analysis", width / 2, 50);
text("of Personality", width / 2, 90);
// Author name
textSize(28);
text("Raymond B. Cattell", width / 2, 150);
// Subtitle
textSize(16);
text(
"A readable and comprehensive introduction by an eminent authority to recent\nresearch on personality structure and individual differences",
width / 2,
200
);
}
// Function that runs when a key is pressed
function keyPressed() {
if (key === "r" || key === "R") {
// Randomly move the shapes
for (let shape of shapes) {
shape.x += random(-20, 20); // Random movement on the X axis
shape.y += random(-20, 20); // Random movement on the Y axis
}
background(255, 0, 0); // Redraw background
drawShapes(); // Redraw the shapes
addText(); // Redraw the text
}
}