[GIF] Moving bars illusion

movingbars.gif

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!

13 Likes

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.

3 Likes

Hadn’t thought about that analogy! great!

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…

I am impressed. Perhaps a suggestion, put another screen below the first one without the black bars so we can see the rectangles move together at the same speed.

news-congrads-kkluyshnik-02-04-19.jpg – you have earned Featured Contributor Badge 2015-11-02_10-07-11.png

Your exceptional post has been selected for our editorial column Staff Picks http://wolfr.am/StaffPicks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you, keep it coming, and consider contributing to the The Notebook Archive!

1 Like

It would seem to me that bw bars produce an effect similar to a strobe light.

1 Like