Spawning regular polygons​
​by Sander Huisman
Let’s make a function that for a given time, outputs a regular polygon at position p, with n sides, angles an angles θ. at time t, with color clr.
The opacity fades after 1 second. The radius is linear with time, and the object rotates with time:
In[]:=
ClearAll[ngon]​​ngon[p_,n_,θ_,t_,clr_]:=Module[{r,op},​​If[t<0,Return[{}]];​​If[t>1,Return[{}]];​​r=t;​​op=Max[Erfc[3(t-1)]-1,0];​​{Directive[{Opacity[op],clr}],RegularPolygon[p,{r,θ-3t},n]}​​]​​​​m=6;(*numberofspawners*)​​n=5;(*spawningn-sidedregularpolygons*)​​angles=N@Most[Subdivide[0,2Pi,m]];​​​​tmax=5;​​spawnrate=8;(*spawnnewpolygonsatthisfrequency*)​​δt=1/spawnrate;​​ts=Range[0,tmax,δt];​​ngons=Table[​​t=ts[[ti]];​​offset=(*0.2Sin[0.3×2Pit]+*)0.6t;(*rotatespawnlocations*)​​θs=Table[offset+a,{a,angles}];​​MapThread[With[{tt=N@t,p=AngleVector[{0.55+0.45Sin[0.5×2Pit],#}],col=ColorData[60][ti]},Function[{τ},ngon[p,n,#,τ-tt,col]]]&,{θs}](*modulateradius,andchoosecolorsforeachtriangle*)​​,​​{ti,Length[ts]}​​];
Create the images in a parallelized manner:
In[]:=
imgs=ParallelTable[Rasterize[Graphics[Map[#[t]&,ngons,{2}],PlotRange2,BackgroundBlack,ImageSize400{1,1}],RasterSize400{1,1}],{t,Range[0,tmax+1.5,1/40]}];
Export the images as a gif:
In[]:=
SetDirectory[NotebookDirectory[]];​​Export["Spawners.gif",imgs,"DisplayDurations"->1/30]
Out[]=
Spawners.gif