Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ TESTER=./test/verify.py

SOGITREE=./SogiTree
TREE2PNG=./tree2png
TREE2HTML=./tree2html

.PRECIOUS : %.ppm
.PHONY : all note clean view
.PHONY : all note clean view web

all : $(TARGET)

Expand Down Expand Up @@ -43,6 +44,9 @@ $(RST)/%.mp4 : datas/%.tree
ffmpeg -r 10 -i $$DIR/%0$${#I}d.tree.png -r 10 $@ ;\
convert -delay 10 -loop 0 $$DIR/*.png $$DIR.gif

$(RST)/%.html : $(DATA)/%.tree
$(TREE2HTML) $< $@ tree.css

README.pdf : README.md
pandoc -t beamer $< --highlight-style=zenburn -o $@

Expand All @@ -59,6 +63,8 @@ note:
@echo "ERREURS = " $$(cat $(NOTE) | sort | uniq | grep "FAILED" | wc -l)
@echo "TESTS OK= " $$(cat $(NOTE) | sort | uniq | grep "SUCCESS" | wc -l)




generate:
./scripts/terraform.py > new_world.tree
cat new_world.tree | ./SogiTree > new_world.processed
./tree2png new_world.processed new_world.png
eog new_world.png
135 changes: 114 additions & 21 deletions SogiTree
Original file line number Diff line number Diff line change
@@ -1,28 +1,121 @@
#! /bin/bash
#!/usr/bin/python3

IFS=''
COUNT=0
import fileinput
import random

TMP_FILE=.${0#./}.tmp
matrix = []

rm -f $TMP_FILE
#############
# Read file #
#############
for line in fileinput.input():
line = line[0:-1]
matrix.append(list(line))

#sed -e 's/[^- fFtTor]/ /g' |
while read LINE;
do
echo $LINE | grep -qi '-'
####################
# Grow the trees ! #
####################
for l in range(1, len(matrix)-2):
for c in range(1, len(matrix[l])-1):
if matrix[l][c] == 'r':
# Grow the root
# R : new leaf
growing_chance = 0.15
n_of_new = 0
n_of_new_allowed = 1
if matrix[l+1][c-1] == '-':
if random.random() < growing_chance - 0.1:
matrix[l+1][c-1] = 'R'
n_of_new += 1
if matrix[l+1][c] == '-':
if random.random() < growing_chance - 0.1:
matrix[l+1][c] = 'R'
n_of_new += 1
if matrix[l+1][c+1] == '-' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance - 0.1:
matrix[l+1][c+1] = 'R'
n_of_new += 1
if matrix[l][c-1] == '-' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance - 0.0:
matrix[l][c-1] = 'R'
n_of_new += 1
if matrix[l][c+1] == '-' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance - 0.0:
matrix[l][c+1] = 'R'
n_of_new += 1

if [ "$?" = "0" ]
then
echo $LINE | grep -qi 'r'
if [ "$?" = "0" ]
then
echo $LINE | sed -e 's/[-]/ /g' | sed -e 's/[rR]/T/g' >> $TMP_FILE
fi
fi
echo $LINE >> $TMP_FILE
done
elif matrix[l][c] == 'T':
if random.random() < 0.07:
# N : new trunc
if matrix[l][c-1] == ' ':
matrix[l][c-1] = 'N'
if matrix[l][c+1] == ' ':
matrix[l][c+1] = 'N'

cat $TMP_FILE | tail -n+2
rm -f $TMP_FILE
elif matrix[l][c] == 't':
if random.random() < 0.15:
matrix[l][c] = 'T'

elif matrix[l][c] == 'F':
if random.random() < 0.2:
matrix[l][c] = 't'

elif matrix[l][c] == 'f':
if random.random() < 0.3:
matrix[l][c] = 'F'

# Grow the tree around the leaf
# n : new leaf
growing_chance = 0.3
n_of_new = 0
n_of_new_allowed = 2
if matrix[l-1][c-1] == ' ':
if random.random() < growing_chance:
matrix[l-1][c-1] = 'n'
n_of_new += 1
if matrix[l-1][c] == ' ':
if random.random() < growing_chance:
matrix[l-1][c] = 'n'
n_of_new += 1
if matrix[l-1][c+1] == ' ' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance:
matrix[l-1][c+1] = 'n'
n_of_new += 1
if matrix[l][c-1] == ' ' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance - 0.1:
matrix[l][c-1] = 'n'
n_of_new += 1
if matrix[l][c+1] == ' ' and n_of_new < n_of_new_allowed:
if random.random() < growing_chance - 0.1:
matrix[l][c+1] = 'n'
n_of_new += 1
#if matrix[l+1][c-1] == ' ' and n_of_new < n_of_new_allowed:
# if random.random() < growing_chance - 0.2:
# matrix[l+1][c-1] = 'n'
# n_of_new += 1
#if matrix[l+1][c] == ' ' and n_of_new < n_of_new_allowed:
# if random.random() < growing_chance - 0.2:
# matrix[l+1][c] = 'n'
# n_of_new += 1
#if matrix[l+1][c+1] == ' ' and n_of_new < n_of_new_allowed:
# if random.random() < growing_chance - 0.2:
# matrix[l+1][c+1] = 'n'

# Replace the new leaf (n) by leaf (f) and the new trunc (N) by trunc (T) and the new root "R"
for l in range(1, len(matrix)-1):
for c in range(1, len(matrix[l])-1):
if matrix[l][c] == 'n':
matrix[l][c] = 'f'
elif matrix[l][c] == 'N':
matrix[l][c] = 'T'
elif matrix[l][c] == 'R':
matrix[l][c] = 'r'

#######################
# Write modified file #
#######################
for line in matrix:
for character in line:
print(character, end = '')

print('')
Loading