1 of 4

Animation by GNUPLOT

Initiative for an Add-On Course

​

Somenath Jalal

Department of Physics

Netaji Mahavidyalaya

2 of 4

Plot sin wave

# Set up GIF output

set term gif animate optimize delay 10 size 600,400

set output "sinewave.gif"

​

# Axis and plot settings

set xrange [0:2*pi]

set yrange [-1.5:1.5]

set size ratio 0.5

set samples 500

unset key

set title "Sine Wave Animation"

​

# Loop over frames (simulate time evolution)

do for [t=0:100] {

phase = t*0.10

## plot sin(x - phase) lw 4 lc rgb "blue"

plot cos(x + phase) lw 4 lc rgb "red"

}

​

set output # Finalize GIF file

​

3 of 4

Sin wave with a red BALL

# Animated GIF of sine wave with a moving ball on the crest

​

set term gif animate optimize delay 10 size 600,400

set output "sinewave_ball.gif"

​

set xrange [0:2*pi]

set yrange [-1.5:1.5]

set samples 500

set size ratio 0.5

unset key

set title "Sine Wave with Ball on Crest"

​

# Constants

omega = 1.0 # angular frequency

ball_radius = 0.2

​

do for [t=0:100] {

phase = t*0.1

xball = pi/2 + phase # peak of sine(x - phase) is at x = pi/2 + phase

yball = sin(xball - phase) # = sin(pi/2) = 1

​

plot sin(x - phase) lw 4 lc rgb "blue", \

'+' using (xball):(yball) with points pt 7 ps 1.5 lc rgb "red"

}

​

set output

​

4 of 4

A red ball moving on Sine wave

# Create a rolling ball on a fixed sine wave

​

set term gif animate optimize delay 10 size 600,400

set output "rolling_ball.gif"

​

set xrange [0:2*pi]

set yrange [-1.5:1.5]

set samples 500

set size ratio 0.5

unset key

set title "Ball Rolling on a Fixed Sine Wave"

​

do for [t=0:100] {

xball = t * 2*pi/100 # move ball smoothly from x=0 to x=2π

yball = sin(xball) # y-position on sine wave

​

plot sin(x) lw 2 lc rgb "blue", \

'+' using (xball):(yball) with points pt 7 ps 1.5 lc rgb "red"

}

​

set output

​