-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
153 lines (111 loc) · 2.87 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html>
<head><title>proc.bonsai</title>
<meta name="viewport" content="width=device-width, initial-scale=0.8">
<style>body,textarea{font-family:monospace;font-size:11pt;background-color:#17181c;color:#e8e7e3;}body{color:#737270;font-size:8pt;}a{color:#cfcfcf;}</style>
</head>
<body>
<textarea rows=45 cols=45 id="output" style="border:0;font-family:monospace"></textarea>
<br>
Bonsai is in the public domain. <br>
Ctrl+U or Cmd+Option+U to view source.
<br><br>inspired by <a href="https://www.reddit.com/r/unixporn/comments/amdt7m/2bwm_cat/">u/enjuus' rice</a> <a href="https://p.teknik.io/Raw/EWWzQ">[source code]</a>
<br><br>
Update: @jallbrit has ported bonsai to bash and C and added many features!
<br>
<a href="https://gitlab.com/jallbrit/bonsai.sh">bonsai.sh</a>
<br>
<a href="https://gitlab.com/jallbrit/cbonsai">cbonsai</a>
<script>
// inspired by https://p.teknik.io/Raw/EWWzQ
// and https://www.reddit.com/r/unixporn/comments/amdt7m/2bwm_cat/
var output = document.getElementById("output");
var rows=35
var cols=40
var grid
var branches = 0
var max_branches = 1024
var t = 50
function init() {
grid=[]
for(var row = 0; row < rows; row++) {
grid.push([])
for(var col = 0; col < cols; col++) {
grid[row].push(" ")
}
}
}
function show(){
var str = getString()
output.value = str
}
function getString(){
str = ""
for(var row = 0; row < rows; row++) {
str += grid[row].join("") +"\n";
}
return str
}
function bonsai(){
init()
grow()
//show()
}
bonsai()
function grow() {
var start = int(cols / 2) //+ rand(-1*cols/3, 2*cols / 3)
var x = start;
var y = rows - 3;
var life = 32
//branch(x,y,life)
window.setTimeout(function(){step(x,y,life)},400);
//grid[y][x] = "|"
}
function nextTimeT(){
t += 2;
return t;
}
function nextTime(){
return 1+Math.floor(nextTimeT()/5)
}
function step(x,y,life){
if(life<1){
return
}
var dy = (rand(0,10) > 3) ? -1 : 0
var dx = rand(-2,2)
if(branches < max_branches){
//if(rand(0,10)<2) { branch(x,y,life) }
//if(rand(0,20) + life < 15) { branch(x,y,life) }
if(life%13==0 || rand(0,40)<2 || life < 5){
//var f= life*life * rand(0,10)
//if(f < 500 || life < 2){
//if(life%15==0){
branches++
window.setTimeout(function(){step(x,y,life-1)},t+rand(1,11))
//step(x,y,life-1)
}
}
x += dx
y += dy
var char = (dx > 0) ? "/" : "\\"
if (dx == 0) { char = "|" }
if (dy == 0) { char = "~" }
if (life==1) { char = "&"}
if(x<0||x>rows-1||y<0){return}
grid[y][x] = char
show()
if(life>0){
window.setTimeout(function(){step(x,y,life-1)},t+rand(1,11))
//step(x,y,life-1)
}
}
function rand(min,max){
return int(min + Math.random() * (Math.abs(min)+max))
}
function int(float){
return Math.round(float) // yea i know
}
</script>
</body>
</html>