A Little Challenge: Spin the Circle - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: A Little Challenge: Spin the Circle (/showthread.php?tid=3021) |
RE: A Little Challenge: Spin the Circle - SMcNeill - 09-12-2024 Code: (Select All)
Cleaned it up a bit more and removed some more unnecessary variables and such. If there's anything that seems obtuse in this, just ask and I'll be more than happy to explain the idea behind my changes. I'm really pretty happy with this little brainstorm of an idea: Code: (Select All) For i = start To fini Step Sgn(fini - start) Now all one needs do is swap start and fini, and that loop will count up by 1 or down by 1 automagically! How's that for a neat little trick of logic? RE: A Little Challenge: Spin the Circle - Dav - 09-12-2024 Woah, that's pretty tight coding, Steve. I ain't even gonna try to shorten that. - Dav RE: A Little Challenge: Spin the Circle - SMcNeill - 09-12-2024 (09-12-2024, 11:44 PM)Dav Wrote: Woah, that's pretty tight coding, Steve. I ain't even gonna try to shorten that. Code: (Select All)
Think that's about as compact as I can get it. This version even makes the ESC sequence more responsive by keeping it inside the innermost loop. At this point, all I can see is just merging lines with colons to try and pretend like we're getting them shorter. 13 lines isn't so bad for something like this, is it? RE: A Little Challenge: Spin the Circle - NakedApe - 09-13-2024 Sure, @SMcNeill, would you explain this dark magic? For i = start To fini Step Sgn(fini - start) And I like this, Steve: If _KeyDown(27) Then System Else _Limit 60 That's getting your _LIMIT in there for free! Tricky. RE: A Little Challenge: Spin the Circle - SMcNeill - 09-13-2024 For i = start To fini Step Sgn(fini - start) Start = 1: Fini = 90 SGN(90 - 1) = +1 'It's a positive number, so what we end up with is: FOR i = 1 TO 90 STEP 1 Now, swap start and fini Start = 90: Fini = 1 SGN (1 -90) = SGN (-89) = -1 it's a negative number, so we end up with: FOR I = 90 TO 1 STEP -1 See the logic here? |