Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Comments on Golf me a polygonal loader

Parent

Golf me a polygonal loader

+2
−0

CGCC Sandbox, Codidact Sandbox

Given three positive integers as input, animate an ascii-art polygonal loading symbol on the screen.

Intro

Using the first input $n$, Take one the following regular polygons:

                           * * *
                          *     *
                * * *    *       *
               *     *   *       *
  *    * * *  *       *  *       *
 * *   *   *   *     *    *     *
* * *  * * *    * * *      * * *

And draw it with the correct side length $l$.

Given load length $d$ lesser than it's perimeter, create it's loading animation as follows:

  • Start at any one of the topmost corners, and draw the bounding line till it's length is $d$.
  • Then, shift the position by 1 clockwise and do the next step.

For example, $n=3,l=3,d=4$ would result in the following steps:

  *                        *       *       *
   *  →    *  →   *    →  *    →  * *  →  * *  → . . .
  * *   * * *    * * *   * *     *           *

Further details(important):

  • You are guaranteed that $n∊(3,4,6,8)$
  • You are guaranteed that $l≥3.$
  • You are guaranteed that $d<l×n.$
  • There must be a delay of at least 0.1 s between each step. You can have a delay of up to 10 seconds.
  • Your language is allowed to output a list of steps infinitely if and only if it cannot clear the screen or do something similar.
  • If so, there must be at least 2 newlines between each step.
  • This is not graphical-output.

Scoring

This is code-golf. Shortest answer in each language wins.

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

Post
+3
−0

JavaScript (Browser), 670 bytes

for(_="=1,w=):=0,w(=f(||(.join`w?q-w?q=-w(a,b=>A(L*5,a),g.innerText=N=L=D=T,I=,c,d)a-d?I,b(d,cd+1c,A=)I(a,(x,y)[...y,b(x)],[](U=_(Kf=({value:a})a==[a|]+[]&&aKQnFlZdOtQ-N|F-L|Z-D|O-T&&(B=Q,e=F,H=Z,V=O,K&=(V>0&V<61&[3,4,6,8].includes(B)&e>1&e<101&H>0&H<=B*(e-1)K&&(N=Q,L=F,D=Z,T=O,X=N-4&&L,Y,WE=N==3,M=1)R=requestAnimationFrame,N?(s=' ')x=X,y=Y,q=W,E,m=M,I(D,i(s[y][x]='*',m++-Lm=2,N<4?w<0?1:w?(q=-1q-1N<6?w?(q,qN<8?w::q:q?q+ww:q:qx+=q*(?2:1y+=w,iX=x,Y=y,W=q,E=w,M=m))s.map(aa`)\\n`(''T-60?setTimeout(_R(U1e3/T-16R(U)))()";G=/[-]/.exec(_);)with(_.split(G))_=join(shift());eval(_)

Try it online!

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.

1 comment thread

General comments (1 comment)
General comments
Razetime‭ wrote almost 4 years ago

Very clean answer. I love it!