{"action":"created","issue":{"url":"https://api.github.com/repos/enzyme69/blendersushi/issues/431","repository_url":"https://api.github.com/repos/enzyme69/blendersushi","labels_url":"https://api.github.com/repos/enzyme69/blendersushi/issues/431/labels{/name}","comments_url":"https://api.github.com/repos/enzyme69/blendersushi/issues/431/comments","events_url":"https://api.github.com/repos/enzyme69/blendersushi/issues/431/events","html_url":"https://github.com/enzyme69/blendersushi/issues/431","id":346832718,"node_id":"MDU6SXNzdWUzNDY4MzI3MTg=","number":431,"title":"LIVENODING 1046 / SV Geometry Patterns in Python as Nodes","user":{"login":"enzyme69","id":3952687,"node_id":"MDQ6VXNlcjM5NTI2ODc=","avatar_url":"https://avatars1.githubusercontent.com/u/3952687?v=4","gravatar_id":"","url":"https://api.github.com/users/enzyme69","html_url":"https://github.com/enzyme69","followers_url":"https://api.github.com/users/enzyme69/followers","following_url":"https://api.github.com/users/enzyme69/following{/other_user}","gists_url":"https://api.github.com/users/enzyme69/gists{/gist_id}","starred_url":"https://api.github.com/users/enzyme69/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enzyme69/subscriptions","organizations_url":"https://api.github.com/users/enzyme69/orgs","repos_url":"https://api.github.com/users/enzyme69/repos","events_url":"https://api.github.com/users/enzyme69/events{/privacy}","received_events_url":"https://api.github.com/users/enzyme69/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-02T02:08:53Z","updated_at":"2018-08-02T02:15:50Z","closed_at":null,"author_association":"OWNER","body":"SOURCE:\r\nhttps://rigmarolestudio.com/geometry-patterns-in-python/\r\n\r\nSNL Gears:\r\n[sv_snl_gears.blend.zip](https://github.com/enzyme69/blendersushi/files/2251804/sv_snl_gears.blend.zip)\r\n\r\n```python\r\n\"\"\"\r\nin   gears s        default=7       nested=2\r\nin   inner_radius s        default=0.3       nested=2\r\nin   outer_radius s        default=0.8      nested=2\r\nin   gear_ratio s        default=0.5       nested=2\r\nout  verts v\r\n\"\"\"\r\n\r\nfrom math import sin, cos, radians, pi\r\nfrom mathutils import Vector, Euler\r\n\r\n# SOURCE: https://rigmarolestudio.com/geometry-patterns-in-python/\r\n# python pattern generator\r\n\r\nimport math\r\n\r\ndef polar_to_cartesian(theta, radius):\r\n        return (0.0, math.cos(theta)*radius, math.sin(theta)*radius)\r\n        \r\ndef lerp_values(lower, upper, segments, inclusive=True):\r\n    ''' lerp values and optionally include the first and last values '''\r\n    for each in range(segments):\r\n        if each in [0, segments-1] and not inclusive:\r\n            pass\r\n        else:\r\n            yield (each / float(segments-1)) * (float(upper)-float(lower)) + lower\r\n        \r\ndef gear_pattern(gears, inner_radius, outer_radius, gear_ratio):\r\n    \"\"\"\r\n    Draw gears. Lerp an arc until a segment is complete. Then lerp in or out.\r\n    Includes an option for the size ratio between teeth and notches\r\n    \"\"\"\r\n    \r\n    arc_samples = 5\r\n    notch_samples = 5\r\n    \r\n    # each gear has a corresponding notch. So multiply times 2.\r\n    gear_width = math.pi*2.0 / gears\r\n    # the width range of a gear or notch can be from 0 to 2 segments.\r\n    # For example, if the gear was 2 segments wide, the notch would be 0.\r\n    inner_width = (1 - gear_ratio) * (gear_width)\r\n    outer_width = gear_ratio * (gear_width)\r\n    \r\n    # multiply the width so the first gear is centered at the top\r\n    arc1 = 0 + (outer_width * 0.5)\r\n    arc2 = inner_width  + (outer_width * 0.5)\r\n    \r\n    for gear in range(gears):\r\n        # draw the inner notch\r\n        for lerp in lerp_values(arc1, arc2, arc_samples, inclusive=True):\r\n            yield polar_to_cartesian(lerp, inner_radius)\r\n        # draw outwards\r\n        for lerp in lerp_values(inner_radius, outer_radius, notch_samples, inclusive=False):\r\n            yield polar_to_cartesian(arc2, lerp)\r\n        arc1 += inner_width\r\n        arc2 = arc1 + outer_width\r\n        \r\n        # draw the outer edge of the tooth\r\n        for lerp in lerp_values(arc1, arc2, arc_samples, inclusive=True):\r\n            yield polar_to_cartesian(lerp, outer_radius)\r\n        # draw inwards\r\n        for lerp in lerp_values(outer_radius, inner_radius, notch_samples, inclusive=False):\r\n            yield polar_to_cartesian(arc2, lerp)\r\n        arc1 += outer_width\r\n        arc2 = arc1 + inner_width\r\n    \r\n    # cap off the shape if needed, by drawing another point at the original 0 point.\r\n    yield polar_to_cartesian(0 + (outer_width * 0.5), inner_radius)\r\n\r\nVerts = []\r\n\r\nVerts.append(list(gear_pattern(gears, inner_radius, outer_radius, gear_ratio)))\r\n\r\n\r\nverts = [Verts]\r\n```\r\n\r\n<img width=\"585\" alt=\"screen shot 2018-08-02 at 12 08 31 pm\" src=\"https://user-images.githubusercontent.com/3952687/43558422-cb0e71ec-964c-11e8-81a3-ad2547359866.png\">\r\n"},"comment":{"url":"https://api.github.com/repos/enzyme69/blendersushi/issues/comments/409783499","html_url":"https://github.com/enzyme69/blendersushi/issues/431#issuecomment-409783499","issue_url":"https://api.github.com/repos/enzyme69/blendersushi/issues/431","id":409783499,"node_id":"MDEyOklzc3VlQ29tbWVudDQwOTc4MzQ5OQ==","user":{"login":"enzyme69","id":3952687,"node_id":"MDQ6VXNlcjM5NTI2ODc=","avatar_url":"https://avatars1.githubusercontent.com/u/3952687?v=4","gravatar_id":"","url":"https://api.github.com/users/enzyme69","html_url":"https://github.com/enzyme69","followers_url":"https://api.github.com/users/enzyme69/followers","following_url":"https://api.github.com/users/enzyme69/following{/other_user}","gists_url":"https://api.github.com/users/enzyme69/gists{/gist_id}","starred_url":"https://api.github.com/users/enzyme69/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/enzyme69/subscriptions","organizations_url":"https://api.github.com/users/enzyme69/orgs","repos_url":"https://api.github.com/users/enzyme69/repos","events_url":"https://api.github.com/users/enzyme69/events{/privacy}","received_events_url":"https://api.github.com/users/enzyme69/received_events","type":"User","site_admin":false},"created_at":"2018-08-02T02:15:50Z","updated_at":"2018-08-02T02:15:50Z","author_association":"OWNER","body":"[python_pattern_study_010.blend.zip](https://github.com/enzyme69/blendersushi/files/2251818/python_pattern_study_010.blend.zip)\r\n<img width=\"731\" alt=\"screen shot 2018-08-02 at 12 14 13 pm\" src=\"https://user-images.githubusercontent.com/3952687/43558591-a1b29958-964d-11e8-9157-ff525240f426.png\">\r\n\r\n**SNL_sawtooth_wave.py**\r\n```\r\n\"\"\"\r\nin   height s        default=0.3       nested=2\r\nin   width s        default=0.5      nested=2\r\nin   segments s        default=5       nested=2\r\nout  verts v\r\n\"\"\"\r\n\r\nfrom math import sin, cos, radians, pi\r\nfrom mathutils import Vector, Euler\r\n\r\n# SOURCE: https://rigmarolestudio.com/geometry-patterns-in-python/\r\n# python pattern generator\r\n\r\nimport math\r\n\r\ndef polar_to_cartesian(theta, radius):\r\n        return (0.0, math.cos(theta)*radius, math.sin(theta)*radius)\r\n        \r\ndef lerp_values(lower, upper, segments, inclusive=True):\r\n    ''' lerp values and optionally include the first and last values '''\r\n    for each in range(segments):\r\n        if each in [0, segments-1] and not inclusive:\r\n            pass\r\n        else:\r\n            yield (each / float(segments-1)) * (float(upper)-float(lower)) + lower\r\n        \r\ndef sawtooth_wave_pattern(height, width, segments):\r\n    \"\"\" Create a generator of points that make a saw-tooth wave shape |_|⎺|_|⎺|_|⎺|_|⎺| \"\"\"\r\n    heightPoints = [1.0 * height, -1.0 * height]\r\n    segmentRange = range(-segments, segments+1)\r\n    widthPoints = [(x/float(segments) * width) for x in segmentRange]\r\n\r\n    for each, each2 in zip(widthPoints[0::2], widthPoints[1::2]):\r\n        # DOWN\r\n        yield [0.0, heightPoints[0], each]\r\n        yield [0.0, heightPoints[1], each]\r\n        # UP\r\n        yield [0.0, heightPoints[1], each2]\r\n        yield [0.0, heightPoints[0], each2]\r\n    # to finish the wave, add the final DOWN cycle\r\n    yield [0.0, heightPoints[0], widthPoints[-1]]\r\n    yield [0.0, heightPoints[1], widthPoints[-1]]\r\n\r\nVerts = []\r\n\r\nVerts.append(list(sawtooth_wave_pattern(height, width, segments)))\r\n\r\n\r\nverts = [Verts]\r\n```\r\n\r\n\r\n\r\n**SNL Spiral**\r\n\r\n```python\r\n\"\"\"\r\nin   loops s        default=5       nested=2\r\nin   startRadius s        default=0.2      nested=2\r\nin   endRadius s        default=1.5       nested=2\r\nin   density s        default=10       nested=2\r\nout  verts v\r\n\"\"\"\r\n\r\nfrom math import sin, cos, radians, pi\r\nfrom mathutils import Vector, Euler\r\n\r\n# SOURCE: https://rigmarolestudio.com/geometry-patterns-in-python/\r\n# python pattern generator\r\n\r\nimport math\r\n\r\ndef polar_to_cartesian(theta, radius):\r\n        return (0.0, math.cos(theta)*radius, math.sin(theta)*radius)\r\n        \r\ndef lerp_values(lower, upper, segments, inclusive=True):\r\n    ''' lerp values and optionally include the first and last values '''\r\n    for each in range(segments):\r\n        if each in [0, segments-1] and not inclusive:\r\n            pass\r\n        else:\r\n            yield (each / float(segments-1)) * (float(upper)-float(lower)) + lower\r\n        \r\ndef spiral_pattern(loops, startRadius, endRadius, density):\r\n    startRadius = float(startRadius)\r\n    endRadius = float(endRadius)\r\n    segments = loops*density+1\r\n    arcRange = [arc/float(segments-1) * math.pi * 2.0 for arc in range(int(segments))]\r\n    for i, lerp in enumerate(lerp_values(startRadius, endRadius, int(segments), inclusive=True)):\r\n        yield polar_to_cartesian(-arcRange[i]*loops, lerp)\r\n\r\nVerts = []\r\n\r\nVerts.append(list(spiral_pattern(loops, startRadius, endRadius, density)))\r\n\r\n\r\nverts = [Verts]\r\n```\r\n\r\n\r\n\r\n**SNL Star**\r\n\r\n\r\n```\r\n\"\"\"\r\nin   n s        default=8       nested=2\r\nin   innerRad s        default=0.1       nested=2\r\nin   outerRad s        default=1.0       nested=2\r\nout  verts v\r\n\"\"\"\r\n\r\nfrom math import sin, cos, radians, pi\r\nfrom mathutils import Vector, Euler\r\n\r\n# https://rigmarolestudio.com/geometry-patterns-in-python/\r\n# python generator\r\n\r\nimport math\r\n\r\ndef polar_to_cartesian(theta, radius):\r\n        return (0.0, math.cos(theta)*radius, math.sin(theta)*radius)\r\n        \r\ndef lerp_values(lower, upper, segments, inclusive=True):\r\n    ''' lerp values and optionally include the first and last values '''\r\n    for each in range(segments):\r\n        if each in [0, segments-1] and not inclusive:\r\n            pass\r\n        else:\r\n            yield (each / float(segments-1)) * (float(upper)-float(lower)) + lower\r\n\r\ndef star_pattern(points, innerRadius, outerRadius):\r\n    radiusChoice = [outerRadius, innerRadius]\r\n    switch = 0\r\n    segments = math.pi * 2.0\r\n    # I do this to shift the segments by half\r\n    for lerp in lerp_values(0, segments, points*2+1, inclusive=True):\r\n        yield polar_to_cartesian(lerp, radiusChoice[switch])\r\n        switch = -switch + 1\r\n        \r\n\r\nVerts = []\r\n\r\nVerts.append(list(star_pattern(n, innerRad, outerRad)))\r\n\r\nverts = [Verts]\r\n```"}}
{"actor":{"display_login":"enzyme69"}}