File: borromean.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 (58 lines) | stat: -rw-r--r-- 1,212 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
47
48
49
50
51
52
53
54
55
56
57
58
#
# Code under the MIT license by Alexander Pruss
#

#
# Draw Borromean rings
#

from mc import *

def ball(x0,y0,z0,r,block_type,done):
  for x in range(-r,r):
    for y in range(-r,r):
      for z in range(-r,r):
         if (x**2 + y**2 + z**2 <= r**2):
            if not (x0+x,y0+y,z0+z) in done:
                mc.setBlock(x0+x,y0+y,z0+z,block_type)
                done.add((x0+x,y0+y,z0+z))

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

scale = 30
r = sqrt(3)/3


x0 = int(playerPos.x)
y0 = int(playerPos.y + 4 + (r/2+1) * scale)
z0 = int(playerPos.z)


# parametrization by I.J.McGee
done = set()
t = 0
while t < 2*pi:
  x = x0+int( scale * cos(t) )
  y = y0+int( scale * ( sin(t) + r) )
  z = z0+int( scale * - cos(3*t)/3 )
  ball(x,y,z,4,GOLD_BLOCK,done)
  t += 2*pi / 10000

done = set()
t = 0
while t < 2*pi:
  x = x0+int( scale * (cos(t) + 0.5) )
  y = y0+int( scale * ( sin(t) - r/2) )
  z = z0+int( scale * - cos(3*t)/3 )
  ball(x,y,z,4,LAPIS_LAZULI_BLOCK,done)
  t += 2*pi / 10000

done = set()
t = 0
while t < 2*pi:
  x = x0+int( scale * ( cos(t) - 0.5 ) )
  y = y0+int( scale * ( sin(t) - r/2) )
  z = z0+int( scale * - cos(3*t)/3 )
  ball(x,y,z,4,DIAMOND_BLOCK,done)
  t += 2*pi / 10000