Neat one-liners

Chat about anything CX16 related that doesn't fit elsewhere
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Neat one-liners

Post by grml »


POKE34,203:POKE35,96:FORI=0TO128:POKE$9F2A,I:POKE$9F2B,I:SYS34:NEXT


Works best right after reset while the X16 logo is still visible.

This part:

POKE34,203:POKE35,96:SYS34


does wait for vblank irq, for the rare case when you need it in BASIC. The address is arbitrary, it will work anywhere in RAM.

Add your own interesting one-liners or short BASIC programs below if you must. Inb4 the inevitable "maze" generator

grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: Neat one-liners

Post by grml »

Sierpiński triangle:

Code: Select all

CLS:FORY=0TO59:FORX=0TO79:VPOKE1,$B000+Y*256+X*2,78-((XANDY)>0):NEXT:NEXT
It looks better if you squint a little :lol:
x16sierpinsky.png
x16sierpinsky.png (2.85 KiB) Viewed 5328 times
And damn, BASIC is still slow as hell even at 8 MHz.
User avatar
desertfish
Posts: 1097
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Neat one-liners

Post by desertfish »

I love the sierpinsky oneliner!
User avatar
Jestin
Posts: 85
Joined: Sat Jun 27, 2020 10:14 pm
Contact:

Re: Neat one-liners

Post by Jestin »

I tried putting these together, and they make a great two-liner! Zooming Seirpinski!
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: Neat one-liners

Post by grml »

Code: Select all

COLOR13,0:CLS:FORT=0TO9^9:?CHR$(164+2*RND(0)+INT(2*RND(0))*41);:NEXT
This one is interesting. If you watch it go for a minute, you can see the pattern go through a bunch of distinctive phases while the RNG "warms up", until it finally seems to generate more uniformly distributed numbers.

First it's lots of diagonals and vertical lines, then lots of horizontal lines for a while
phase1_2.png
phase1_2.png (31.55 KiB) Viewed 5237 times
then mostly diagonals but clearly biased towards one direction,
phase3.png
phase3.png (34.28 KiB) Viewed 5237 times
and only then the actual intended pattern emerges after about ~4 screens.
phase4.png
phase4.png (35.81 KiB) Viewed 5237 times
User avatar
desertfish
Posts: 1097
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Neat one-liners

Post by desertfish »

That is unexpected and slightly worrying behavior of the rng...
When running the same oneliner on the C64 (in vice) there is no such 'phasing', it seems uniform right from the start....

(the same when running an equivalent program written in prog8)

Yeah, you should probably be using RND(1) instead of RND(0) in the BASIC oneliner, that seems to fix the lack of uniformedness on the X16.


Screenshot_20230121_113022.jpg
Screenshot_20230121_113022.jpg (150.34 KiB) Viewed 5232 times
User avatar
desertfish
Posts: 1097
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Neat one-liners

Post by desertfish »

Is it allowed to cheat a tiny little bit by setting up a variable first?

If so, this is my entry:

first set up the variable:
M$=CHR$(145)+CHR$(17)+CHR$(157)+CHR$(29)

and then the one liner itself:
CLS:LOc30,40:FoI=0TO9^9:COlRn(1)*16:?Ch(209)Ch(157)Mi(M$,1+Rn(1)*4,1);:Ne


(yes, it uses token abbreviatons to fit it under 80 characters. They look a bit weird in ascii due to the case flip, if you paste the line in the emulator it does work correctly)

EDIT: it can be done on 1 line and so it adheres to the rules again, but it requires you to embed the actual characters into the line instead of using ascii-copyable chr$ notation:
Screenshot_20230121_154148.png
Screenshot_20230121_154148.png (18.79 KiB) Viewed 5202 times
1 = shift-Q , a ball
2 = cursor left
3 = cursor up
4 = cursor down
5 = cursor left
6 = cursor right

Screenshot_20230121_125326.png
Screenshot_20230121_125326.png (186.2 KiB) Viewed 5219 times
Last edited by desertfish on Sat Jan 21, 2023 2:44 pm, edited 2 times in total.
grml
Posts: 60
Joined: Sat Aug 13, 2022 8:31 pm

Re: Neat one-liners

Post by grml »

desertfish wrote: Sat Jan 21, 2023 10:32 am Yeah, you should probably be using RND(1) instead of RND(0)
Yes, that's it. At least I got this beautiful oneliner artwork out of my blunder:

Code: Select all

SCREEN128:S=16:FORY=0TO239:FORX=0TO319:PSETX,Y,S+S*RND(0):NEXT:NEXT
rnd0.png
rnd0.png (55.26 KiB) Viewed 5215 times
desertfish wrote: Sat Jan 21, 2023 11:54 am Is it allowed to cheat a tiny little bit by setting up a variable first?
Comparing twoliners against oneliners seems a bit unfair to me. :) It's too bad you have to use CHR$. It would fit on one line if you could copy those chars verbatim, and remove the CLS.

Thanks for showing me how to copy abbreviated tokens.

Code: Select all

SCr128:FORY=0TO239:FORX=0TO319:PsX,Y,136-119*SIN((X+2*Y)/(X+Y+59))+Rn(1):Ne:Ne
This one I call STRIPES OF PATIENCE. A picture would only deprive you of a quintessential and beautiful real-time art experience.
User avatar
desertfish
Posts: 1097
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

Re: Neat one-liners

Post by desertfish »

I made it into a one liner but you can no longer copy paste it from the forum because of the embedded control characters that you have to type now ;)
BruceRMcF
Posts: 224
Joined: Sat Jan 07, 2023 10:33 pm

Re: Neat one-liners

Post by BruceRMcF »

desertfish wrote: Sat Jan 21, 2023 10:32 am ... Yeah, you should probably be using RND(1) instead of RND(0) in the BASIC oneliner, that seems to fix the lack of uniformedness on the X16.
Does anything interesting happen with RND(T) in one of the RND() functions ... that is, using a different seed each time through the loop?
Post Reply