Skip to content

Instantly share code, notes, and snippets.

@abought
Last active March 3, 2018 19:51
Show Gist options
  • Save abought/fdf9faf15b3142bdd8cad33c1204f65c to your computer and use it in GitHub Desktop.
Save abought/fdf9faf15b3142bdd8cad33c1204f65c to your computer and use it in GitHub Desktop.
Otter Graphics- A Revolution in Otters

Otter Programming Language (OPL)

Turtle graphics- with otters!

How to use this

OPL has been tested with Python 3.6. Although it may work with older versions, they are not officially supported.

OPL a thin wrapper around Python's turtle graphics library, and many excellent tutorials and exercise ideas are available. (just replace all references to "turtle" with the word "otter" where appropriate).

To use only the otter cursor + turtle graphics capabilities, you can run OPL from an interactive terminal: from otter import *

You may notice that the otter cursor is selected by default, with a custom window table. These default display options are set in turtle.cfg[1], which is automatically loaded whenever you start a new Otter session. (This file is purely for convenience- you can delete it, and write Python code to control the display instead)

Several demos have been written that show simple examples of how you can use the otter to draw or animate. Run python3 otter_demo.py --help for details.

For example: python otter_demo.py escalate --quick python otter_demo.py spiral

Or import otter_demo into your REPL to experiment with different parameters:

import otter_demo
otter_demo.spiral(turnings=2, increment_deg=5, control=False)

Many more (and better looking!) demos are available via the grace of the Python turtle graphics community.

[1] We apologize for the non-otter reference; this one is very difficult to customize. Just imagine that the turtle and the otter are friends.

FAQ

Q: Dear god, why does this exist?

A: It's better if you don't ask.

Q: How was the otter shape generated?

A: Turtle graphics allows you to change the cursor in two ways: either by specifying an image file (easy), or by giving it a set of points corresponding to a shape. The latter option is more work, but is required for things like coloring and rotation. Freely available line art was converted to an svg path, then subjected to additional manipulations to create a set of points suitable for use with OPL.

"""
A simple utility script that takes a set of points extracted from SVG, and performs scaling, centering, and rotation
required to turn it into a nice cursor
"""
coords = [
[356, 1.873], [356, 2.353], [353.789, 2.958], [351.087, 3.218],
[347.639, 3.549], [344.533, 4.779], [340.668, 7.345], [337.639, 9.355], [334.77, 11], [334.293, 11],
[333.815, 11], [331.192, 13.283], [328.462, 16.074], [309.915, 35.037], [299.936, 40.512], [284, 40.468],
[271.284, 40.432], [256.051, 39.143], [254.5, 37.971], [253.95, 37.556], [249.225, 36.654], [244, 35.966],
[238.775, 35.279], [234.014, 34.338], [233.42, 33.877], [231.751, 32.58], [190.872, 32.466], [188.5, 33.752],
[187.4, 34.349], [183.125, 35.376], [179, 36.035], [174.875, 36.694], [171.05, 37.586], [170.5, 38.019],
[169.95, 38.451], [167.475, 39.317], [165, 39.944], [159.63, 41.304], [159.426, 41.389], [145.773, 47.994],
[139.873, 50.847], [133.398, 54.491], [131.385, 56.091], [129.372, 57.691], [127.318, 59], [126.82, 59],
[125.735, 59], [115.411, 66.526], [114.522, 67.965], [113.745, 69.221], [99.797, 75.988], [97.895, 76.032],
[97.128, 76.049], [95.671, 76.692], [94.658, 77.459], [93.645, 78.227], [90.945, 79.164], [88.658, 79.541],
[86.371, 79.918], [84.05, 80.571], [83.5, 80.993], [82.95, 81.415], [78.45, 82.334], [73.5, 83.036],
[68.55, 83.737], [64.05, 84.648], [63.5, 85.059], [62.95, 85.471], [59.8, 86.109], [56.5, 86.478],
[44.891, 87.775], [28.871, 98.825], [19.5, 111.998], [17.85, 114.318], [15.825, 116.961], [15, 117.871],
[14.175, 118.782], [12.916, 120.646], [12.202, 122.014], [11.488, 123.381], [9.827, 126.3], [8.512, 128.5],
[-0.548, 143.652], [-2.086, 150.203], [3.272, 150.819], [6.336, 151.171], [31.304, 139.117], [44.5, 130.915],
[46.7, 129.548], [49.625, 127.86], [51, 127.164], [52.375, 126.468], [57.1, 123.926], [61.5, 121.515],
[74.657, 114.305], [97.163, 103], [98.372, 102.994], [98.993, 102.99], [100.819, 102.3], [102.43, 101.46],
[107.14, 99.003], [117, 98.293], [117, 100.41], [117, 101.393], [115.742, 102.543], [114, 103.15],
[112.35, 103.725], [111, 104.789], [111, 105.514], [111, 106.24], [110.438, 107.022], [109.75, 107.253],
[107.662, 107.954], [113.688, 118], [116.196, 118], [116.662, 118], [118.721, 119.105], [120.771, 120.456],
[122.822, 121.807], [126.525, 123.219], [129, 123.593], [131.475, 123.967], [133.95, 124.6], [134.5, 125],
[135.925, 126.037], [157.758, 127.09], [162.32, 126.342],
[168.873, 125.268], [171.139, 117.404], [165.623, 114.884],
[164.455, 114.351], [162.375, 113.265], [161, 112.472],
[159.459, 111.583], [155.718, 111.024], [151.25, 111.015],
[143.617, 110.999], [140.979, 108.975], [146.715, 107.535],
[148.209, 107.16], [151.246, 106.028], [153.465, 105.018],
[155.684, 104.008], [159.229, 102.858], [161.343, 102.462],
[163.457, 102.066], [167.282, 100.566], [169.843, 99.129],
[175.018, 96.225], [198.01, 95.139], [201.114, 97.651], [201.876, 98.269], [204.525, 99.101], [207, 99.5],
[209.475, 99.899], [211.95, 100.559], [212.5, 100.966], [213.05, 101.374], [217.1, 102.289], [221.5, 103],
[225.9, 103.711], [229.95, 104.564], [230.5, 104.896], [231.05, 105.228], [234.183, 105.95], [237.462, 106.5],
[243.386, 107.493], [243.43, 107.526], [244.217, 111.5],
[245.149, 116.209], [245.584, 117.317], [250.059, 126.373],
[255.282, 136.943], [263.079, 142], [274.152, 142], [277.854, 142], [281.133, 141.593], [281.441, 141.096],
[281.748, 140.599], [286.837, 139.866], [292.75, 139.468],
[306.288, 138.555], [308.426, 137.833], [307.579, 134.46],
[306.245, 129.143], [303.451, 127.716], [292.752, 126.887],
[281.151, 125.988], [279.589, 125.101], [280.299, 119.808],
[281.475, 111.038], [287.842, 101.422], [294.723, 98.02],
[297.35, 96.721], [300.892, 94.611], [302.594, 93.329], [304.296, 92.048], [306.041, 91], [306.472, 91],
[307.714, 91], [322.824, 77.822], [330.473, 70.069], [334.308, 66.181], [337.866, 63], [338.378, 63],
[339.306, 63], [347, 55.353], [347, 54.431], [347, 53.577], [353.292, 47], [354.109, 47],
[355.211, 47], [359.994, 42.461], [360.026, 41.385], [360.069, 39.895], [368.196, 36.639], [373.757, 35.884],
[379.335, 35.127], [388, 31.467], [388, 29.868], [388, 29.343], [390.025, 26.749], [392.5, 24.103],
[394.975, 21.457], [397, 18.589], [397, 17.73], [397, 16.87], [397.563, 15.962], [398.25, 15.712],
[400.038, 15.061], [397.844, 11.591], [395.393, 11.193],
[393.376, 10.866], [388.849, 8.953], [382.774, 5.864], [380.725, 4.821], [377.001, 3.688], [374.497, 3.345],
[371.994, 3.001], [369.706, 2.334], [369.414, 1.86], [368.715, 0.729], [356, 0.741], [356, 1.873],
[369.419, 5.869], [369.714, 6.346], [371.746, 7.024], [373.934, 7.373],
[376.122, 7.723], [380.024, 9.132], [382.605, 10.505], [385.186, 11.877], [388.356, 13], [389.649, 13],
[390.942, 13], [392, 13.45], [392, 14], [392, 14.55], [392.706, 15], [393.568, 15],
[395.583, 15], [393.314, 18.302], [386.25, 25.653], [381.526, 30.57], [380.945, 30.863], [373.621, 32.045],
[369.398, 32.726], [365.704, 33.67], [365.412, 34.142], [365.121, 34.614], [363.903, 35], [362.707, 35],
[361.251, 35], [356.921, 38.716], [349.599, 46.25], [334.983, 61.291], [314.884, 80], [313.342, 80],
[312.659, 80], [311.74, 80.595], [311.3, 81.323], [310.23, 83.092], [299.371, 91], [298.011, 91],
[297.421, 91], [296.678, 91.675], [296.362, 92.5], [296.045, 93.325], [295.375, 94], [294.872, 94],
[291.023, 94], [281.601, 102.616], [279.867, 107.72],
[279.161, 109.799], [278.24, 111.98], [277.822, 112.566],
[277.403, 113.152], [276.78, 116.077], [276.436, 119.066],
[275.479, 127.388], [278.69, 130.032], [290.989, 131.051],
[306.336, 132.322], [306.94, 135.958], [291.809, 135.985], [287.029, 135.993], [282.84, 136.45], [282.5, 137],
[282.16, 137.55], [277.859, 138], [272.941, 138], [267.647, 138], [264, 137.592], [264, 137],
[264, 136.45], [263.343, 136], [262.54, 136], [260.825, 136], [256, 131.064], [256, 129.31],
[256, 128.644], [255.411, 127.74], [254.691, 127.3], [253.971, 126.86], [252.794, 124.925], [252.074, 123],
[251.354, 121.075], [250.114, 118.02], [249.317, 116.21],
[248.394, 114.115], [247.953, 110.303], [248.103, 105.71],
[248.299, 99.657], [248.069, 98.448], [246.668, 98.177], [245.483, 97.947], [245, 98.55], [245, 100.26],
[245, 101.584], [244.773, 102.894], [244.495, 103.172],
[243.796, 103.871], [231.859, 102.148], [229.911, 101.066],
[229.038, 100.581], [224.763, 99.601], [220.411, 98.887], [216.06, 98.173], [212.275, 97.281], [212, 96.906],
[211.314, 95.969], [198.142, 94], [192.558, 94], [190.051, 94], [188, 93.55], [188, 93],
[188, 92.442], [185.282, 92], [181.845, 92], [175.946, 92], [175.759, 91.924], [177.345, 90.171],
[178.255, 89.165], [179, 88.04], [179, 87.671], [179, 85.875], [176.236, 87.492], [170.963, 92.374],
[166.918, 96.119], [163.998, 97.963], [161.329, 98.457], [159.223, 98.847], [156.15, 99.766], [154.5, 100.5],
[152.85, 101.234], [149.813, 102.412], [147.75, 103.118], [145.687, 103.824], [144, 104.761], [144, 105.201],
[144, 105.64], [143.48, 106], [142.844, 106], [140.963, 106], [135, 110.979], [135, 112.551],
[135, 114.297], [136.179, 114.421], [137.758, 112.842],
[138.634, 111.966], [139.325, 112.025], [140.603, 113.085],
[141.608, 113.919], [145.885, 114.74], [151.174, 115.114],
[162.563, 115.92], [168.973, 120.749], [160.983, 122.504], [157.309, 123.311], [136, 122.036], [136, 121.009],
[136, 120.606], [133.476, 119.979], [130.391, 119.616],
[118.126, 118.175], [111.287, 110.86], [117.453, 105.778], [119.404, 104.17], [121, 102.206], [121, 101.414],
[121, 100.621], [121.558, 99.079], [122.241, 97.986], [123.226, 96.409], [123.227, 95.593], [122.246, 94.022],
[120.42, 91.098], [120.505, 81.053], [122.387, 77.5], [123.357, 75.667], [123.578, 74.366], [122.954, 74.155],
[121.406, 73.633], [119, 76.011], [119, 78.063], [119, 79.064], [118.55, 80.16], [118, 80.5],
[116.697, 81.305], [116.697, 91.695], [118, 92.5], [120.405, 93.986], [118.497, 94.877], [111.5, 95.532],
[107.375, 95.919], [104, 96.596], [104, 97.038], [104, 97.48], [102.537, 98.154], [100.75, 98.536],
[98.962, 98.918], [96.375, 99.817], [95, 100.533], [93.625, 101.249], [85.525, 105.284], [77, 109.5],
[56.979, 119.402], [48.779, 123.75], [48.071, 124.84], [47.757, 125.323], [45.812, 126.322], [43.75, 127.06],
[41.687, 127.798], [40, 128.761], [40, 129.201], [40, 129.64], [39.583, 130], [39.073, 130],
[38.564, 130], [34.481, 132.25], [30, 135], [25.519, 137.75], [21.436, 140], [20.927, 140],
[20.417, 140], [20, 140.414], [20, 140.921], [20, 141.427], [18.537, 142.162], [16.75, 142.554],
[14.962, 142.946], [11.932, 144.107], [10.015, 145.133], [3.139, 148.816], [2.439, 147.235], [7.016, 138.353],
[10.805, 130.997], [11.538, 129.823], [16.75, 122.747], [19.087, 119.574], [21, 116.525], [21, 115.971],
[21, 112.277], [44.898, 92.016], [49.281, 91.994], [49.951, 91.99], [51.779, 91.321], [53.342, 90.505],
[54.905, 89.69], [60.305, 88.534], [65.342, 87.936], [70.379, 87.338], [75.4, 86.448], [76.5, 85.958],
[77.6, 85.469], [81.292, 84.586], [84.705, 83.998], [88.117, 83.41], [92.167, 82.272], [93.705, 81.47],
[95.242, 80.668], [97.175, 79.98], [98, 79.94], [98.825, 79.9], [101.75, 78.549], [104.5, 76.937],
[107.25, 75.326], [110.625, 73.456], [112, 72.782], [113.375, 72.109], [116.843, 69.857], [119.707, 67.779],
[122.571, 65.7], [125.158, 64], [125.455, 64], [125.752, 64], [128.311, 62.336], [131.142, 60.303],
[136.629, 56.36], [140.806, 53.849], [145.25, 51.818], [146.763, 51.127], [148, 50.282], [148, 49.941],
[148, 49.599], [149.912, 48.709], [152.25, 47.962], [154.588, 47.215], [157.4, 46.051], [158.5, 45.376],
[159.6, 44.701], [162.188, 43.84], [164.25, 43.463], [166.313, 43.086], [168, 42.428], [168, 42.002],
[168, 41.575], [171.037, 40.666], [174.75, 39.981], [178.463, 39.297], [182.132, 38.233], [182.904, 37.618],
[184.899, 36.03], [233.824, 36.074], [237.099, 37.668], [238.42, 38.31], [244.45, 39.373], [250.5, 40.03],
[256.55, 40.687], [261.95, 41.57], [262.5, 41.993], [264.511, 43.538], [286.308, 45.106], [291.5, 44.078],
[300.117, 42.373], [311.519, 35.804], [321.079, 27.037], [325.899, 22.617], [330.119, 19], [330.455, 19],
[330.792, 19], [332.486, 17.548], [334.221, 15.774], [338.016, 11.892], [347.464, 7.009], [351.191, 7.004],
[352.671, 7.002], [354.16, 6.55], [354.5, 6], [355.257, 4.775], [368.67, 4.657], [369.419, 5.869]]
# Center and scale coordinates for use in a cursor: target size ~n px in largest dimension
xc, yc = zip(*coords)
xavg = sum(xc) / len(xc)
xextent = max(xc) - min(xc)
yavg = sum(yc) / len(yc)
yextent = max(yc) - min(yc)
scale_factor = 100 / max(xextent, yextent)
new_x = [(c - xavg) * scale_factor
for c in xc]
new_y = [(c - yavg) * scale_factor
for c in yc]
# Re-combine the x and y coordinate lists to get a list of (x,y) coordinate pairs
print(list(zip(new_y, new_x)))
"""
Turtle graphics, but with otters.
It's better if you just don't ask.
"""
from turtle import *
# Special cursor option: an otter roughly 100px in its longest dimension, with pen centered on the otter's body
addshape('otter', (
(-20.20842751562628, 39.38188568352402), (-20.089061349965938, 39.38188568352402),
(-19.938610245331546, 38.83205528295105), (-19.873953572265524, 38.16012324208804),
(-19.791640653862245, 37.30267628542791), (-19.48576485435762, 36.53027772180077),
(-18.847653227098366, 35.56913140872321), (-18.347807408395674, 34.81588116750409),
(-17.938729611497205, 34.10241964817173), (-17.938729611497205, 33.98379952104677),
(-17.938729611497205, 33.864930714410015), (-17.3709942860752, 33.21264435497859),
(-16.67692976866266, 32.53374928778538), (-11.96122018654371, 27.921490382572077),
(-10.599699859480417, 25.43991753439588), (-10.61064175799928, 21.476960834472482),
(-10.619594220423807, 18.314752162520545), (-10.940142111124187, 14.526617159387182),
(-11.23159449894486, 14.1409152365972), (-11.334796496338699, 14.004141505111386),
(-11.559105415975427, 12.829130811892382), (-11.730196920088586, 11.529780362777185),
(-11.901039744689953, 10.230429913661988), (-12.135047165286585, 9.046466758018456),
(-12.249688420222872, 8.898751128013775), (-12.572225747017594, 8.483705022832293),
(-12.600575211361924, -1.6820647397285058), (-12.280773359196921, -2.2719325417000404),
(-12.13231169065687, -2.5454800046716595), (-11.876917832046093, -3.608584917584096),
(-11.713038033774913, -4.634387903727673), (-11.549158235503732, -5.660190889871251),
(-11.327336110984927, -6.611390022477111), (-11.219657882378826, -6.748163753962924),
(-11.112228333284516, -6.884937485448737), (-10.896871876072312, -7.500419277134882),
(-10.74094982217849, -8.115901068821028), (-10.402745686140848, -9.451310047146123),
(-10.381607927638496, -9.50204066755177), (-8.739079752249811, -12.897262042053166),
(-8.029597105106143, -14.364471161628224), (-7.123408964134702, -15.974671000483898),
(-6.72552174526689, -16.475262857721965), (-6.327634526399078, -16.975854714960025),
(-6.00211304546285, -17.486642432181583), (-6.00211304546285, -17.61048482905419),
(-6.00211304546285, -17.880302099348924), (-4.130551039713381, -20.44766937909348),
(-3.7727012222441405, -20.668745465076906), (-3.460359755432908, -20.86196944573959),
(-1.777545499133857, -24.33055127621974), (-1.766603600614993, -24.803539707648852),
(-1.7623760489145202, -24.994276893193607), (-1.6024751228320215, -25.356602941875106),
(-1.4117379372872616, -25.60851528732079), (-1.2207520722307117, -25.860427632766477),
(-0.9877393696812501, -26.53186231460591), (-0.893987193735523, -27.100592358075087),
(-0.8002350177897924, -27.669322401544267), (-0.6378472965893689, -28.246507548414385),
(-0.5329045426129843, -28.383281279900196), (-0.427961788636596, -28.520055011386006),
(-0.19942531729939733, -29.639112814451725), (-0.024852300021145322, -30.87007639782402),
(0.14947203774531312, -32.10103998119631), (0.37601907298817383, -33.22009778426203),
(0.4782263523348434, -33.35687151574784), (0.5806823111933065, -33.49364524723366),
(0.7393398397168442, -34.27698570937966), (0.8311025795682333, -35.09762809829452),
(1.153639906362956, -37.98454855069229), (3.901548511668781, -41.968394329606255),
(7.177403720509836, -44.29877003461267), (7.754340187868161, -44.709091229070104),
(8.411600137535428, -45.212667240449676), (8.637898493266494, -45.417827837678395),
(8.864445528509355, -45.62298843490711), (9.327984138490358, -45.936075940253716),
(9.668177710622336, -46.11363311167348), (10.008122603242523, -46.291190283093236),
(10.734018098164487, -46.704246952180384), (11.281113024107729, -47.031260510187366),
(15.049104986785904, -49.28429688702636), (16.678204468537807, -49.66676597616304),
(16.831391047801908, -48.33434115197946), (16.918926235952828, -47.57238712784759),
(13.921343400807451, -41.36335707741539), (11.881674045086331, -38.08178223980311),
(11.541729152466147, -37.53468731385987), (11.121958136560604, -36.80729974186715),
(10.948877196353106, -36.465365413152625), (10.77579625614561, -36.123431084438096),
(10.143652937169373, -34.948420391219095), (9.544086634237939, -33.85423053933261),
(7.751107354214862, -30.582354202680236), (4.939785473401977, -24.985573110280875),
(4.938293396331223, -24.684919580523886), (4.937298678284052, -24.530489603700815),
(4.765709815147309, -24.076400815167922), (4.5568190252417065, -23.675778121670394),
(3.9458134647678245, -22.504497621128273), (3.7692510113952347, -20.052517634855384),
(4.295705537859706, -20.052517634855384), (4.540157497951618, -20.052517634855384),
(4.82613893651286, -20.3653564606902), (4.977087400170836, -20.79855617023253),
(5.120078119451453, -21.208877364689965), (5.38467311999855, -21.54459470560968),
(5.564965766048026, -21.54459470560968), (5.745507091609295, -21.54459470560968),
(5.939974469830941, -21.684352591236998), (5.99741943705498, -21.85544409535016),
(6.171743774821438, -22.37468691597265), (8.669978150287713, -20.876144177911755),
(8.669978150287713, -20.25245596233646), (8.669978150287713, -20.13657130984121),
(8.944769010818296, -19.624540195060693), (9.280735031249806, -19.11474719588631),
(9.616701051681314, -18.604705517200134), (9.967836522332156, -17.68384528503294),
(10.060842659742509, -17.068363493346794), (10.15384879715286, -16.45288170166065),
(10.311262928117436, -15.837399909974504), (10.41073473283439, -15.700626178488692),
(10.668615386563093, -15.346257874184543), (10.93047491248047, -9.91683809322146),
(10.744462637659767, -8.782362160424615), (10.47738084199475, -7.1527653196491325),
(8.521765161259452, -6.589257545927589), (7.89509279154265, -7.9609737329743755),
(7.76254661175731, -8.251431402747873), (7.492480661950783, -8.768684787276031),
(7.295277809099422, -9.110619115990557), (7.074201723115995, -9.493834243662617),
(6.935189876024054, -10.424144297277923), (6.9329517604179225, -11.535244355966286),
(6.928972888229243, -13.433415069477544), (6.425645556361461, -14.089431621585842),
(6.067547059380431, -12.66300594194474), (5.974292242458287, -12.29147875132692),
(5.692787035109313, -11.536239074013453), (5.441620728199005, -10.984419237346158),
(5.190454421288697, -10.432599400678862), (4.90447298272746, -9.551030531374863),
(4.805995896057676, -9.025322043445772), (4.707518809387893, -8.499613555516675),
(4.334499541699319, -7.548414422910808), (3.977147083253666, -6.911546193210522),
(3.254981781008585, -5.62462971968494), (2.984915831202058, 0.09300961544551427),
(3.6095987648245225, 0.8649108200490727), (3.763282703112217, 1.0544046080348681),
(3.9701840569234776, 1.7131566347728895), (4.069407182128638, 2.3286384264590345),
(4.1686303073338, 2.9441202181451795), (4.332758785116771, 3.5596020098313246),
(4.4339713464162696, 3.696375741317138), (4.535432587227562, 3.833149472802951),
(4.7629743405175935, 4.8403014955620955), (4.939785473401977, 5.93449134744858),
(5.116596606286361, 7.028681199335064), (5.328720229845262, 8.035833222094208),
(5.411281827760335, 8.172606953580022), (5.493843425675403, 8.309380685065834),
(5.673390033189506, 9.088493595511364), (5.810163764675315, 9.903913714678586),
(6.0571025198851505, 11.37709114253666), (6.0653089437742995, 11.388033041055529),
(7.053561323637227, 11.583743816836135), (8.224593144667557, 11.815513121826632),
(8.500130043733515, 11.92368870945632), (10.752171702525333, 13.036529524727229),
(13.380714142170817, 14.335382614818846), (14.638286433304891, 16.27433676826405),
(14.638286433304891, 19.027965002341094), (14.638286433304891, 19.948576554996496),
(14.53707387200539, 20.763996674163717), (14.41348015464458, 20.840589963795768),
(14.289886437283762, 20.916934573916034), (14.107604355139951, 22.182464609427466),
(14.008629909446578, 23.65290656265583), (13.781585515180137, 27.019529793301103),
(13.602038907666033, 27.55120658951321), (12.76324291439033, 27.34057504302507),
(11.44101395019023, 27.00883657429403), (11.0861482868625, 26.31402601834612),
(10.879992971586617, 23.653403921679416), (10.656430090485264, 20.768472905375987),
(10.43585136352542, 20.380035507956283), (9.119590707608342, 20.55659796132887),
(6.938671389189146, 20.849045067196723), (4.547369203793597, 22.43238751877881),
(3.7013615046759116, 24.1435512394222), (3.3783268188576088, 24.796832316900794),
(2.853613048975682, 25.677655147669405), (2.534805914857845, 26.10090767674004),
(2.216247460251805, 26.524160205810674), (1.955631331893388, 26.95810595388838),
(1.955631331893388, 27.065286823470895), (1.955631331893388, 27.374146777117037),
(-1.321467274506627, 31.13169420029994), (-3.249479529432968, 33.03384378599987),
(-4.216345471281752, 33.98752971372365), (-5.00739499829332, 34.87233141668095),
(-5.00739499829332, 34.99965532671865), (-5.00739499829332, 35.23042991366198),
(-6.909047224969668, 37.143770077392574), (-7.138329734842245, 37.143770077392574),
(-7.35070203791294, 37.143770077392574), (-8.986267186971439, 38.70846156559024),
(-8.986267186971439, 38.91163272672462), (-8.986267186971439, 39.18567754871983),
(-10.115023490997062, 40.3751116536228), (-10.382602645685667, 40.38306939800015),
(-10.753135118256315, 40.393762617007226), (-11.562835608652312, 42.41478100934392),
(-11.750588640055561, 43.797687774421355), (-11.938839030482395, 45.18482209119926),
(-12.849006043642515, 47.33963006088025), (-13.246644582998536, 47.33963006088025),
(-13.377201326689535, 47.33963006088025), (-14.022275980278977, 47.843206072259825),
(-14.68028196848162, 48.458687863945975), (-15.338287956684264, 49.074169655632126),
(-16.051500796504815, 49.5777456670117), (-16.26511649713447, 49.5777456670117),
(-16.47898087727592, 49.5777456670117), (-16.704781873983404, 49.71775223215081),
(-16.7669517519315, 49.88859505675217), (-16.928842114108342, 50.33323402383696),
(-17.79176002002791, 49.78763117496447), (-17.890734465721277, 49.17811769156133),
(-17.972052666077385, 48.676531116276095), (-18.447776572136213, 47.55075896639198),
(-19.21594758406288, 46.040030932253266), (-19.475320314862337, 45.53048661259068),
(-19.757074201723107, 44.60440411067584), (-19.842371274267894, 43.98171061314772),
(-19.927917026324472, 43.359265795131385), (-20.093786260689992, 42.79028707215041),
(-20.211660349279583, 42.71767265470703), (-20.492916877116766, 42.54384567596415),
(-20.489932722975258, 39.38188568352402), (-20.20842751562628, 39.38188568352402),
(-19.21470418650392, 42.71891605226599), (-19.096084059378953, 42.79227650824475),
(-18.92747935038372, 43.29759327620687), (-18.840690200768176, 43.84170404800861),
(-18.753652371640843, 44.38581481981034), (-18.403262939525376, 45.356162274824214),
(-18.061825969834437, 45.998004094760354), (-17.720637679655287, 46.63984591469649),
(-17.44137058791244, 47.428159967078344), (-17.44137058791244, 47.74970257582589),
(-17.44137058791244, 48.07124518457344), (-17.32946480760587, 48.33434810804978),
(-17.19269107612006, 48.33434810804978), (-17.05591734463425, 48.33434810804978),
(-16.944011564327678, 48.50991584337521), (-16.944011564327678, 48.72427758254024),
(-16.944011564327678, 49.2253667988019), (-16.122871816389228, 48.66111298654498),
(-14.294828725203427, 46.90444091524358), (-13.072071565720282, 45.729678901536374),
(-12.999208468765115, 45.58519610518499), (-12.705269285826517, 43.763867360817585),
(-12.535918538295906, 42.71369378251836), (-12.301165079163896, 41.795071665957295),
(-12.183788349597892, 41.72245724851391), (-12.066411620031888, 41.650091510582335),
(-11.970421328480027, 41.34719986521922), (-11.970421328480027, 41.049779169115524),
(-11.970421328480027, 40.68770179994581), (-11.046328262659534, 39.6109195138848),
(-9.172776820815725, 37.79008812854097), (-5.432388283946502, 34.15538838418352),
(-0.7798432978228187, 29.157178876668425), (-0.7798432978228187, 28.773715069484563),
(-0.7798432978228187, 28.60386696293037), (-0.6318789883063515, 28.37533049159317),
(-0.4508403037214984, 28.265911506404525), (-0.010926247360772556, 27.999824428786678),
(1.955631331893388, 25.299413610233188), (1.955631331893388, 24.96120947419556),
(1.955631331893388, 24.814488562238044), (2.1234900023532455, 24.629719684976305),
(2.3286505995819615, 24.55113695924992), (2.533811196810678, 24.472305554011733),
(2.7016698672705353, 24.30569028111083), (2.7016698672705353, 24.180604486679268),
(2.7016698672705353, 23.22343704579039), (4.8442925408737025, 20.880378685682555),
(6.113552769062022, 20.44916841223457), (6.630557474078387, 20.273600676909144),
(7.172927489297573, 20.04456684654836), (7.318653683207908, 19.940618810619142),
(7.464379877118244, 19.83642209517814), (8.191767449110962, 19.681494759331475),
(8.935070509858393, 19.595949007274896), (11.004581406994602, 19.357962714489588),
(11.662090036173662, 20.15647262685493), (11.915494458690093, 23.214981942389436),
(12.231566118178215, 27.03146640986714), (13.135764823055316, 27.181668834989733),
(13.142479169873715, 23.418899142059203), (13.144468605968049, 22.230211075691606),
(13.258115142857166, 21.18849260079331), (13.39488887434298, 21.10394156678391),
(13.531662605828792, 21.019390532774505), (13.643568386135362, 19.949819952555455),
(13.643568386135362, 18.72681411356052), (13.643568386135362, 17.41030477813165),
(13.542107145324074, 16.503370598624834), (13.39488887434298, 16.503370598624834),
(13.258115142857166, 16.503370598624834), (13.146209362550596, 16.339988159377242),
(13.146209362550596, 16.14029851140796), (13.146209362550596, 15.713813148684016),
(11.918727292343396, 14.513934504285773), (11.48254342865956, 14.513934504285773),
(11.316922873805833, 14.513934504285773), (11.092116595145518, 14.367462271840061),
(10.982697609956869, 14.188413023349545), (10.873278624768222, 14.00936377485903),
(10.392083769449961, 13.716667989479399), (9.913375709249626, 13.537618740988883),
(9.43466764904929, 13.358569492498368), (8.67495174052356, 13.050206897875812),
(8.224841824179347, 12.852009326977283), (7.703858246974306, 12.622478137592914),
(6.755891948021746, 12.512810472892474), (5.613706950359332, 12.550112399661332),
(4.108449865480042, 12.598853583972637), (3.807796335723051, 12.541657296260386),
(3.7404041880273184, 12.193257300239262), (3.6832079003150695, 11.898572078765289),
(3.8331616459258746, 11.778459874569567), (4.25840361109085, 11.778459874569567),
(4.587655284703964, 11.778459874569567), (4.913425445151986, 11.722009625392696),
(4.982558349430266, 11.652876721114415), (5.156385328173141, 11.479049742371537),
(4.727910529354866, 8.510562410105871), (4.45883929759551, 8.026134721134309),
(4.338229734376204, 7.8090375073395615), (4.094523812819669, 6.745932594427125),
(3.9169666413999082, 5.663679359106676), (3.7394094699801474, 4.58167480329802),
(3.5175873454613433, 3.6404228511638532), (3.4243325285392, 3.5720359854209467),
(3.191319825989735, 3.4014418403313704), (2.7016698672705353, 0.12583531100210998),
(2.7016698672705353, -1.2627910828465543), (2.7016698672705353, -1.8862306189100582),
(2.5897640869639624, -2.3962722975962314), (2.452990355478153, -2.3962722975962314),
(2.314227187898002, -2.3962722975962314), (2.2043108436857706, -3.0721832106479243),
(2.2043108436857706, -3.9268946926783457), (2.2043108436857706, -5.39385513274161),
(2.185411200789551, -5.440358201446788), (1.7494760166175045, -5.045952495744067),
(1.499304427754368, -4.819654140012999), (1.2195399769879376, -4.634387903727673),
(1.1277772371365484, -4.634387903727673), (0.6811488339574281, -4.634387903727673),
(1.0832636045257116, -5.3217380743218206), (2.2973169810961203, -6.633025140003053),
(3.2286217527585936, -7.6389337652032365), (3.6871867725037455, -8.365077939636997),
(3.8100344513291824, -9.028803556610862), (3.9070194609282116, -9.552522608445617),
(4.135555932265413, -10.31671474818361), (4.318086693921021, -10.727035942641043),
(4.500617455576628, -11.137357137098475), (4.793561920468058, -11.892596814411942),
(4.969129655793477, -12.405622647239625), (5.1446973911189, -12.918648480067306),
(5.3777100936683615, -13.338170816461059), (5.487129078857009, -13.338170816461059),
(5.596299384533867, -13.338170816461059), (5.685824008779124, -13.4674841625931),
(5.685824008779124, -13.625644332093055), (5.685824008779124, -14.093410493774526),
(6.923999297993396, -15.576286422592501), (7.314923490531022, -15.576286422592501),
(7.749117918120521, -15.576286422592501), (7.779954177582779, -15.28309327818928),
(7.387289228462604, -14.890428329069108), (7.169445976132477, -14.672585076738986),
(7.18411806732823, -14.500747534090449), (7.447718349828152, -14.18293511801978),
(7.655117062663, -13.933012208668437), (7.859282941844546, -12.86940993673242),
(7.952289079254899, -11.554143998862505), (8.152724765759558, -8.721933039059067),
(9.353598128204972, -7.127897368469889), (9.790030671400606, -9.114846667691026),
(9.990715037417058, -10.02849519401624), (9.673648659881769, -15.327606910800117),
(9.418254801270992, -15.327606910800117), (9.318036958018661, -15.327606910800117),
(9.162114904124838, -15.955273998564092), (9.071844241344204, -16.722450292443593),
(8.71349706485138, -19.77250450457716), (6.894406436090103, -21.473223685725262),
(5.630617157161217, -19.939865816013434), (5.230740502199065, -19.454692088506498),
(4.742333941038826, -19.057799587685853), (4.545379767699259, -19.057799587685853),
(4.348176914847898, -19.057799587685853), (3.964713107664044, -18.9190364201057),
(3.6929064012749726, -18.749188313551507), (3.300738811178386, -18.50423899443601),
(3.097816329555801, -18.503990314924216), (2.7071408165299693, -18.747944915992548),
(1.9800019240490412, -19.202033704525437), (-0.5179837719054406, -19.180895946023085),
(-1.4015420773037748, -18.71288110482982), (-1.8573716224192114, -18.47166197839121),
(-2.1809036672611013, -18.416703806285092), (-2.2333750442492937, -18.57187982164354),
(-2.3631857494049187, -18.956835705898147), (-1.7718258703626333, -19.55515861127062),
(-1.261535512164663, -19.55515861127062), (-1.0126073208604904, -19.55515861127062),
(-0.7400545759360384, -19.667064391577192), (-0.6555035419266275, -19.803838123063002),
(-0.45531653493375795, -20.127867526928476), (2.128463592589092, -20.127867526928476),
(2.3286505995819615, -19.803838123063002), (2.6981883541054428, -19.20576389720232),
(2.9197617991124534, -19.680244405702187), (3.082646879336464, -21.420254949713488),
(3.1788858504001163, -22.446057935857066), (3.347241879883561, -23.285351288156356),
(3.4571582240957923, -23.285351288156356), (3.567074568308027, -23.285351288156356),
(3.734684559256091, -23.64916941390861), (3.829680132760782, -24.0935597014816),
(3.924675706265474, -24.538198668566377), (4.148238587366822, -25.18153256557327),
(4.32629311781017, -25.523466894287797), (4.504347648253514, -25.865401223002323),
(5.5077694783357805, -27.87970526852062), (6.556202300052463, -29.99969810655068),
(9.018626825820634, -34.978510612145975), (10.099885343093913, -37.01768260884351),
(10.37094601094761, -37.193747703192514), (10.491058215143328, -37.27183306989532),
(10.739489047423922, -37.755514720331504), (10.9230145271267, -38.2682918736474),
(11.106540006829476, -38.78131770647508), (11.34601837668554, -39.20084004286883),
(11.455437361874187, -39.20084004286883), (11.564607667551043, -39.20084004286883),
(11.654132291796303, -39.304539399286256), (11.654132291796303, -39.43136595030037),
(11.654132291796303, -39.557943821802695), (12.213661193329163, -40.57330226845099),
(12.897529850758215, -41.68763516079265), (13.581398508187267, -42.80196805313432),
(14.140927409720128, -43.81732649978262), (14.140927409720128, -43.943904371284944),
(14.140927409720128, -44.070730922299056), (14.24388072760217, -44.17443027871648),
(14.36996124008091, -44.17443027871648), (14.495793073047855, -44.17443027871648),
(14.67857251421526, -44.53824840446873), (14.776054882837872, -44.982638692041725),
(14.873537251460485, -45.4272776591265), (15.162254164651442, -46.18077657985742),
(15.417399343750429, -46.65749520396342), (16.333285985681773, -48.36741552704784),
(15.940123677538017, -48.54149118530251), (13.731352253798075, -47.403285059828775),
(11.902065765053312, -46.461038389647435), (11.610116018209053, -46.27875630750362),
(9.850459792766152, -44.982638692041725), (9.061399701848924, -44.40147467298293),
(8.30317587039395, -43.9257507669241), (8.165407420860971, -43.9257507669241),
(7.246785304299909, -43.9257507669241), (2.2082897158744497, -37.982807794109746),
(2.202818766615016, -36.89284549392373), (2.2018240485678455, -36.72623022102284),
(2.0354574551787423, -36.27164407346636), (1.8325349735561576, -35.88295799653487),
(1.6298611714453664, -35.49427191960337), (1.3423876558133745, -34.151402555924506),
(1.19367730776153, -32.89880385502628), (1.044966959709682, -31.646205154128044),
(0.8236421942144615, -30.397585325418493), (0.7017892334361954, -30.124037862446873),
(0.5801849521697193, -29.85049039947525), (0.3606009432570467, -28.932365641937775),
(0.2143773903231274, -28.083622468190374), (0.06815383738920452, -27.235127973954764),
(-0.21484344703052446, -26.227975951195617), (-0.4142844154880168, -25.845506862058933),
(-0.6137253839455057, -25.46328645243404), (-0.7848168880586653, -24.982588956139367),
(-0.7947640685303622, -24.77742835891065), (-0.8047112490020556, -24.572267761681935),
(-1.140677269433564, -23.844880189689217), (-1.5415486424428866, -23.161011532260165),
(-1.9421713359404158, -22.477142874831113), (-2.4072020229921685, -21.637849522531823),
(-2.574812013940236, -21.295915193817297), (-2.74217332537651, -20.95398086510277),
(-3.302199585932954, -20.09156031820679), (-3.8189556114375254, -19.379342196433406),
(-4.335960316453887, -18.667124074660023), (-4.758715486500938, -18.02379017765313),
(-4.758715486500938, -17.94993236265079), (-4.758715486500938, -17.876074547648454),
(-5.172518194123462, -17.239703676971743), (-5.678083641597376, -16.535691979087513),
(-6.658626956594739, -15.17118749788271), (-7.283061210705412, -14.132453177125925),
(-7.788129299155741, -13.027321426720581), (-7.959966841804276, -12.651069325378705),
(-8.17010102926884, -12.34345276929153), (-8.254900742790042, -12.34345276929153),
(-8.339949135823037, -12.34345276929153), (-8.561273901318257, -11.867977542744493),
(-8.747037496627167, -11.286564844173903), (-8.932801091936076, -10.705152145603314),
(-9.22226404366241, -10.005865358443133), (-9.390122714122269, -9.732317895471514),
(-9.557981384582126, -9.458770432499893), (-9.772094444235366, -8.81518785598121),
(-9.865846620181095, -8.302410702665314), (-9.959598796126825, -7.789384869837632),
(-10.123229914886211, -7.3698625334438805), (-10.229167386909765, -7.3698625334438805),
(-10.335353538445112, -7.3698625334438805), (-10.56140321466439, -6.6146228561304135),
(-10.731748680242172, -5.691275828845299), (-10.901845466308162, -4.767928801560184),
(-11.166440466855256, -3.8555236727939306), (-11.31937836660757, -3.6635430896902133),
(-11.714281431333873, -3.167427463664409), (-11.70333953281501, 8.999217650777904),
(-11.306944391017952, 9.81364305189795), (-11.147292144447242, 10.142148686975688),
(-10.88294582341194, 11.641686143083755), (-10.719563384164344, 13.14619718942767),
(-10.55618094491675, 14.650708235771587), (-10.336596936004076, 15.993577599450447),
(-10.231405502515898, 16.13035133093626), (-9.847195656796668, 16.630445829150748),
(-9.457266182306212, 22.050913147689297), (-9.71290872042878, 23.34205717291535),
(-10.136907288034793, 25.484928526030313), (-11.770483000998953, 28.320372319487056),
(-13.95065628088277, 30.697748452222232), (-15.049819723005099, 31.896383699061513),
(-15.949293517158146, 32.94581123882537), (-15.949293517158146, 33.029367554787605),
(-15.949293517158146, 33.11317255026163), (-16.310376168280687, 33.534435643237934),
(-16.751533622200373, 33.96589459619772), (-17.716907486978403, 34.90963334344982),
(-18.931209543060604, 37.25915737086424), (-18.932452940619566, 38.18598591131444),
(-18.932950299643153, 38.554031588767174), (-19.045353438973308, 38.92431538182604),
(-19.18212717045912, 39.00886641583544), (-19.486759572404786, 39.19711680626228),
(-19.51610375479629, 42.53265509793351), (-19.21470418650392, 42.71891605226599)
))
"""
Demonstrations of otter motion.
Run `python3 otter_demo.py --help` for details, or `import otter_demo`
"""
import argparse
import math
import random
from otter import *
############################################################
# Example functions that move the otter in interesting ways
############################################################
def escalate(nsteps=3):
"""
Walk the otter up a flight of `nsteps` stairs.
We choose to rotate the otter to specify a direction of motion, though this is not the only way to move the otter
"""
for i in range(nsteps):
left(90)
forward(50)
right(90)
forward(75)
def spiral(a=0, b=10, turnings=2, increment_deg=10, control=True):
"""
Draw an Archimedean spiral of n full turns, wide enough to accommodate the otter
A given point along the spiral is defined in polar coordinates (and radians) according to the formula
r = a + b*theta
:param a: Affects the inner curve of the spiral; usually leave 0
:param b: Control the spacing between each turn of the spiral. From the equation for r, we can see that a good
minimum is (brush_size_px * 2* pi) so that the brush can fit inside the spiral.
:param turnings: How many full revolutions the spiral should go through
:param increment_deg: The spiral is drawn as a series of points and line segments- smaller increments translate to better graphics but slower drawing
:param control: Whether to spiral out of control
:return:
"""
if not isinstance(increment_deg, int):
raise TypeError("Increment must be specified as an integer, in degrees")
max_angle_deg = turnings * 360
for ang in range(0, max_angle_deg + increment_deg, increment_deg):
# Python's built-in range function only supports integer step sizes, so we convert to degrees inside the loop
# (Numpy is a very popular library whose range function is much smarter, but we're trying to keep this simple)
ang_rad = ang * math.pi / 180
# We can make the spiral seem ragged and out of control by slightly randomizing b
b_local = b if control else b * random.uniform(0.85, 1)
r = a + b_local * ang_rad
x = r * math.cos(ang_rad)
y = r * math.sin(ang_rad)
# Turtle graphics operates in cartesian coordinates and degrees
goto(x,y) # Go to next point in spiral
setheading(ang + 90) # Make it seem as though the otter is following the direction of movement
########
# Convenient helpers for using the demo script from the command line.
KNOWN_DEMOS = {
"escalate": escalate,
"spiral": spiral
}
def parse_args():
"""
Writing a command line argument parser is gratuitous, unnecessary, and frankly absurd... Just like otter graphics!
To see help text, run `python otter.py --help` at the command line
"""
parser = argparse.ArgumentParser("Otter Graphics- a Revolution in Otters!")
parser.add_argument("demo",
choices=KNOWN_DEMOS.keys(),
help="Which demo to run?")
parser.add_argument("--quick", action='store_true',
help="If specified, this closes the drawing window as soon as the demo is complete. WARNING: this will make it harder to gaze upon otter majesty")
return parser.parse_args()
if __name__ == '__main__':
args = parse_args()
func = KNOWN_DEMOS[args.demo]
func()
if not args.quick:
print("This has been a brief demonstration. For more, use `import otter_demo` in an interactive session ")
input("Plotting complete. Press enter to continue...")
width = 750
height = 600
shape = otter
pencolor = chocolate
fillcolor = chocolate
title = Otter Programming Language (OPL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment