Matrix rain

12 views
Skip to first unread message

S.E. Mitchell

unread,
Sep 1, 2023, 6:31:52 AM9/1/23
to TSEPro Support
Found this a few years ago on a Basic forum, and converted it to SAL.
It has an interesting visual effect.
Uses undocumented SAL features, so need to give it an extension of
".si" in order to compile it.
It opens an 80x23 window - kudo's to anyone who can fix it to work in
any size window.

integer proc foreg(integer n)
case n
when 0 return (color(black))
when 2 return (color(green))
when 10 return (color(bright green))
when 11 return (color(bright cyan))
endcase
return (0)
end

integer proc backg(integer n)
case n
when 0 return (color(black))
when 2 return (color(green))
endcase
return (0)
end

// the y in 1..23 is important - > 23 does not seem to work
proc d(integer f, integer b, integer x, integer y)
if y in 1..23
set(attr, foreg(f) + backg(b))
putcharxy(x, y, chr(33 + (x * y) mod 200))
endif
end

proc main()
constant N = 80
integer t[N]
integer x, y

popwinopen(1, 1, 80, 23, 0, "", 7)
SetCursorOff()
set(attr, 0)
clrscr()
for x = 1 to N
t[x] = -Random(0, 50)
endfor

while not keypressed()
for x = 1 to N
if t[x] > 28
t[x] = 0
endif
t[x] = t[x] + 1
y = t[x]
d( 0, 0, x, y - 6)
d( 2, 0, x, y - 5)
d( 2, 0, x, y - 4)
d(10, 0, x, y - 3)
d(10, 0, x, y - 2)
d(11, 0, x, y - 1)
d( 0, 2, x, y)
endfor
delay(1)
endwhile
SetCursorOn()
getkey()
popwinclose()
end

Fred H Olson

unread,
Sep 1, 2023, 8:59:06 AM9/1/23
to TSEPro Support
Interesting. Reminds me of a computer controlled device displayed
long ago at an event that impressed me. Maybe it was at a FORTH
meeting at UMN. It had a large array of red led's (about the only
color available at the time?) The top row of led's got brighter slowly
and when an led got to a certain brightness it "fell", that is led's
below it came on in sequence. The columns dripped in random sequence.
It was amazingly realistic lookimg.

Maybe rain matrix could be modified to have the top led "grow" as "." and
then "o" (maybe there is a better, longer getting bigger sequence?)
before dripping. The random sequence might be better simulated too.

Fred
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/semware/CA%2BgEvkY2zWPpQhN8NsD7EeLwUFP-vF%3D9_mD_x0c4kCoW1uWpDA%40mail.gmail.com.
>

--
Fred H. Olson Minneapolis,MN 55411 USA (near north Mpls)
Email: fholson at cohousing.org 612-588-9532
My Link Pg: http://fholson.cohousing.org

Carlo Hogeveen

unread,
Sep 1, 2023, 9:33:55 AM9/1/23
to sem...@googlegroups.com

Ok, as requested the version below works with all recent TSE variants for all screen sizes, though it limits its own breadth and width to 255 characters.
It does not need the special .si extension: a normal .s extension will work.
Apart from those two changes I kept its code as similar as possible, which means it is still pretty unreadable.

Carlo



integer N = 0
integer M = 0
integer O = 0

integer proc foreg(integer n)
case n
when 0 return (Color(Black))
when 2 return (Color(Green))
when 10 return (Color(Bright Green))
when 11 return (Color(Bright Cyan))
endcase
return (0)
end

integer proc backg(integer n)
case n
when 0 return (Color(Black))
when 2 return (Color(Green))
endcase
return (0)
end

proc d(integer f, integer b, integer x, integer y)
if (x in 1 .. N)
and (y in 1 .. M)
Set(Attr, foreg(f) + backg(b))
PutCharXY(x, y, Chr(33 + (x * y) mod 200))
endif
end

proc Main()
string t[255]
integer x, y

N = Min(Query(ScreenCols) , 255)
M = Min(Query(ScreenRows) , 255)
O = Min(Query(ScreenRows) + 6, 255)

PopWinOpen(1, 1, N, M, 0, "", 7)
SetCursorOff()
Set(Attr, 0)
ClrScr()
for x = 1 to N
t[x] = Chr(Random(1, M))
endfor

while not KeyPressed()
for x = 1 to N
if Asc(t[x]) >= O
t[x] = Chr(0)
endif
t[x] = Chr(Asc(t[x]) + 1)
y = Asc(t[x])
d( 0, 0, x, y - 6)
d( 2, 0, x, y - 5)
d( 2, 0, x, y - 4)
d(10, 0, x, y - 3)
d(10, 0, x, y - 2)
d(11, 0, x, y - 1)
d( 0, 2, x, y)
endfor
Delay(1)
endwhile
SetCursorOn()
GetKey()
PopWinClose()
PurgeMacro(CurrMacroFilename())
end




S.E. Mitchell

unread,
Sep 4, 2023, 6:28:45 PM9/4/23
to sem...@googlegroups.com
Really, really cool Carlo! Thanks for the help!
--
> --
>
> ---
> You received this message because you are subscribed to the Google Groups "SemWare TSE Pro text editor" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to semware+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/semware/000201d9dcd8%24f0d94dc0%24d28be940%24%40ecarlo.nl.
Reply all
Reply to author
Forward
0 new messages