#! python 2 ############################## # final.PROJECT: female icons # friendship bracelets wrapped around the Empire State Building ############################## import math import sys import os import random ############################## import rhinoscriptsyntax as rs sys.path.append("/Users/anny.more/Documents/studium/5. semester/DM2") sys.path.append("P:/") import DM_lib as dm ############################## rs.UnitSystem(4) rs.ShowGrid(None, 0) rs.ShowGridAxes(None, 1) rs.ViewDisplayMode(rs.CurrentView(), "arctic") rs.Command("cplane w t enter", 0) dm.PointRadius(displayModeX=0, rad=3, styl=3) dm.printDisplay(1) rs.EnableRedraw(0) ############################## folder = "/Users/anny.more/Documents/studium/5. semester/DM2/8. finale/animation/viewcapturetofile/" ######################################################################################### # HELIX ######################################################################################### helix_color = (150, 50, 100) # Top of the ESB # print rs.GetObject() points = dm.getSurfacePoints('bbf2dcc5-17b4-43a8-95f6-d2a27887e12d') start = None n = 0 for point in points: if point.Z > 0: if start: start = rs.VectorAdd(start, point) else: start = point n += 1 start = rs.VectorDivide(start, n) def create_helix(turns=5, base_radius=50): base_point = [start.X, start.Y, 0] helix_points = [] for i in range(turns * 50): angle = i * (2 * math.pi / 50) threshold = 120 radius = base_radius if i <= threshold else base_radius * (1 - (i - threshold) / (turns * 50 - threshold)) x = base_point[0] + radius * math.cos(angle) y = base_point[1] + radius * math.sin(angle) z = base_point[2] + start.Z * i / (turns * 50) helix_points.append([x, y, z]) helix_curve = rs.AddCurve(helix_points) rs.ObjectColor(helix_curve, helix_color) rs.ObjectPrintWidth(helix_curve, 5) return helix_points ######################################################################################### # BEADS ######################################################################################### class Decoration: def __init__(self, main_color, step=2, amount=50, color=(255, 255, 255)): self.main_color = main_color self.step = step self.amount = amount self.color = color def sphere(r, n, c, step=1): for i in range(0, n, step): theta = math.acos(1 - 2 * (i + 0.5) / n) phi = math.pi * (1 + 5 ** 0.5) * i x = r * math.sin(theta) * math.cos(phi) y = r * math.sin(theta) * math.sin(phi) z = r * math.cos(theta) p = rs.AddPoint(rs.VectorAdd(c, [x, y, z])) rs.ObjectPrintWidth(p, 4) yield p def decorated_sphere(center, d, size): for p in sphere(size, 500, center): rs.ObjectColor(p, d.main_color) for p in sphere(size+1, d.amount, center, d.step): rs.ObjectColor(p, d.color) def circle(r, n, c): for i in range(n): angle = (2 * math.pi / n) * i x = r * math.cos(angle) y = r * math.sin(angle) yield rs.VectorAdd(c, (x, y, 0)) decorations = [ Decoration((255, 105, 180), 1, 50), Decoration((34, 139, 34), 3, 150), Decoration((0, 150, 139), 4, 300), Decoration((205, 133, 63), 5, 500), Decoration((255, 60, 122), 6, 600), Decoration((186, 85, 211), 7, 700), Decoration((255, 105, 180), 2, 200), Decoration((100, 50, 139), 3, 150 ), Decoration((0, 100, 255), 2, 200 ), Decoration((255, 160, 122), 1, 50 ), Decoration((186, 85, 211), 5, 500 ), Decoration((255, 160, 122), 3, 300 ), Decoration((34, 139, 34), 5, 500 )] def draw(): dm.newEmptyLayer("taylor") points = create_helix() for i, p in enumerate(range(20, len(points) - 75, 12)): decorated_sphere(points[p], random.choice(decorations), 20-i) ######################################################################################### # ANIMATION ######################################################################################### if not os.path.exists(folder): os.makedirs(folder) else: files = os.listdir(folder) [os.remove(os.path.join(folder, f)) for f in files if os.path.isfile(os.path.join(folder, f)) and "bracelets" in f] i = 0 for camera_position in circle(500, 150, start): if i % 9 == 0: draw() dm.setCameraTarget(camera_position, (start.X, start.Y, 200), lens=40) rs.Redraw() frame = dm.makeName("bracelets", i, format='jpg') rs.Command('-viewCaptureToFile Width=1080 Height=1920 Scale=1 DrawCPlaneAxes=No TransparentBackground=No "'+folder+frame+'"', 0) i+=1