This nifty graphics gem began with a contribution by Paul Villain to the MATLAB 2022 Mini Hack, presently happening on MATLAB Central.
Contents
modfun
Villain’s contribution is 102 mod 500 . My rewrite is modfun. Villain’s 102 and 500 grow to be the parameters m and n.
modfun(m,n) connects n factors, z(j), equally spaced across the complicated unit circle, by n+1 straight traces. The j-th line connects z(j+1) to z(mod(j*m,n)+1).
code
The fundamental code makes use of complicated arithmetic and is just eight traces lengthy. When the graphics is completed with line as an alternative of plot, it’s not obligatory to make use of maintain on.
operate modfun(m,n) init_fig z = exp(2i*pi*(0:n)/n); for j = 0:n zj = [z(j+1),z(mod(j*m,n)+1)]; line(actual(zj),imag(zj)) finish finish
The initialization makes line attainable.
operate init_fig axis([-1 1 -1 1]) axis sq. axis off finish
Animation
This animation of modfun(105,200) has one body for each 5 traces.
Gallery
A pattern.
Quiz
Match these calls to modfun to the plots within the Gallery.
modfun(88,179) modfun(89,220) modfun(99,200) modfun(101,200) modfun(111,200) modfun(113,188) modfun(126,188) modfun(126,200)
Revealed with MATLAB® R2022a