素数オブジェ

エンドレスな素数遊びですが、今回は素数階段の延長で、オブジェを作ります。
素数が現れたら、右に90度回転し上がっていく階段です。

準備するもの
  • Linux PC(確認環境はDebian 8.3 Jessie)
  • 端末ウィンドウ(ターミナルソフト)
  • Blender(確認環境はv2.72)
#!/bin/bash
cat <<EOL>/tmp/tmp.py

import bpy,math

bpy.data.materials['Material'].diffuse_color=(0, 0.7, 1)
bpy.data.materials['Material'].emit=0.1

red=bpy.data.materials.new("red")
red.diffuse_color=(1, 0, 0)

yellow=bpy.data.materials.new("yellow")
yellow.diffuse_color=(1,1,0)

green=bpy.data.materials.new("green")
green.diffuse_color=(0,1,0)

bpy.ops.transform.resize(value=(999, 999, 0.5))

pos=bpy.context.object.location

forwards=[(0,2,0),(2,0,0),(0,-2,0),(-2,0,0)]
ups=[(0,2,2),(2,0,2),(0,-2,2),(-2,0,2)]
forward=forwards.pop(0)
forwards.append(forward)
up=ups.pop(0)
ups.append(up)

num=2
while num < 500:
    bpy.ops.mesh.primitive_cube_add(location=pos)
    bpy.ops.transform.resize(value=(1,1,1))

    for i in range(num-1,0,-1):
        if i < 2:
            bpy.context.object.data.materials.append(red)
            bpy.ops.transform.translate(value=up)
            forward=forwards.pop(0)
            forwards.append(forward)
            up=ups.pop(0)
            ups.append(up)
            break
        if (num % i) == 0:
            bpy.context.object.data.materials.append(yellow)
            bpy.ops.transform.translate(value=forward)
            break

    pos=bpy.context.object.location
    bpy.ops.object.text_add(rotation=(0,0,0),location=pos)
    bpy.context.object.data.materials.append(green)
    bpy.context.object.data.body="%d" % num
    bpy.context.object.data.extrude=0.1
    bpy.context.object.data.size=1.0
    bpy.context.object.data.align="CENTER"
    bpy.ops.transform.translate(value=(0,-0.6,1.1))

    num = num + 1   

EOL
blender -P /tmp/tmp.py

primes-art-002

primes-art-001

Leave a Reply

Your email address will not be published. Required fields are marked *

CAPTCHA