File: mcdragoncurve.py

package info (click to toggle)
minetest-mod-pycraft 0.22-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,744 kB
  • sloc: python: 79,282; makefile: 10
file content (46 lines) | stat: -rwxr-xr-x 1,016 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#
# Code under the MIT license by Alexander Pruss
#

import mcpi.minecraft as minecraft
import mcpi.block as block
import lsystem

mc = minecraft.Minecraft()
playerPos = mc.player.getPos()

DIRECTIONS = ((1,0),(0,1),(-1,0),(0,-1))

pos = (int(playerPos.x),int(playerPos.y),int(playerPos.z))
direction = 0

def go():
    global pos
    dx = DIRECTIONS[direction][0]
    dz = DIRECTIONS[direction][1]
    # draw a wall
    mc.setBlocks(pos,pos[0]+dx*4,pos[1]+4,pos[2]+dz*4,block.BRICK_BLOCK)
    # draw a door in it
    mc.setBlocks(pos[0]+dx*2,pos[1],pos[2]+dz*2,pos[0]+dx*2,pos[1]+1,pos[2]+dz*2,block.AIR)
    pos = (pos[0]+dx*4, pos[1], pos[2]+dz*4)

def left():
    global direction
    direction -= 1
    if direction == -1:
        direction = 3

def right():
    global direction
    direction += 1
    if direction == 4:
        direction = 0

rules = {'X':'X+YF+', 'Y':'-FX-Y'}
dictionary = { '+': left,
               '-': right,
               'F': go }

lsystem.lsystem('FX', rules, dictionary, 14)

#go()