Skip to content

Commit

Permalink
improve mandelbulb
Browse files Browse the repository at this point in the history
  • Loading branch information
arpruss committed Jun 28, 2015
1 parent c987319 commit 7e26ee8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
23 changes: 21 additions & 2 deletions python2-scripts/mcpipy/mandelbulb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
import cmath
import time
import sys
from random import uniform

# setting this to 0 makes for more isolated blocks because the connecting filigree was
# missed; increasing slows down rendering
AVOID_ISOLATES = 12 if not settings.isPE else 0

ESCAPE = 250
if len(sys.argv) < 2:
Expand All @@ -35,7 +40,14 @@

palette = list(reversed([WOOL_WHITE,HARDENED_CLAY_STAINED_WHITE,WOOL_PINK,WOOL_LIGHT_GRAY,WOOL_LIGHT_BLUE,WOOL_MAGENTA,WOOL_PURPLE,HARDENED_CLAY_STAINED_LIGHT_BLUE,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_PURPLE,HARDENED_CLAY_STAINED_CYAN,WOOL_CYAN,WOOL_BLUE,HARDENED_CLAY_STAINED_BLUE,WOOL_GRAY,HARDENED_CLAY_STAINED_GREEN,WOOL_GREEN,HARDENED_CLAY_STAINED_BROWN,WOOL_BROWN,HARDENED_CLAY_STAINED_GRAY,WOOL_BLACK]));

def calculate(pos):
def positions(pos,scale):
yield pos
for i in range(AVOID_ISOLATES):
yield (uniform(pos[0]-0.5*scale,pos[0]+0.5*scale),
uniform(pos[1]-0.5*scale,pos[1]+0.5*scale),
uniform(pos[2]-0.5*scale,pos[2]+0.5*scale))

def calculate0(pos):
x,z,y = pos[0],pos[1],pos[2]
cx,cy,cz = x,y,z

Expand Down Expand Up @@ -63,6 +75,13 @@ def calculate(pos):
except:
return 0

def calculate(pos0,scale):
for pos in positions(pos0,scale):
r = calculate0(pos)
if r >= 0:
return r
return r

#
# we could of course just do for x in range(0,size): for y in range(0,size): yield(x,y)
# but it will make users happier if we start at the player
Expand Down Expand Up @@ -107,7 +126,7 @@ def draw():
for mcX in rangeX:
for mcY in rangeY:
for mcZ in rangeZ:
radius = calculate(toBulb(centerMC,centerBulb,scale,mcX,mcY,mcZ))
radius = calculate(toBulb(centerMC,centerBulb,scale,mcX,mcY,mcZ),scale)
if radius < 0:
mc.setBlock(mcX,mcY,mcZ,AIR)
else:
Expand Down
4 changes: 3 additions & 1 deletion python2-scripts/mcpipy/mcpipy.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "mcpipy", "mcpipy.pyproj", "{AD0B690C-A698-4CE0-9B50-3069E7E8660D}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7CD6D1CE-4B00-4E16-94F0-FB3BF4F0D6F8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
Binary file modified python3-scripts.zip
Binary file not shown.
4 changes: 2 additions & 2 deletions zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ rm -rf *.{bak,pyc} */*.{bak,pyc} __pycache__ */__pycache__ */*/__pycache__
cd ..
zip -9r ../python3-scripts.zip mcpipy
cd ../python2-scripts
rm mcpipy/*.pyc mcpipy/*/*.pyc
rm mcpipy/*.pyc mcpipy/*/*.pyc mcpipy/_sunfish.*
zip -9r ../python2-scripts.zip mcpipy
rm mcpipy/*.pyc mcpipy/*/*.pyc
rm mcpipy/*.pyc mcpipy/*/*.pyc mcpipy/_sunfish.*
cd ..

0 comments on commit 7e26ee8

Please sign in to comment.