Skip to content

Commit

Permalink
0.40
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jul 10, 2015
1 parent 5121711 commit 0236d42
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 12 deletions.
Binary file modified python2-scripts.zip
Binary file not shown.
Binary file modified python3-scripts.zip
Binary file not shown.
2 changes: 2 additions & 0 deletions python3-scripts/mcpipy/mcpipy.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<Compile Include="lforest.py" />
<Compile Include="lsystem.py" />
<Compile Include="ltree.py" />
<Compile Include="mandelbrot.py" />
<Compile Include="mc.py" />
<Compile Include="mcdragoncurve.py" />
<Compile Include="mcpi\block.py" />
Expand Down Expand Up @@ -63,6 +64,7 @@
<Compile Include="render\render.py" />
<Compile Include="scan.py" />
<Compile Include="server.py" />
<Compile Include="sierpinski3d.py" />
<Compile Include="simpletree.py">
<SubType>Code</SubType>
</Compile>
Expand Down
26 changes: 21 additions & 5 deletions python3-scripts/mcpipy/mengersponge.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
#
# Code under the MIT license by Alexander Pruss
#
# mengersponge [levels [options]]
# levels is a level count, up to 5
# options is a string of characters containing possibly the options 's' for 'slice' (cut off a diagonal slice) and 'c' for 'color'
#
from mc import *
import mcpi.settings as settings
import sys

def deleteCubes(x0,y0,z0,length):
RAINBOW = (STAINED_GLASS_RED,STAINED_GLASS_ORANGE,STAINED_GLASS_YELLOW,STAINED_GLASS_GREEN,STAINED_GLASS_BLUE,STAINED_GLASS_PURPLE)

def deleteCubes(x0,y0,z0,length,colorIndex=None):
nextColorIndex = colorIndex + 1 if colorIndex is not None else None
length /= 3
if length < 1:
return
Expand All @@ -16,10 +23,14 @@ def deleteCubes(x0,y0,z0,length):
posY = y0+y*length
posZ = z0+z*length
if (x == 1 and y == 1) or (x == 1 and z == 1) or (y == 1 and z == 1):
mc.setBlocks(posX,posY,posZ,
if colorIndex is not None:
mc.setBlocks(posX,posY,posZ,
posX+length-1,posY+length-1,posZ+length-1,RAINBOW[colorIndex])
else:
mc.setBlocks(posX,posY,posZ,
posX+length-1,posY+length-1,posZ+length-1,AIR)
else:
deleteCubes(posX,posY,posZ,length)
deleteCubes(posX,posY,posZ,length,nextColorIndex)

def slice(x0,y0,z0,length):
for x in range(0,length):
Expand All @@ -34,9 +45,14 @@ def slice(x0,y0,z0,length):
length = 3*3*3
else:
length = 3*3*3*3
if len(sys.argv) > 1:
length = 3**int(sys.argv[1])
colorIndex = None
if len(sys.argv) > 2:
colorIndex = 'c' in sys.argv[2]
mc.setBlocks(playerPos.x,playerPos.y,playerPos.z,
playerPos.x+length-1,playerPos.y+length-1,playerPos.z+length-1,WOOL_PURPLE)
deleteCubes(playerPos.x,playerPos.y,playerPos.z,length)
if len(sys.argv)>1 and sys.argv[1][0] == 's':
deleteCubes(playerPos.x,playerPos.y,playerPos.z,length,colorIndex=colorIndex)
if len(sys.argv)>2 and 's' in sys.argv[2]:
mc.postToChat("Slicing")
slice(playerPos.x,playerPos.y,playerPos.z,length)
17 changes: 12 additions & 5 deletions python3-scripts/mcpipy/sierpinski3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

from mc import *
import drawing
from sys import argv
import mcpi.settings as settings

RAINBOW = (WOOL_RED,WOOL_PINK,WOOL_ORANGE,WOOL_YELLOW,WOOL_GREEN,WOOL_BLUE,WOOL_LIGHT_BLUE,WOOL_PURPLE)

TAN30 = sqrt(3.)/3
SQRT32 = sqrt(3./2)

Expand All @@ -32,14 +35,14 @@ def average(a,b):
return tuple(0.5*(a[i]+b[i]) for i in range(len(a)))

def transform(tet):
height, apex = tet[0],tet[1]
level, height, apex = tet[0],tet[1],tet[2]
bottom = tetrahedronBottom(height,apex)
yield (height/2.,apex)
yield (level,height/2.,apex)
for p in bottom:
yield (height/2.,average(apex,p))
yield (level+1,height/2.,average(apex,p))

def sierpinski(height, x,y,z, level):
tetrahedra = [(height,(x,y,z))]
tetrahedra = [(0,height,(x,y,z))]
for i in range(level):
out = []
for tet in tetrahedra:
Expand All @@ -55,5 +58,9 @@ def sierpinski(height, x,y,z, level):
mc.player.setPos(tetrahedronBottom(height,(pos.x,pos.y+height,pos.z))[0])
tetrahedra = sierpinski(height,pos.x,pos.y+height,pos.z,levels)
mc.postToChat("Drawing")
if len(argv) >= 2 and '__' not in argv[1]:
block = lambda level : eval(argv[1])
else:
block = lambda level : RAINBOW[level % len(RAINBOW)]
for tet in tetrahedra:
drawTetrahedron(tet[0],tet[1],GOLD_BLOCK)
drawTetrahedron(tet[1],tet[2],block(tet[0]))
15 changes: 13 additions & 2 deletions python3-scripts/mcpipy/spacefill.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import lsystem
from mcturtle import *
from sys import argv
COLORS = (WOOL_WHITE,HARDENED_CLAY_STAINED_WHITE,WOOL_PINK,WOOL_MAGENTA,WOOL_PURPLE,HARDENED_CLAY_STAINED_LIGHT_BLUE,HARDENED_CLAY_STAINED_CYAN,HARDENED_CLAY_STAINED_PURPLE,HARDENED_CLAY_STAINED_LIGHT_GRAY,HARDENED_CLAY_STAINED_MAGENTA,HARDENED_CLAY_STAINED_PINK,HARDENED_CLAY_STAINED_RED,WOOL_RED,REDSTONE_BLOCK,HARDENED_CLAY_STAINED_ORANGE,WOOL_ORANGE,HARDENED_CLAY_STAINED_YELLOW,WOOL_YELLOW,WOOL_LIME,HARDENED_CLAY_STAINED_LIME,HARDENED_CLAY_STAINED_GREEN,WOOL_GREEN,HARDENED_CLAY_STAINED_GRAY,WOOL_BROWN,HARDENED_CLAY_STAINED_BROWN,WOOL_GRAY,HARDENED_CLAY_STAINED_BLUE,WOOL_BLUE,WOOL_CYAN,WOOL_LIGHT_BLUE,WOOL_LIGHT_GRAY)
t = Turtle()
t.pendelay(0)
t.turtle(None)
Expand All @@ -19,12 +21,21 @@
}
axiom = 'W'

colorIndex = 0
def go():
global colorIndex
t.penblock(COLORS[colorIndex % len(COLORS)])
colorIndex += 1
t.go(6)



dictionary = {
'F': lambda: t.go(6),
'F': go,
'+': lambda: t.yaw(-30),
'-': lambda: t.yaw(30),
'[': lambda: t.push(),
']': lambda: t.pop()
}

lsystem.lsystem(axiom, rules, dictionary, 5)
lsystem.lsystem(axiom, rules, dictionary, 6)

0 comments on commit 0236d42

Please sign in to comment.