import rhinoscriptsyntax as rs import Rhino.Geometry as rg import random as r import perlin as p def draw_castle(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis n = 0 draw_fort(o + vz*h*n, l, w, h, t) draw_fort_vert(o + vz*h*n, l, w, h, t) n = 1 draw_fort(o + vz*h*n, l, w, h, t) draw_fort_vert(o + vz*h*n, l, w, h, t) n = 2 draw_fort(o + vz*h*n, l, w, h, t) draw_tower_a(o + vz*h*n, l, w, h, t) draw_tower_b(o + vz*h*n, l, w, h, t) draw_tower_c(o + vz*h*n, l, w, h, t) draw_tower_d(o + vz*h*n, l, w, h, t) draw_tower_a_vert(o + vz*h*n, l, w, h, t) draw_tower_b_vert(o + vz*h*n, l, w, h, t) draw_tower_c_vert(o + vz*h*n, l, w, h, t) draw_tower_d_vert(o + vz*h*n, l, w, h, t) n = 3 draw_tower_a(o + vz*h*n, l, w, h, t) draw_tower_b(o + vz*h*n, l, w, h, t) draw_tower_c(o + vz*h*n, l, w, h, t) draw_tower_d(o + vz*h*n, l, w, h, t) draw_tower_a_vert(o + vz*h*n, l, w, h, t) draw_tower_b_vert(o + vz*h*n, l, w, h, t) draw_tower_c_vert(o + vz*h*n, l, w, h, t) draw_tower_d_vert(o + vz*h*n, l, w, h, t) n = 4 draw_tower_a(o + vz*h*n, l, w, h, t) draw_tower_b(o + vz*h*n, l, w, h, t) draw_tower_c(o + vz*h*n, l, w, h, t) draw_tower_d(o + vz*h*n, l, w, h, t) def draw_fort(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o, o + vx*l) rs.AddLine(o, o + vy*w) rs.AddLine(o + vx*l, o + vx*l + vy*w) rs.AddLine(o + vy*w, o + vx*l + vy*w) rs.AddLine(o + vx*t + vy*t, o + vx*(l-t) + vy*t) rs.AddLine(o + vx*t + vy*t, o + vx*t + vy*(w-t)) rs.AddLine(o + vx*(l-t) + vy*t, o + vx*(l-t)+ vy*(w-t)) rs.AddLine(o + vx*t + vy*(w-t), o + vx*(l-t)+ vy*(w-t)) def draw_fort_vert(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o, o + vz*h) rs.AddLine(o + vy*w, o + vy*w + vz*h) rs.AddLine(o + vx*l, o + vx*l + vz*h) rs.AddLine(o + vx*l + vy*w, o + vx*l + vy*w + vz*h) rs.AddLine(o + vx*t + vy*t, o + vx*t + vy*t + vz*h) rs.AddLine(o + vx*t + vy*(w-t), o + vx*t + vy*(w-t) + vz*h) rs.AddLine(o + vx*(l-t) + vy*t, o + vx*(l-t) + vy*t + vz*h) rs.AddLine(o + vx*(l-t)+ vy*(w-t), o + vx*(l-t)+ vy*(w-t) + vz*h) def draw_tower_a(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o, o + vx*t) rs.AddLine(o, o + vy*t) rs.AddLine(o + vx*t, o + vx*t + vy*t) rs.AddLine(o + vy*t, o + vx*t + vy*t) def draw_tower_b(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vx*(l-t), o + vx*l) rs.AddLine(o + vx*(l-t), o + vy*t + vx*(l-t)) rs.AddLine(o + vx*l, o + vx*l + vy*t) rs.AddLine(o + vy*t + vx*(l-t), o + vx*l + vy*t) def draw_tower_c(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vy*(w-t), o + vx*t + vy*(w-t)) rs.AddLine(o + vy*(w-t), o + vy*w) rs.AddLine(o + vx*t + vy*(w-t), o + vx*t + vy*w) rs.AddLine(o + vy*w, o + vx*t + vy*w) def draw_tower_d(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vy*(w-t) + vx*(l-t), o + vx*l + vy*(w-t)) rs.AddLine(o + vy*(w-t) + vx*(l-t), o + vy*w + vx*(l-t)) rs.AddLine(o + vx*l + vy*(w-t), o + vx*l + vy*w) rs.AddLine(o + vy*w + vx*(l-t), o + vx*l + vy*w) def draw_tower_a_vert(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o, o + vz*h) rs.AddLine(o + vy*t, o + vy*t + vz*h) rs.AddLine(o + vx*t, o + vx*t + vz*h) rs.AddLine(o + vx*t + vy*t, o + vx*t + vy*t + vz*h) def draw_tower_b_vert(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vx*(l-t), o + vx*(l-t) + vz*h) rs.AddLine(o + vy*t + vx*(l-t), o + vy*t + vx*(l-t) + vz*h) rs.AddLine(o + vx*l, o + vx*l + vz*h) rs.AddLine(o + vx*l + vy*t, o + vx*l + vy*t + vz*h) def draw_tower_c_vert(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vy*(w-t), o + vy*(w-t) + vz*h) rs.AddLine(o + vy*w, o + vy*w + vz*h) rs.AddLine(o + vx*t + vy*(w-t), o + vx*t + vy*(w-t) + vz*h) rs.AddLine(o + vx*t + vy*w, o + vx*t + vy*w + vz*h) def draw_tower_d_vert(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis rs.AddLine(o + vy*(w-t) + vx*(l-t), o + vy*(w-t) + vx*(l-t) + vz*h) rs.AddLine(o + vy*w + vx*(l-t), o + vy*w + vx*(l-t) + vz*h) rs.AddLine(o + vx*l + vy*(w-t), o + vx*l + vy*(w-t) + vz*h) rs.AddLine(o + vx*l + vy*w, o + vx*l + vy*w + vz*h) def draw_fort_v2(o, l, w, h, t): vx, vy, vz = rg.Vector3d.XAxis, rg.Vector3d.YAxis, rg.Vector3d.ZAxis points = [] point = o points.append(point) point += vx*l points.append(point) point += vy*w points.append(point) point += -vx*l points.append(point) point += -vy*w points.append(point) rs.AddPolyline(points) points = [] point = o + vx*t + vy*t points.append(point) point += vx*(l-2*t) points.append(point) point += vy*(w-2*t) points.append(point) point += -vx*(l-2*t) points.append(point) point += -vy*(w-2*t) points.append(point) rs.AddPolyline(points) rs.EnableRedraw(False) objects = rs.ObjectsByLayer("Default") rs.DeleteObjects(objects) grid_size_x = 20 grid_size_y = 20 grid_spacing = 40 sampling = 0.1 perlin_scale = -20 perlin_offset = 5 perlin_shift = 10 perlin_gen = p.SimplexNoise() for i in range(grid_size_x): for j in range(grid_size_x): o = rg.Point3d(i*grid_spacing, j*grid_spacing, 0) z = perlin_gen.noise2(i*sampling, j*sampling) * perlin_scale + perlin_offset #print z #l, w, h, t = 6, 4, 1, 1 l = perlin_gen.noise2(i*sampling, j*sampling) * perlin_scale + perlin_offset w = perlin_gen.noise2(i*sampling + perlin_shift, j*sampling + perlin_shift) * perlin_scale + perlin_offset h = perlin_gen.noise2(i*sampling, j*sampling) * perlin_scale*0.1 + 2 t = 1 if t*2 >= l: t = int(l/2) - 1 if t*2 >= w: t = int(w/2) - 1 draw_castle(o, l, w, h, t)