The first tweetcart for the Tweetcart Token Club (TTC)!
Click/Tap to generate a new tree!
Source Code:
pal(0,12)cls(12)m=128r=rnd
l=line::_::
for i=1,99do
x=r(m)y=r(m)
if(r()>.9)?"░",x-r(9),y+r(9)+2,r({8,9})
?"▒",x,y,0
end
for i=1,25do
f=-r(2)x=110y=m
z=x+i
w=y-r(9)-40l(z,y,z,w,4)
for i=1,25do
z+=r(9)*f*i/9w-=r(9)l(z,w,4)c=r({8,9})?"░",z,w,c
end
end
if(t()<1)goto _
Explanation:
pal(0,12) -- set the bg color to sky blue
cls(12) -- clear the screen (fill with blue)
m=128 -- I use this number a lot, store it to save characters
r=rnd -- likewise but for this function
l=line -- and again
::_:: -- start of the draw loop
-- dithering to avoid screen clutter
for i=1,99do -- 99 loops
x=r(m)y=r(m) -- random x and y position
-- 10% of the time, print some falling leaves
if(r()>.9)?"░",x-r(9),y+r(9)+2,r({8,9})
?"▒",x,y,0 -- erase parts of the screen
end
-- trunk of the tree
for i=1,25do -- 25 vertical lines
f=-r(2) -- need a consistent scaling factor
x=110y=m -- line starts at bottom of screen, on the right side
z=x+i -- move to the right to draw the trunk
w=y-r(9)-40 -- get a random length factor for end point
l(z,y,z,w,4) -- draw trunk
for i=1,25do -- draw branches (25 for each trunk line)
z+=r(9)*f*i/9 -- get new branch x endpoint
w-=r(9) -- get new branch y endpoint
l(z,w,4) -- draw branch
c=r({8,9}) -- random leaf color 8 or 9
?"░",z,w,c -- draw leaves at the branch endpoints
end
end
if(t()<1)goto _ -- only loop in the first second