QBIC,93 91 84字节
:{X=space$(a)+@--O--`┘a=a-sgn(a-5)~t>-1|?X[t|?]t=t-1?@____|`+@ `+_fB|\_xB+A+_fB
通过替换X $的声明删除一些字节;优化了FOR循环,该循环打印地面上的距离。以下说明是针对旧版本的,但其基本原理相同。
为了测试(和美观),我有一个略有不同的版本,为103字节:
:{_z.5|_CX=Y[a|X=X+@ `]X=X+@--O--`
a=a-sgn(a-5)
~u>0|?X';`[u|?]u=u-1?@____|`+@ `+_fC|\_xC+_tB+_fC
这些在功能上是相同的。第二个功能是在画面之间清除屏幕,并且在画面之间暂停0.5秒。
样品输出
请注意,我在框架之间添加了两个换行符。上面最常用的代码不会在框架之间添加空行,较凉的代码可以清除屏幕。
Command line: 10
--O--
____| |____
--O--
____| |____
--O--
____| |____
--O--
____| |____
--O--
____| |____
____|--O--|____
说明
因为我感觉到这涉及到我非常喜欢QBIC的许多事情,并且可以很好地了解QBIC的某些功能是如何工作的,所以我在解释上有些过分了。请注意,QBIC的核心是Codegolf的QBasic解释器。QBIC代码进入-QBasic代码出现(并随后执行)。
:{ get the starting offset (called 'a') from the command line, and start a DO-loop
---- cool code only ----
_z.5|_C At the start of a DO-loop, pause for half a second and clear the screen
---- resume golf-mode ----
---- #1 - The tip of the left wing is anywhere between 0 and 10 positions to the right.
---- Create the plane with the spacing in X$
X=Y Clear X$
[a| For each point in the current offset
X=X+@ `] Add a space to X$
- Every capital letter in QBIC references that letter+$, a variable of type String
- @ and ` start and end a string literal, in this case a literal space.
- ] ends one language construct (an IF, DO or FOR). Here, it's NEXT
X=X+@--O--` Create the actual plane
- @ and `once again create a string literal. Every literal that is created in this
way is assigned its own capital letter. This is our second literal, so the body of
our plane is stored in B$ (A$ contains the space, remember?)
---- #2 Adjust the offset for the next iteration
a=a-sgn(a-5) The clever bit: We have an offset X in the range 0 - 10, and 5 attempts to
get this to be == 5. X - 5 is either positive (X = 6 - 10), negative
(X = 0 - 4) or 0 (X=5). sgn() returns the sign of that subtraction
as a 1, -1 or 0 resp. We then sub the sign from 'a', moving it closer to 5.
---- #3 Draw the plane, the empty airspace and the landing strip
~u>0| Are we there yet?
- ~ is the IF statement in QBIC
- It processes everything until the | as one true/false expression
- All the lower-case letters are (or better, could be) references to numeric
variables. Since QBasic does not need to post-fix those, they double as 'natural'
language: ignored by QBIC and passed as literal code to the QBasic beneath.
- The lower-case letters q-z are kinda special: at the start of QBIC, these
are set to 1 - 10. We haven't modified 'u' yet, so in the first DO-loop, u=5
?X';` If we're still air-borne, print X$ (our plane, incl. spacers)
- ? denotes PRINT, as it does in QBasic.
- ' is a code literal in QBIC: everything until the ` is not parsed, but
passed on to QBasic.
- In this case, we want a literal ; to appear after PRINT X$. This suppresses
QBasic's normal line-break after PRINT. This needs to be a code literal
because it is the command to read a String var from the command Line in QBIC.
[u|?] FOR EACH meter above the ground, print a newline
u=u-1 Descent 1 meter
?@____|` Print the LHS of the landing strip
+@ ` plus 5 spaces
+_fC| plus the LHS reversed.
\ ELSE - touchdown!
_x Terminate the program (effectively escape the infinite DO-loop)
- the _x command has an interesting property: ULX, or Upper/Lowercase Extensibility.
Writing this command with an uppercase _X does something similar, yet different.
The _x command terminates, and prints everything found between _x and | before
quitting. Uppercase _X does not look for |, but only prints something if it is
followed by a character in the ranges a-z and A-Z - it prints the contents of
that variable.
C+B+_fC But before we quit, print C$ (the LHS of the landing strip) and the plane,
and the LHS flipped.
---- #4 QBIC has left the building
- Did I say _x looks for a | ? Well, that gets added implicitly by QBIC at the end of
the program, or when one ( ']' ) or all ( '}' ) opened language constructs are closed.
- Also, all still opened language constructs are automatically closed at EOF.
- Had we stored anything in Z$, that would also be printed at this time.