# [GIF] Moving bars illusion

Posted 4 years ago
9188 Views
|
5 Replies
|
14 Total Likes
|
 These bars are moving at a constant speed together, but it looks as if they move to the right in an alternating fashionÂ…Code: size={sizex,sizey}={600,400}; n=16; bars=sizex Subdivide[-1/2,1/2,2n-1]; width=N[bars[[2]]-bars[[1]]]; bars=Rectangle[{#1,-sizey/2},{#2,sizey/2}]&@@@Partition[bars,2]; cols={Lighter[Yellow,1/5],Darker[Blue,1/5]}; heights=N[sizey Subdivide[-1/2,1/2,Length[cols]+1][[2;;-2]]]; ClearAll[CreateScene] CreateScene[\[Alpha]_]:=Module[{recs}, recs=MapThread[{#1,Rectangle[{\[Alpha] sizex-2 width,#2-width/2},{\[Alpha] sizex+2 width,#2+width/2}]}&,{cols,heights}]; Rasterize[Graphics[{bars,recs},PlotRange->({{-1,1},{-1,1}}size/2),PlotRangePadding->0],"Image",RasterSize->size,ImageSize->size] ] Manipulate[CreateScene[a], {a, -0.6, 0.6}] enjoy!
5 Replies
Sort By:
Posted 4 years ago
 Nice. If these were cars on a US freeway, one of them would be frantically changing lanes back and forth in an attempt to always travel in the fastest lane, which would of course bring an end to the continuous progress.
Posted 4 years ago
Posted 4 years ago
 Maybe this explains my wife's exclamation that the other driver "came out of nowhere." Now that I think of it, I think the other driver was in a yellow car. Hmm...