xxxxxxxxxx
46
let wavefunction_data;
let t = 0; // Time variable for animation
function preload() {
// Load the JSON data file
wavefunction_data = loadJSON("fermion_wavefunction_data.json");
}
function setup() {
createCanvas(windowWidth, windowHeight);
background(255);
}
function draw() {
background(255); // Clear the canvas for each frame
// Extract the data from the JSON file
let x_values = wavefunction_data.x;
let psi_real = wavefunction_data.psi_real;
// Scaling factors for display
let xScale = width / (x_values[x_values.length - 1] - x_values[0]);
let yScale = height / 4; // Adjust the scale for the wavefunction amplitude
// Translate to the middle of the canvas
translate(width / 2, height / 2);
// Draw the animated wavefunction (real part)
stroke(0, 0, 255); // Blue for real part
noFill();
beginShape();
for (let i = 0; i < x_values.length; i++) {
let x = x_values[i] * xScale;
let y = psi_real[i] * yScale * cos(t + i * 0.1); // Animate using cosine function
vertex(x, -y);
}
endShape();
// Update the time variable for the next frame
t += 0.05;
}
function windowResized() {
resizeCanvas(windowWidth, windowHeight);
}