The script draws the two squares in thick lines, the cuts in thin lines and the rearrangement in dashed lines.
A triple [a, b, c] where a, b and c are positive integers with a2 + b2 = c2 is called a Pythagorean triple for obvious reasons. If, in addition, a and b are relatively prime, [a, b, c] is called a fundamental Pythagorean triple (FPT). Thus, among the Pythagorean triples [8, 6, 10], [15, 8, 17] and [50, 120, 130], only [15, 8, 17] is an FPT. All [a, b, c] forming FPTs are generated by the parametric equations
a = 2mnwhere m and n are any relatively prime positive integers, not both odd, and m > n. A proper subset of FPTs can be obtained by substituting m = n + 1
b = m2 - n2
c = m2 + n2
a = 2n2 + 2nwhere n is any positive integer (the substitution took care of all constraints on m and n).
b = 2n + 1
c = 2n2 + 2n + 1
The Java applet below shows animated 4-piece solutions for squares that have sides in the ratio a/b for some a and b in this subset of FPTs.
Though the applet is written to work for all values of n, the available screen real-estate puts an upper bound on what can be displayed. The largest usable value of n is computed to be the one that will make each unit cell two pixels wide (with just one colored pixel between every pair of adjacent white grid lines).
See Elementary Number Theory by Underwood Dudley for the derivation of the first set of parametric equations (in terms of m and n) given above for FPTs.