Created
May 2, 2016 15:53
-
-
Save hamukazu/def4946dc90201bda59a032260bb597a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"This program draws a Koch curve in Minecraft" | |
import mcpi | |
import mcpi.block | |
import mcpi.minecraft | |
import numpy as np | |
LIMIT = 7 | |
m1 = np.array([[1. / 2., -np.sqrt(3) / 2., 0], | |
[np.sqrt(3) / 2., 1. / 2., 0], | |
[0, 0, 1]]) | |
def line(mc, v1, v2): | |
v = v2 - v1 | |
norm = np.sqrt((v**2).sum()) | |
v = v / norm | |
for d in np.arange(0, norm, 0.2): | |
x, y, z = v1 + v * d | |
mc.setBlock(x, y, z, mcpi.block.WOOL) | |
def curve(mc, v1, v2, depth=0): | |
if depth >= LIMIT: | |
line(mc, v1, v2) | |
else: | |
v3 = 2. / 3. * v1 + 1. / 3. * v2 | |
v4 = 1. / 3. * v1 + 2. / 3. * v2 | |
dv = (v2 - v1) / 3. | |
v5 = v3 + np.dot(m1, dv) | |
curve(mc, v1, v3, depth + 1) | |
curve(mc, v3, v5, depth + 1) | |
curve(mc, v5, v4, depth + 1) | |
curve(mc, v4, v2, depth + 1) | |
def main(): | |
mc = mcpi.minecraft.Minecraft() | |
x, y, z = mc.player.getPos() | |
curve(mc, np.array([x + 10, y, z]), np.array([x + 210, y, z])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment