1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
############################################################################
#
# File: ranstars.icn
#
# Subject: Program to display star field
#
# Author: Ralph E. Griswold
#
# Date: March 2, 1996
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# This program display a random field of "stars" on an ANSI terminal.
# It displays stars at randomly chosen positions on the screen until
# the specified maximum number is reached. It then extinguishes existing
# stars and creates new ones for the specified steady-state time, after
# which the stars are extinguished, one by one.
#
# The programming technique is worth noting. It is originally due to
# Steve Wampler.
#
# The options are:
#
# -m n maximum number of stars, default 10.
#
# -t n length of steady-state time before stars are extinguished,
# default 50.
#
# -s c the character to be used for "stars", default *. If
# more than one character is given, only the first is
# used.
#
############################################################################
#
# Requires: co-expressions, ANSI terminal
#
############################################################################
#
# Links: ansi, options, random
#
############################################################################
link ansi
link options
link random
procedure main(args)
local length, steady, star, opts, r, ran1, ran2
randomize()
opts := options(args,"m+t+s:")
length := \opts["m"] | 10
steady := \opts["t"] | 50
star := \opts["s"] | "*"
star := star[1]
r := 0
ran1 := create 2(&random :=: r, |?(24 | 80), &random <-> r)
ran2 := ^ran1
clear() # clear the screen
every 1 to length do # start up the universe
place(ran1,star)
every 1 to steady do { # steady state condition
place(ran2," ") # clean up the beginning
place(ran1,star) # create more
}
every 1 to length do # and the universe dies
place(ran2," ") # clean up the end
clear() # clear the screen
home() # home the cursor
end
procedure clear()
ED()
return
end
procedure home()
CUP(1,1)
return
end
procedure place(e,s)
CUP(@e,@e)
writes(s)
return
end
|