// [c_pendu] Ewing's pendulum simulation with spring and graph // Leapfrog integration + frame export // Clear only the pendulum area and keep the graph trajectory // Each frame can be saved and converted into a video // [c_pendu]**************************************************[Ver 0.00] // Caluclation of period for the EWING's pendulam longer period // [leapfrog method] // prog.by Y.Okamoto 1991.03/05-03/07 // ********************************************************************** float PI_ = 3.14159; float RAD = PI_/180.0; // Screen coordinates float X00 = 200, Y00 = 350; // hinge point float DT = 0.02; ... float L0 = 0.07; // init spring length float GAMMA = 0*RAD; float THETA = 3*RAD; float PHAI = 0*RAD; float I_; float BETA; float B; // Variables for calculation float X, Y, L, CSA, SNA, P, AC; float V = 0, T = 0; float XX, YY, WXX, WYY, XXP, YYP; float XX2, YY2, WX2, WY2; // Frame saving settings int frameCountMax = 600; // Maximum number of frames to save (e.g., 500 → about 10 seconds) boolean saveFrames = true; // Enable frame saving when true void setup() { size(800, 600); // Initial coordinates X = L0*cos(PHAI); Y = L0*sin(PHAI); } void draw() { // Equations of motion ... // --- Clear the pendulum drawing area with black --- noStroke(); fill(0); rect(0, 0, width, height - 160); // Clear only the upper part (keep the lower graph) // --- Leapfrog integration --- ... // Recalculation ... // Coordinate transformation ... // --- Pendulum drawing --- stroke(255); line(XX, YY, XXP, YYP); // Spring line(WXX, WYY, X00, Y00); // Boom ellipse(WXX, WYY, RW, RW); // Bob // --- Time display --- ... // --- Draw lower graph (keep trajectory) --- float gy0 = height - 100; // Bottom of graph float gxScale = 20; // Horizontal axis scale float gyScale = 800; // Vertical axis scale stroke(0, 255, 0); point(gx0 + T*gxScale, gy0 - (WY - 0)*gyScale); // Plot of bob height // --- Frame saving --- if (saveFrames && frameCount <= frameCountMax) { if (frameCount % 1 == 0) { // Save every 4 frames saveFrame("frames/frame-####.png"); } if (frameCount == frameCountMax) { println("Frame saving completed (" + frameCountMax + "枚)"); noLoop(); // Automatic stop } } }