Skip to content

Commit aa9eb68

Browse files
committed
fix flattening with None
1 parent 0240915 commit aa9eb68

15 files changed

Lines changed: 162 additions & 152 deletions

File tree

RaspberryJamMod.iss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
33

44
#define MyAppName "RaspberryJamMod"
5-
#define MyAppVersion "0.25"
5+
#define MyAppVersion "0.28"
66
#define MyAppPublisher "Omega Centauri Software"
77
#define MyAppURL "http://github.com/arpruss/raspberryjammod"
88

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ buildscript {
1717

1818
apply plugin: 'forge'
1919

20-
version = "0.25"
20+
version = "0.28"
2121
group= "mobi.omegacentauri.raspberryjammod" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
2222
archivesBaseName = "RaspberryJamMod"
2323

python2-scripts.zip

1.8 KB
Binary file not shown.

python2-scripts/mcpipy/lsystem.py

Lines changed: 124 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,124 @@
1-
#
2-
# Code under the MIT license by Alexander Pruss
3-
#
4-
# L-system with turtle graphics
5-
#
6-
7-
import collections
8-
import random
9-
import mcpi.settings
10-
from mcturtle import *
11-
12-
def playProgram(s, dictionary):
13-
for c in s:
14-
if c in dictionary:
15-
dictionary[c]()
16-
17-
18-
def transform(c, t):
19-
if isinstance(t, basestring):
20-
return t
21-
else:
22-
r = random.random()
23-
for p,out in t:
24-
if r<p:
25-
return out
26-
r -= p
27-
return c
28-
29-
def evolve(axiom, rules, levelCount):
30-
for i in range(levelCount):
31-
out = ""
32-
for c in axiom:
33-
if c in rules:
34-
out += transform(c, rules[c])
35-
else:
36-
out += c
37-
axiom = out
38-
return axiom
39-
40-
41-
def lsystem(axiom, rules, dictionary, levelCount):
42-
out = evolve(axiom, rules, levelCount)
43-
playProgram(out, dictionary)
44-
45-
if __name__ == "__main__":
46-
t = Turtle()
47-
t.pendelay(0)
48-
t.penup()
49-
t.turtle(None)
50-
t.go(10)
51-
t.verticalangle(90)
52-
t.pendown()
53-
t.penblock(WOOD)
54-
55-
# a fairly simple example with rules from http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-94to95/hwchen/
56-
# rules = {'F':'F[-&<F][<++&F]||F[--&>F][+&F]'}
57-
#
58-
# angle = 22.5
59-
#
60-
# dictionary = {
61-
# '[': t.push,
62-
# ']': t.pop,
63-
# 'F': lambda: t.go(5),
64-
# '-': lambda: t.yaw(-angle),
65-
# '+': lambda: t.yaw(angle),
66-
# '&': lambda: t.pitch(angle),
67-
# '^': lambda: t.pitch(-angle),
68-
# '<': lambda: t.roll(-angle),
69-
# '>': lambda: t.roll(angle),
70-
# '|': lambda: t.pitch(180)
71-
# }
72-
#
73-
# lsystem('F', rules, dictionary, 3)
74-
75-
76-
#
77-
# A more complex example with
78-
# rules based on http://www.geekyblogger.com/2008/04/tree-and-l-system.html
79-
#
80-
rules = {'A': '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'}
81-
82-
#randomized version:
83-
# rules = {'A': [(0.75,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
84-
# (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]}
85-
86-
axiom = 'fA'
87-
angle = 15
88-
thickness = 8
89-
length = 10 if mcpi.settings.isPE else 15;
90-
material = WOOD
91-
t.penwidth(thickness)
92-
t.penblock(material)
93-
94-
stack = []
95-
def push():
96-
global length
97-
global thickness
98-
stack.append((length,thickness))
99-
t.push()
100-
thickness = thickness * 0.6
101-
length = length * 0.75
102-
if thickness < 1:
103-
thickness = 1
104-
if length <= 1:
105-
t.penblock(LEAVES_OAK_PERMANENT)
106-
t.penwidth(thickness)
107-
108-
def pop():
109-
global length
110-
global thickness
111-
length,thickness = stack.pop()
112-
t.pop()
113-
114-
dictionary = {
115-
'[': push,
116-
']': pop,
117-
'^': lambda: t.pitch(angle),
118-
'>': lambda: t.roll(angle),
119-
'f': lambda: t.go(length)
120-
}
121-
122-
lsystem(axiom, rules, dictionary, 9 if mcpi.settings.isPE else 11)
1+
#
2+
# Code under the MIT license by Alexander Pruss
3+
#
4+
# L-system with turtle graphics
5+
#
6+
7+
import collections
8+
import random
9+
import mcpi.settings
10+
from mcturtle import *
11+
12+
def playProgram(s, dictionary):
13+
for c in s:
14+
if c in dictionary:
15+
dictionary[c]()
16+
17+
18+
def transform(c, t):
19+
if isinstance(t, basestring):
20+
return t
21+
else:
22+
r = random.random()
23+
for p,out in t:
24+
if r<p:
25+
return out
26+
r -= p
27+
return c
28+
29+
def evolveGenerator(axiom):
30+
for c in axiom:
31+
if c in rules:
32+
yield transform(c, rules[c])
33+
else:
34+
yield c
35+
36+
def evolve(axiom, rules, levelCount):
37+
for i in range(levelCount):
38+
axiom = ''.join(evolveGenerator(axiom))
39+
return axiom
40+
41+
42+
def lsystem(axiom, rules, dictionary, levelCount):
43+
out = evolve(axiom, rules, levelCount)
44+
playProgram(out, dictionary)
45+
46+
if __name__ == "__main__":
47+
t = Turtle()
48+
t.pendelay(0)
49+
t.penup()
50+
t.turtle(None)
51+
t.go(10)
52+
t.verticalangle(90)
53+
t.pendown()
54+
t.penblock(WOOD)
55+
56+
# a fairly simple example with rules from http://www.nbb.cornell.edu/neurobio/land/OldStudentProjects/cs490-94to95/hwchen/
57+
# rules = {'F':'F[-&<F][<++&F]||F[--&>F][+&F]'}
58+
#
59+
# angle = 22.5
60+
#
61+
# dictionary = {
62+
# '[': t.push,
63+
# ']': t.pop,
64+
# 'F': lambda: t.go(5),
65+
# '-': lambda: t.yaw(-angle),
66+
# '+': lambda: t.yaw(angle),
67+
# '&': lambda: t.pitch(angle),
68+
# '^': lambda: t.pitch(-angle),
69+
# '<': lambda: t.roll(-angle),
70+
# '>': lambda: t.roll(angle),
71+
# '|': lambda: t.pitch(180)
72+
# }
73+
#
74+
# lsystem('F', rules, dictionary, 3)
75+
76+
77+
#
78+
# A more complex example with
79+
# rules based on http://www.geekyblogger.com/2008/04/tree-and-l-system.html
80+
#
81+
rules = {'A': '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'}
82+
83+
#randomized version:
84+
# rules = {'A': [(0.75,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
85+
# (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]}
86+
87+
axiom = 'fA'
88+
angle = 15
89+
thickness = 8
90+
length = 10 if mcpi.settings.isPE else 15;
91+
material = WOOD
92+
t.penwidth(thickness)
93+
t.penblock(material)
94+
95+
stack = []
96+
def push():
97+
global length
98+
global thickness
99+
stack.append((length,thickness))
100+
t.push()
101+
thickness = thickness * 0.6
102+
length = length * 0.75
103+
if thickness < 1:
104+
thickness = 1
105+
if length <= 1:
106+
t.penblock(LEAVES_OAK_PERMANENT)
107+
t.penwidth(thickness)
108+
109+
def pop():
110+
global length
111+
global thickness
112+
length,thickness = stack.pop()
113+
t.pop()
114+
115+
dictionary = {
116+
'[': push,
117+
']': pop,
118+
'^': lambda: t.pitch(angle),
119+
'>': lambda: t.roll(angle),
120+
'f': lambda: t.go(length)
121+
}
122+
123+
lsystem(axiom, rules, dictionary, 9 if mcpi.settings.isPE else 11)
124+

python2-scripts/mcpipy/mcpi/block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __repr__(self):
9797
MELON = Block(103)
9898
FENCE_GATE = Block(107)
9999
REDSTONE_BLOCK = Block(152)
100+
QUARTZ_BLOCK = Block(155)
100101

101102
if settings.isPE:
102103
HARDENED_CLAY_STAINED = WOOL

python2-scripts/mcpipy/mcpi/connection.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ def send(self, f, *data):
6868

6969
def send_flat(self, f, data):
7070
"""Sends data. Note that a trailing newline '\n' is added here"""
71+
#print "f,data:",f,ddata
7172
s = "%s(%s)\n"%(f, ",".join(data))
72-
#print "f,data:",f,data
7373
self.drain()
7474
self.lastSent = s
7575
self.socket.sendall(s.encode('utf-8'))
7676

7777
def receive(self):
7878
"""Receives data. Note that the trailing newline '\n' is trimmed"""
79-
# s = self.socket.makefile("r").readline().rstrip("\n")
8079
s = self.readFile.readline().rstrip("\n")
8180
if s == Connection.RequestFailed:
8281
raise RequestError("%s failed"%self.lastSent.strip())

python2-scripts/mcpipy/mcpi/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def floorFlatten(l):
1414
yield str(e)
1515
elif isinstance(e, float):
1616
yield str(int(math.floor(e)))
17-
else:
17+
elif not e is None:
1818
for ee in floorFlatten(e): yield ee
1919

2020
def flatten_parameters_to_string(l):

python3-scripts.zip

58 Bytes
Binary file not shown.

python3-scripts/mcpipy/lsystem.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@ def transform(c, t):
2626
r -= p
2727
return c
2828

29+
def evolveGenerator(axiom):
30+
for c in axiom:
31+
if c in rules:
32+
yield transform(c, rules[c])
33+
else:
34+
yield c
35+
2936
def evolve(axiom, rules, levelCount):
3037
for i in range(levelCount):
31-
out = ""
32-
for c in axiom:
33-
if c in rules:
34-
out += transform(c, rules[c])
35-
else:
36-
out += c
37-
axiom = out
38+
axiom = ''.join(evolveGenerator(axiom))
3839
return axiom
3940

4041

@@ -120,3 +121,4 @@ def pop():
120121
}
121122

122123
lsystem(axiom, rules, dictionary, 9 if mcpi.settings.isPE else 11)
124+

python3-scripts/mcpipy/mcpi/block.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __repr__(self):
9797
MELON = Block(103)
9898
FENCE_GATE = Block(107)
9999
REDSTONE_BLOCK = Block(152)
100+
QUARTZ_BLOCK = Block(155)
100101

101102
if settings.isPE:
102103
HARDENED_CLAY_STAINED = WOOL

0 commit comments

Comments
 (0)