{"id":23495,"date":"2019-01-10T12:15:22","date_gmt":"2019-01-10T10:15:22","guid":{"rendered":"http:\/\/www.webcodegeeks.com\/?p=23495"},"modified":"2019-01-10T11:13:48","modified_gmt":"2019-01-10T09:13:48","slug":"using-python-make-art-math","status":"publish","type":"post","link":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/","title":{"rendered":"Using Python to Make Art With Math"},"content":{"rendered":"\n<p><a rel=\"noreferrer noopener\" href=\"https:\/\/simpleprogrammer.com\/need-learn-math-programmer\/\" target=\"_blank\">Math<\/a>&nbsp;can be intimidating. <\/p>\n\n\n\n<p>Depending on the teacher and how it is taught, it can be an infuriating combination of inscrutable and boring.<\/p>\n\n\n\n<p>But, there\u2019s a beauty to math\u2014a symmetry to the intelligence and logic behind numbers. I love math, and I want other people to love it too.<\/p>\n\n\n\n<p>One neat way to make math more approachable and show its beauty visually is to combine it with something called \u201c<a rel=\"noreferrer noopener\" href=\"https:\/\/en.wikipedia.org\/wiki\/Generative_art\" target=\"_blank\">generative art<\/a>.\u201d Generative art is where you create a few, usually simple rules which are often math- or geometry-based, and then you tell a computer to process these rules.<\/p>\n\n\n\n<p>Since computers are great for processing instructions quickly, and on a much greater scale than a human could, the designs that are created are often more complex and interesting than you might expect from such simple rules.<\/p>\n\n\n\n<p><a href=\"https:\/\/codepen.io\/ashleymarkfletcher\/full\/eRrWZL\" target=\"_blank\" rel=\"noreferrer noopener\">This example<\/a>&nbsp;shows a bunch of floating particles that move with a mesmerizingly natural motion. They float around, link up with other particles, and change directions all on their own. It\u2019s a variation on a \u201cflocking algorithm,\u201d and the amazing thing is that most of this natural motion comes from simply having each particle follow the rules of \u201cdon\u2019t run into anybody,\u201d \u201cstay with the flock,\u201d and \u201cgo in roughly the same direction as those near you.\u201d<\/p>\n\n\n\n<p><a href=\"https:\/\/simpleprogrammer.com\/7-reasons-why-you-should-learn-python\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python<\/a>&nbsp;is a great option for creating these generative art projects; it is used by data scientists, mathematicians, and engineers (among many others) as an open source option for processing numerical calculations and generating visualizations.<\/p>\n\n\n\n<p>It is also extremely easy to read and write clear code, which makes it an ideal language for outlining the simple rules needed to create this generative art.<\/p>\n\n\n\n<p>One of the simplest mathematical constructs you can create with these rules is an&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Integer_sequence\" target=\"_blank\" rel=\"noreferrer noopener\">integer sequence<\/a>, which is an ordered list of integers (whole numbers, including: positive, negative, and zero). Usually, the relationship between these integers is spelled out in some sort of logical way with a set of rules in order to help someone figure out what the next number in the pattern is.<\/p>\n\n\n\n<p>In this article, we are going to take the mathematics of integer sequences, supercharge them with the power of programming in Python, and use them to create some interesting and beautiful generative art.<\/p>\n\n\n\n<p>It is a fun exercise, and the calculations and code samples are simple enough that they should be engaging for programmers, mathematicians, and artists alike.<\/p>\n\n\n\n<p>This is not a beginner\u2019s Python article, though, so I will assume you have some familiarity with Python\u2019s syntax\u2014or, at least, a willingness to pick it up as you go along\u2014as well as how to run Python programs. If you\u2019re not sure how to run them, and you\u2019d like to write code in an application with a big giant \u201cPlay\u201d button, the&nbsp;<a href=\"https:\/\/codewith.mu\/\" target=\"_blank\" rel=\"noreferrer noopener\">Mu text editor<\/a>&nbsp;is great for beginners.<\/p>\n\n\n\n<p>The particular sequence I want to talk about this time is the&nbsp;<strong>Recam\u00e1n sequence<\/strong>. The rules are deceptively simple, but when the numbers are given visual or auditory shape, the results can be interesting and even a little spooky.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Recam\u00e1n Sequence<\/h2>\n\n\n\n<p>Here are the rules:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>Start at zero.<\/li><li>Every step you take will be 1 bigger than the last step you took.<\/li><li>If it\u2019s possible to step backward (negatively), do so. Otherwise step forward.<\/li><li>Backward steps are only allowed if the resulting location is positive (greater than zero) and if we\u2019ve never been to that number before.<\/li><\/ol>\n\n\n\n<p>Let\u2019s do the first few as examples.<\/p>\n\n\n\n<p>We start at zero.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0<\/li><\/ul>\n\n\n\n<p>The next step size will be 1. Stepping backward would put us at -1, which is not allowed, so we\u2019ll step forward.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0 -&gt; 1<\/li><\/ul>\n\n\n\n<p>The next step size is 2. Stepping backward would put us at -1. That\u2019s still not allowed, so forward we must go.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0 -&gt; 1 -&gt; 3<\/li><\/ul>\n\n\n\n<p>The next step size is 3. Stepping backward puts us at 0. Since we\u2019ve already been to 0 (our first starting point), this is not a valid move. I promise the sequence gets interesting soon, but for now, we step forward.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0 -&gt; 1 -&gt; 3 -&gt; 6<\/li><\/ul>\n\n\n\n<p>The next step size is 4. Stepping backward lands us at 2. Since 2 is positive, and we haven\u2019t seen it yet, we can take our first legitimate backward step!<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>0 -&gt; 1 -&gt; 3 -&gt; 6 -&gt; 2<\/li><\/ul>\n\n\n\n<p>Hopefully you\u2019re beginning to see how the rules work. Now, this is kind of interesting to think about, but I\u2019m not sure I would call a list of five numbers&nbsp;<em>beautiful<\/em>. That\u2019s where we\u2019ll lean a little bit harder on art and code. Luckily Python provides both of these to us in a fun and adorable module in its Standard Library:&nbsp;<strong>Turtle<\/strong>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Introducing Turtle Graphics<\/h2>\n\n\n\n<p>Turtle Graphics was originally a&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Turtle_graphics\" target=\"_blank\" rel=\"noreferrer noopener\">key feature of the Logo programming language<\/a>.<\/p>\n\n\n\n<p>It\u2019s a relatively simple Domain-Specific Language (DSL) where there is an avatar\u2014traditionally shaped like a little turtle\u2014on the screen, and you give it instructions on where to go: forward, left, or right. As it moves, it draws a line wherever it goes with its tail, although you can tell it to pick its tail up or put it down as necessary. It can even jump positions and change colors!<\/p>\n\n\n\n<p>Python also includes a \u201cturtle\u201d library packaged along with it in its standard library. Let\u2019s take a look at a sample program to see how it works. Create a file called \u201cexample1.py\u201d with the following contents.<\/p>\n\n\n\n<pre class=\"brush:py\">import turtle\n\nwindow = turtle.Screen()\njoe = turtle.Turtle()\n\njoe.forward(50)\njoe.left(90)\njoe.forward(100)\n\nturtle.done()\n<\/pre>\n\n\n\n<p>Here are the important bits:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>On line 1, we import the \u201cturtle\u201d module. This will have many of the functions that we\u2019re going to use, and we couldn\u2019t use them unless we imported the module first. We\u2019ll use these functions by writing \u201cturtle.function_name,\u201d as you\u2019ll see.<\/li><li>On line 3, we create a Window. This is the window that will pop up when you run your code. It holds all of the stuff we\u2019re going to be drawing.<\/li><li>On line 4, we actually create our Turtle. We are going to call him \u201cjoe\u201d and store him in a variable so that we can give him commands later.<\/li><li>Lines 6-8 are us giving \u201cjoe\u201d commands. You see the \u201cdot\u201d syntax that should be getting pretty familiar.<\/li><li>Line 10 just keeps the window from closing when \u201cjoe\u201d is done with his drawing.<\/li><\/ul>\n\n\n\n<p>If you run your code, you should see something like the following:<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"285\" height=\"261\" src=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/pasted-image-0.png\" alt=\"\" class=\"wp-image-23496\"\/><\/figure><\/div>\n\n\n\n<p><em>Side note: If you want the real, old-fashioned Logo experience, you can add \u201cjoe.shape(\u201cturtle\u201d)\u201d to your code, right under the line where you define \u201cjoe.\u201d Isn\u2019t he cute?<\/em><\/p>\n\n\n\n<p>Okay, now that you\u2019ve seen what \u201cturtle\u201d is all about, let\u2019s get back to the sequence we were working on.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Coding the Sequence<\/h2>\n\n\n\n<p>Like anything good, we\u2019re definitely not going to get a perfect result on the first go. We\u2019ll need to do some iteration. I\u2019ll take you through three passes at this art project, and each one will get a little more complicated and a little more visually interesting. After that, I have some potential ideas for further iteration that you can try if this gets your creative spark going. Let\u2019s get to it!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">First Try<\/h3>\n\n\n\n<p>The code that we write will be very similar to the English we would use to describe the steps for the sequence. Remember the two rules: Go backward when possible, otherwise go forward, and increase the step size by one after each step.<\/p>\n\n\n\n<p>Create a new file named \u201crecaman1.py.\u201d We\u2019ll start with those basic rules and then figure out how to make it actually work. I\u2019m naming our new turtle Euler, after&nbsp;<a href=\"https:\/\/en.wikipedia.org\/wiki\/Leonhard_Euler\" target=\"_blank\" rel=\"noreferrer noopener\">some guy<\/a>.<\/p>\n\n\n\n<pre class=\"brush:py\">import turtle\n\nwindow = turtle.Screen()\neuler = turtle.Turtle()  # A good mathy name for our turtle\neuler.shape(\"turtle\")\n\ncurrent = 0   # Here's how we know where we are\nseen = set()  # Here's where we'll keep track of where we've been\n\n# Step increases by 1 each time\nfor step_size in range(1, 100):\n    \n    backwards = current - step_size\n    \n    # Step backwards if its positive and we've never been there before\n    if backwards &gt; 0 and backwards not in seen:\n        euler.backward(step_size)\n        current = backwards\n        seen.add(current)\n        \n    # Otherwise, go forwards\n    else:\n        euler.forward(step_size)\n        current += step_size\n        seen.add(current)\n        \nturtle.done()\n<\/pre>\n\n\n\n<p>\n\nHowever, when we run it, it doesn\u2019t look very good. In fact, it looks like maybe somebody gave Euler too much coffee.\n\n<\/p>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img decoding=\"async\" src=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman1-results.png\" alt=\"\" class=\"wp-image-23497\" width=\"820\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman1-results.png 976w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman1-results-300x261.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman1-results-768x667.png 768w\" sizes=\"(max-width: 976px) 100vw, 976px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Second Try<\/h3>\n\n\n\n<p>So, that was pretty reasonable. The code seems to read just like we might explain it to someone, which is good.<\/p>\n\n\n\n<p>I\u2019m afraid that the linear motion is just a little boring, though. This is when we want to put our artists\u2019 caps on (do artists wear caps?) and figure out a little more creative way to get Euler from point A to point B.<\/p>\n\n\n\n<p>Luckily turtles don\u2019t have to move in straight lines! They can also move in arcs and circles. Let\u2019s have him&nbsp;<em>bounce<\/em>&nbsp;from spot to spot on the number line! To make a turtle draw a circle or partial arc, we\u2019ll use the \u201ccircle\u201d command, which causes the turtle to follow a circle where the imaginary center is \u201cradius\u201d units to the turtle\u2019s&nbsp;<em>left<\/em>.<\/p>\n\n\n\n<p>That means we\u2019ll have to orient our turtle before drawing, depending on whether he\u2019s going forward or backward, using the \u201csetheading\u201d command.<\/p>\n\n\n\n<p>Remember that you can find&nbsp;<em>all<\/em>&nbsp;the turtle commands&nbsp;<a href=\"https:\/\/docs.python.org\/3.3\/library\/turtle.html?highlight=turtle#turtle-methods\" target=\"_blank\" rel=\"noreferrer noopener\">in the official documentation<\/a>, just in case you\u2019re curious.<\/p>\n\n\n\n<pre class=\"brush:py\">import turtle\n\nwindow = turtle.Screen()\neuler = turtle.Turtle()  # A good mathy name for our turtle\neuler.shape(\"turtle\")\n\ncurrent = 0   # Here's how we know where we are\nseen = set()  # Here's where we'll keep track of where we've been\n\n# Step increases by 1 each time\nfor step_size in range(1, 100):\n    \n    backwards = current - step_size\n    \n    # Step backwards if its positive and we've never been there before\n    if backwards &gt; 0 and backwards not in seen:\n        euler.setheading(90) # 90 degrees is pointing straight up\n        euler.circle(step_size\/2, 180)  # 180 degrees means \"draw a semicircle\"\n        current = backwards\n        seen.add(current)\n        \n    # Otherwise, go forwards\n    else:\n        euler.setheading(270)  # 270 degrees is straight down\n        euler.circle(step_size\/2, 180)\n        current += step_size\n        seen.add(current)\n        \nturtle.done()\n<\/pre>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" width=\"976\" height=\"848\" src=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman2-results.png\" alt=\"\" class=\"wp-image-23498\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman2-results.png 976w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman2-results-300x261.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman2-results-768x667.png 768w\" sizes=\"(max-width: 976px) 100vw, 976px\" \/><\/figure>\n\n\n\n<p>That\u2019s neat, but for the first little while, it seems like he just wiggles around in one place and the lines are very close together. Also, he\u2019s not going to be using the whole left half of the screen!<\/p>\n\n\n\n<p>Let\u2019s do one more iteration together, where we make it even nicer to look at.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Third Try<\/h3>\n\n\n\n<p>The goals for this iteration are to make the picture bigger, and to give him more room to work.<\/p>\n\n\n\n<<pre class=\"brush:py\">\nimport turtle\n\nwindow = turtle.Screen()\nwindow.setup(width=800, height=600, startx=10, starty=0.5)\neuler = turtle.Turtle()  # A good mathy name for our turtle\neuler.shape(&#8220;turtle&#8221;)\nscale = 5  # This isn&#8217;t a turtle module setting.  This is just for us.\n\n# Move the little buddy over to the left side to give him more room to work\neuler.penup()\neuler.setpos(-390, 0)\neuler.pendown()\n\ncurrent = 0   # Here&#8217;s how we know where we are\nseen = set()  # Here&#8217;s where we&#8217;ll keep track of where we&#8217;ve been\n\n# Step increases by 1 each time\nfor step_size in range(1, 100):\n\n    backwards = current &#8211; step_size\n\n    # Step backwards if its positive and we&#8217;ve never been there before\n    if backwards &gt; 0 and backwards not in seen:\n        euler.setheading(90)  # 90 degrees is pointing straight up\n        # 180 degrees means &#8220;draw a semicircle&#8221;\n        euler.circle(scale * step_size\/2, 180)\n        current = backwards\n        seen.add(current)\n\n    # Otherwise, go forwards\n    else:\n        euler.setheading(270)  # 270 degrees is straight down\n        euler.circle(scale * step_size\/2, 180)\n        current += step_size\n        seen.add(current)\n\nturtle.done()\n<\/pre>\n\n\n\n<p>\n\nAs you can see, we\u2019ve added a scaling factor which you can tune to whatever you think works best. I arrived at this value by trying a couple and picking my favorite. We also shifted him over so he starts at the left side of the screen. Since he can never go negative, we know he will only go right from wherever he starts.\n\n<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" width=\"816\" height=\"638\" src=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman3-results.png\" alt=\"\" class=\"wp-image-23499\" srcset=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman3-results.png 816w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman3-results-300x235.png 300w, https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2019\/01\/recaman3-results-768x600.png 768w\" sizes=\"(max-width: 816px) 100vw, 816px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Further Tweaking<\/h2>\n\n\n\n<p>By now, I think you get the gist (pun intended), and you\u2019re hopefully starting to see the magic of integer sequences: out of a few simple rules (and with the help of a tireless reptile assistant), you can make some truly interesting and captivating results.<\/p>\n\n\n\n<p>You\u2019ve got all the tools you need to do something even cooler. Here are some ideas to get your creative juices flowing:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>What if you change the color of the lines? What if you change it continuously?<\/li><li>What if you skew the drawing to an angle to take up more of the screen?<\/li><li>What if you have multiple turtles drawing sequences in tandem?<\/li><li>What if you vary the predictable sequence with a little bit of randomness?<\/li><li>What if you incorporate user input (mouse clicks, key presses, etc.) to affect how the turtles behave?<\/li><li>What if you make a turtle that draws but is driven by something really slow, like the cycle of the moon?<\/li><li>Is there a way you could incorporate a turtle with an IoT project or a web application?<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Other Incarnations of the Sequence<\/h2>\n\n\n\n<p>If you found the Recam\u00e1n sequence&nbsp;<em>particularly<\/em>&nbsp;fascinating, you\u2019re not alone. There are a ton of different incarnations out there people have created, combining the lines with color, sound, and more. Here are a few of my favorite.<\/p>\n\n\n\n<p>This slightly spooky version with sound:<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\nhttps:\/\/www.youtube.com\/watch?v=ebvW-sqL5yY\n<\/div><\/figure>\n\n\n\n<p>\n\nThis Numberphile video about the sequence is really interesting:\n\n<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"The Slightly Spooky Recam\u00e1n Sequence - Numberphile\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/FGC5TdIiT9U?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>\n\nThe Coding Train also did a couple videos on coding this up if you want a cool video walkthrough with an amazing teacher and don\u2019t mind writing JavaScript:\n\n<\/p>\n\n\n\n<figure class=\"wp-block-embed-youtube aligncenter wp-block-embed is-type-video is-provider-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Coding Challenge #110: Recam\u00e1n&#039;s Sequence - Part 1\" width=\"500\" height=\"281\" src=\"https:\/\/www.youtube.com\/embed\/DhFZfzOvNTU?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>In fact,&nbsp;<a href=\"https:\/\/p5js.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">P5.js<\/a>&nbsp;(and its Java-based predecessor,&nbsp;<a href=\"https:\/\/processing.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Processing<\/a>) are both great alternatives for making art and animations with code; they come with dedicated editors to help you do that, and they allow support for sound and other add-ins!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Get Your Turtles in Gear<\/h2>\n\n\n\n<p>Hopefully this tutorial was enough to spark your interest in using code to generate art, and hopefully (if you were before), you are no longer too intimidated to look to mathematics as a source for your artistic ideas.<\/p>\n\n\n\n<p>Geometry, never-ending constants, golden ratios, Fibonacci spirals, fractals, and number theory are all goldmines of awesome visual projects just waiting to be programmatically generated, and now you have all the tools you need to get your own set of turtles and start generating!<\/p>\n\n\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Ryan Palo, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/simpleprogrammer.com\/python-generative-art-math\/\" target=\"_blank\" rel=\"noopener\">Using Python to Make Art With Math<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>Math&nbsp;can be intimidating. Depending on the teacher and how it is taught, it can be an infuriating combination of inscrutable and boring. But, there\u2019s a beauty to math\u2014a symmetry to the intelligence and logic behind numbers. I love math, and I want other people to love it too. One neat way to make math more &hellip;<\/p>\n","protected":false},"author":10897,"featured_media":1651,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[53],"tags":[],"class_list":["post-23495","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Using Python to Make Art With Math - Web Code Geeks - 2026<\/title>\n<meta name=\"description\" content=\"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Using Python to Make Art With Math - Web Code Geeks - 2026\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\" \/>\n<meta property=\"og:site_name\" content=\"Web Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webcodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2019-01-10T10:15:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ryan Palo\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@webcodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ryan Palo\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\"},\"author\":{\"name\":\"Ryan Palo\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/862ca6e96af77f39f5f597ed16bc6cc0\"},\"headline\":\"Using Python to Make Art With Math\",\"datePublished\":\"2019-01-10T10:15:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\"},\"wordCount\":2105,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\",\"name\":\"Using Python to Make Art With Math - Web Code Geeks - 2026\",\"isPartOf\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"datePublished\":\"2019-01-10T10:15:22+00:00\",\"description\":\"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.webcodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\/\/www.webcodegeeks.com\/category\/python\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Using Python to Make Art With Math\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#website\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"name\":\"Web Code Geeks\",\"description\":\"Web Developers Resource Center\",\"publisher\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.webcodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/www.webcodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webcodegeeks\",\"https:\/\/x.com\/webcodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/862ca6e96af77f39f5f597ed16bc6cc0\",\"name\":\"Ryan Palo\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/0b836426da5f64d7de16599fe8fe475dc6af3018ca9476a162e87b4a95994454?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/0b836426da5f64d7de16599fe8fe475dc6af3018ca9476a162e87b4a95994454?s=96&d=mm&r=g\",\"caption\":\"Ryan Palo\"},\"description\":\"Ryan is a mechanical engineer in the East SF Bay Area. He is a hobbyist programmer, with a focus on dynamic languages like Ruby and Python. His goal is to learn as much as possible and become a physics, math, and programming teacher. He writes about scripting, physics, simulation, data science, the web, and more on his blog at assertnotmagic.com.\",\"sameAs\":[\"https:\/\/simpleprogrammer.com\"],\"url\":\"https:\/\/www.webcodegeeks.com\/author\/ryan-palo\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Using Python to Make Art With Math - Web Code Geeks - 2026","description":"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/","og_locale":"en_US","og_type":"article","og_title":"Using Python to Make Art With Math - Web Code Geeks - 2026","og_description":"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.","og_url":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/","og_site_name":"Web Code Geeks","article_publisher":"https:\/\/www.facebook.com\/webcodegeeks","article_published_time":"2019-01-10T10:15:22+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","type":"image\/jpeg"}],"author":"Ryan Palo","twitter_card":"summary_large_image","twitter_creator":"@webcodegeeks","twitter_site":"@webcodegeeks","twitter_misc":{"Written by":"Ryan Palo","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#article","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/"},"author":{"name":"Ryan Palo","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/862ca6e96af77f39f5f597ed16bc6cc0"},"headline":"Using Python to Make Art With Math","datePublished":"2019-01-10T10:15:22+00:00","mainEntityOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/"},"wordCount":2105,"commentCount":0,"publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/","url":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/","name":"Using Python to Make Art With Math - Web Code Geeks - 2026","isPartOf":{"@id":"https:\/\/www.webcodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage"},"image":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage"},"thumbnailUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","datePublished":"2019-01-10T10:15:22+00:00","description":"Interested to learn about Art With Math? Check our articledemonstrating example how to do art with math using python language.","breadcrumb":{"@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#primaryimage","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2014\/11\/python-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.webcodegeeks.com\/python\/using-python-make-art-math\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.webcodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Python","item":"https:\/\/www.webcodegeeks.com\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Using Python to Make Art With Math"}]},{"@type":"WebSite","@id":"https:\/\/www.webcodegeeks.com\/#website","url":"https:\/\/www.webcodegeeks.com\/","name":"Web Code Geeks","description":"Web Developers Resource Center","publisher":{"@id":"https:\/\/www.webcodegeeks.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.webcodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.webcodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.webcodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.webcodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webcodegeeks","https:\/\/x.com\/webcodegeeks"]},{"@type":"Person","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/862ca6e96af77f39f5f597ed16bc6cc0","name":"Ryan Palo","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.webcodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/0b836426da5f64d7de16599fe8fe475dc6af3018ca9476a162e87b4a95994454?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/0b836426da5f64d7de16599fe8fe475dc6af3018ca9476a162e87b4a95994454?s=96&d=mm&r=g","caption":"Ryan Palo"},"description":"Ryan is a mechanical engineer in the East SF Bay Area. He is a hobbyist programmer, with a focus on dynamic languages like Ruby and Python. His goal is to learn as much as possible and become a physics, math, and programming teacher. He writes about scripting, physics, simulation, data science, the web, and more on his blog at assertnotmagic.com.","sameAs":["https:\/\/simpleprogrammer.com"],"url":"https:\/\/www.webcodegeeks.com\/author\/ryan-palo\/"}]}},"_links":{"self":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/23495","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/users\/10897"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/comments?post=23495"}],"version-history":[{"count":0,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/posts\/23495\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media\/1651"}],"wp:attachment":[{"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/media?parent=23495"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/categories?post=23495"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webcodegeeks.com\/wp-json\/wp\/v2\/tags?post=23495"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}