Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math, random
- import rhinoscriptsyntax as rs
- def RandomPoints(range, count, tolerance):
- points = []
- while len(points) < count:
- cur = (random.uniform(-range, range), random.uniform(-range, range), 0)
- good = True
- for old in points:
- if rs.PointCompare(cur, old, tolerance):
- good = False
- break
- if good:
- points.append(cur)
- return points
- def BuildSpeakers():
- random.seed(0)
- speaker = rs.ObjectsByName("Speaker", True, True)
- wires = rs.ObjectsByName("Wires", True, True)
- lights = rs.ObjectsByName("Lights", True, True)
- maxTranslation = 240 #rs.GetReal("max translation")
- minSpeakerOffset = -20 #rs.GetReal("min speaker offset")
- maxSpeakerOffset = +150 #rs.GetReal("max speaker offset")
- speakerTarget = (-100, 0, 0) # rs.GetPoint("speaker target")
- maxSpeakers = 50 # rs.GetInteger("max speakers")
- tolerance = 30 # rs.GetReal("speaker distance tolerance")
- whiteness = 255 # rs.GetInteger("light whiteness")
- allPoints = RandomPoints(maxTranslation, maxSpeakers, tolerance)
- for curTranslation in allPoints:
- curWires = rs.CopyObjects(wires, curTranslation)
- speakerOffset = (0, 0, random.uniform(minSpeakerOffset, maxSpeakerOffset))
- curSpeakerTranslation = rs.VectorAdd(curTranslation, speakerOffset)
- curSpeaker = rs.CopyObjects(speaker, curSpeakerTranslation)
- curSpeakerRotation = rs.Angle(speakerTarget, curSpeakerTranslation)
- rs.RotateObjects(curSpeaker, curSpeakerTranslation, curSpeakerRotation[0], (0, 0, 1))
- curLights = rs.CopyObjects(lights, curSpeakerTranslation)
- for curLight in curLights:
- rs.LightColor(curLight, (
- random.uniform(whiteness, 255),
- random.uniform(whiteness, 255),
- random.uniform(whiteness, 255)))
- rs.DeleteObjects(speaker)
- rs.DeleteObjects(wires)
- rs.DeleteObjects(lights)
- BuildSpeakers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement