xxxxxxxxxx
44
let margin = 100; // Margin around the graph
let axisColor = 0; // Color of the axes
let labelColor = 0; // Color of the labels
function setup() {
createCanvas(400, 400);
noLoop();
}
function draw() {
background(220);
// Draw x and y axes
stroke(axisColor);
line(margin, height - margin, width - margin, height - margin); // x-axis
line(margin, margin, margin, height - margin); // y-axis
// Draw the graph
stroke(0); // Set the color to black
strokeWeight(2); // Set the thickness of the line
noFill();
beginShape();
// Iterate over the x-axis and plot the corresponding y values
for (let x = 0; x < width - 2 * margin; x++) {
let normalizedX = x / (width - 2 * margin); // Normalize x to range between 0 and 1
let y = (height - margin) - (normalizedX * normalizedX * (height - 2 * margin)); // Calculate y = x^2
//let y = (height - margin) - (normalizedX * (height - 2 * margin)); // Calculate y = x^2
vertex(x + margin, y); // Plot the point
}
endShape();
// Add labels to the axes
textAlign(RIGHT, TOP);
fill(labelColor);
noStroke();
text('# of correct characters', width - margin, height - margin + 5); // x-axis label
textAlign(RIGHT, CENTER);
text('fitness', margin - 5, margin); // y-axis label
// save('squared.png');
}