Message Boards Message Boards

Circle Morphing into a triangle

In this youtube video Coding Challenge #81.1: Circle Morphing there is this guy solving a Javascript code challenge about morphing an equilateral triangle into a circle. Here is a one-line Wolfram expression written in a pure functional style that returns the solution using only built-in function.

{Interpolation[#2, InterpolationOrder -> 1], Most@Array[# &, 50, {#1, #2}] & @@ #1} &~MapThread~(
Partition[#, 2, 1] & /@ {First@Transpose@#, #} &@Table[{Cos@x, Sin@x}, {x, -Pi/6, 2 Pi - Pi/6, 2 Pi/3}]) // 
       Join @@ MapThread[Transpose@{#2, #1@#2} &, Transpose@#] & // 
      Transpose@{#, Most@N@Table[{Cos@x, Sin@x}, {x, -Pi/6, 2 Pi - Pi/6, 2 Pi/(Length@#)}]} & // 
     Animate[.5 (Sin@k First@# + (1 - Sin@k) Last@#) & /@ Append[#, First@#] // Graphics[{Thickness@.01, Line@#},
     PlotRange -> {{-.5, .5}, {-.6, .6}}] &, {k, 0, Pi/2}, AnimationDirection -> ForwardBackward, AnimationRate -> .5] &
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract

Be respectful. Review our Community Guidelines to understand your role and responsibilities. Community Terms of Use