Message Boards Message Boards

5
|
11622 Views
|
4 Replies
|
8 Total Likes
View groups...
Share
Share this post:

Updating a One-Liner Competition Winner

Posted 9 years ago

The 2015 One-Liner Competition has some awesome entries. The third-place award is a particularly cool one, and was posted with a challenge from the judges:

Third Place

I decided to try my hand at it. I'm still well over 128 characters, but I was able to make a non-stop animated version:

r := RandomReal[1, {7, 2}];
p = r;
p2 = r;
c = 0;
data[t_] := p + t (p2 - p);
Dynamic[
 c = c + .01;
 If[c == 1, p = p2; p2 = r; data[t_] := p + t (p2 - p);];
 c = FractionalPart[c];
 Graphics[{Hue@(data[c][[1]]), 
   BSplineCurve[data[c], SplineClosed -> 2 > 1]}, 
  PlotRange -> {{0, 1}, {0, 1}}]]

And it works! I'm sure it can be done better, but I had fun anyway.

Result

POSTED BY: Evan Ot
4 Replies

Just an idea, not sure how to make it, - I think this needs memory. Basically if we show a sequence of a few loops ( trailing ) the the visual will be much more striking. I think also after awhile this gets stuck in a short cycle of repetitive behavior. It became so dense, hard to understand. Could someone tell me - is it really just a random vector of 2D points slightly incremented by another random vector?

POSTED BY: Sam Carrettie
Posted 9 years ago

I was never the golfing sort with respect to coding, but maybe y'all might pick up something of use:

r := RandomReal[{-1, 1}, {7, 2}]; p = q = r; c = 0;
Dynamic[If[(c += .01) == 1, {p, q} = {q, r}]; c -= ?c?; 
        Graphics[{Hue[#?1,1?], BSplineCurve[#, SplineClosed -> True]} &[{1 - c, c}.{p, q}], PlotRange -> 1]]
POSTED BY: J. M.

It gets down to 164 characters if you are willing to sacrifice the fixed size of the plot and have it dynamically resizing. I made a couple of other optimisations: for example, you don't need to redefine data in the If block.

r := RandomReal[1, {7, 2}]; p = p2 = r; c = 0; d := 
 p + # (p2 - p) &; Dynamic[c += .01;
 If[c == 1, p = p2; p2 = r]; c = FractionalPart[c]; 
 Graphics[{Hue@d[c][[1]], BSplineCurve[d[c], SplineClosed -> 2 > 1]}]]
POSTED BY: Patrick Stevens

And it can be trimmed just a bit more:

r:=RandomReal[1,{7,2}];p=p2=r;c=0;d:=p+# (p2-p)&;Dynamic[If[(c+=.01)==1,p=p2;p2=r];Graphics[{Hue@d[c=FractionalPart@c][[1]],BSplineCurve[d@c,SplineClosed->2>1]}]]

by making constructs like (c+=.01)==1 and using @ and the [[ and ]] can be typed as 1 character...

POSTED BY: Sander Huisman
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