<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Farouk Ounane on Medium]]></title>
        <description><![CDATA[Stories by Farouk Ounane on Medium]]></description>
        <link>https://medium.com/@ounane.farouk?source=rss-e46b852794b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*G0skHtA2TTpRfaL6ji2BQQ.jpeg</url>
            <title>Stories by Farouk Ounane on Medium</title>
            <link>https://medium.com/@ounane.farouk?source=rss-e46b852794b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 16 Nov 2026 21:55:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ounane.farouk/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to approximate Euler’s number (and why is it irrational)]]></title>
            <link>https://medium.com/@ounane.farouk/how-to-approximate-eulers-number-and-why-is-it-irrational-f4a42ef227cb?source=rss-e46b852794b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4a42ef227cb</guid>
            <category><![CDATA[mathematics]]></category>
            <category><![CDATA[math]]></category>
            <category><![CDATA[mathematics-education]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Farouk Ounane]]></dc:creator>
            <pubDate>Sat, 31 Oct 2026 23:51:49 GMT</pubDate>
            <atom:updated>2026-11-01T15:35:51.522Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/823/1*Q71XSp2EMC8gJ5FC0JIsrQ.png" /></figure><p>Hello, and welcome. Writing this short post has been on my mind for quite a while. It is quite trivial, and at first I even hesitated to publish it, but it combines elementary mathematics and programming, and it’s always fun to bring those two together. So it might be worth sharing. Enjoy your read.</p><p>This post is about our favorite number, <strong><em>e</em></strong> or Euler’s number. This number is often expressed as the sum of the following infinite series:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/437/1*dZcUVTHLoqWM2sepsPGyOg.png" /></figure><p>During my first algorithms class (the first one I have ever taken), we were taught that this number could be approximated using the following algorithm:</p><pre>double euler_number(int num_iterations) {<br>    double result = 1.0;<br>    double term   = 1.0;<br>    for (int i = 1; i &lt;= num_iterations; ++i) {<br>        term /= i;         <br>        result += term;<br>    }<br>    return result;<br>}</pre><p>The problem with this algorithm is that it doesn’t let you control the precision, i.e., you don’t know how far off you are from the ‘real answer.’ Or, put another way, you don’t know how many digits after the decimal point you got right. And if you think about it, how could you know, when you have nothing to compare your answer against?</p><p>To answer this question, we estimate the difference between the partial sum of order <strong><em>n</em></strong> of the above series and the number <strong><em>e</em></strong> itself. We assume that <strong><em>n</em></strong> is at least greater than 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/911/1*tBjTJmAjTWjtP1UJZG_fcw.png" /></figure><p>If you are puzzled by the fact that the infinite series 1+1/2 +1/4+…= 2, the following picture might make it click forever:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yAAUfKWKi0MyZwXf7bGCvg.png" /><figcaption>A proof without words</figcaption></figure><p>Anyway, we’ve just shown that the partial sum of order <strong><em>n</em></strong> is at most at a distance of <strong><em>1/n!</em></strong> from the true value of <strong><em>e</em></strong>. That is to say, our previous algorithm approximates <strong><em>e</em></strong> with an error less than <strong><em>1/n!</em></strong>, where n = num_iterations.</p><p>Knowing that, we can now improve our previous algorithm as follows:</p><pre>double euler_number(double prec) {<br>    double result = 1.0;<br>    double term   = 1.0;<br>    int i = 1;<br><br>    while (term &gt; prec)<br>    {<br>        term /= i;         <br>        result += term;<br>        i++;<br>    }<br><br>    return result;<br>}</pre><p>Now, let’s test it.</p><pre>#include &lt;stdio.h&gt;<br>#include &lt;math.h&gt;<br><br>double euler_number(double prec) {<br>    double result = 1.0, term = 1.0;<br>    int i = 1;<br>    while (term &gt; prec) {<br>        term /= i;<br>        result += term;<br>        i++;<br>    }<br>    return result;<br>}<br><br>int main(void) {<br>    double e = euler_number(1e-15); // 15 decimals<br>    printf(&quot;%.17g\n&quot;, e);       <br>    printf(&quot;%.17g\n&quot;, M_E);     <br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*6SQ5fEV-iNxtIKKU6mODzw.png" /></figure><h4>So, Why is e Irrational?</h4><p>One famous fact about <strong><em>e</em></strong> is that it is irrational (and even transcendental). A rational number is a real number that can be written as a fraction of integers. An irrational number is the opposite: a number that cannot be written as a fraction of integers (the square root of 2 is a well-known example).</p><p>Since the definition of rational is more straightforward than that of irrational, we will use a proof by contradiction. This means that we will assume that <strong><em>e</em></strong> is rational and arrive at a contradiction.</p><p>So, assume that <strong><em>e</em></strong> is rational, thus <strong><em>e</em></strong> can be written as <strong><em>p/q</em></strong>, where <strong><em>p</em></strong> and <strong><em>q </em></strong>are positive integers. But, as we’ve seen earlier,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*ND-zfrzMEbPRYQmFhaGqYg.png" /></figure><p>This completes the proof, <strong><em>e</em></strong> is irrational.</p><p>I have always found the above proof delightful, and I hope that now you feel the same.</p><p>Thank you for reading all the way to the end.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4a42ef227cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reigniting the spark of creative coding]]></title>
            <link>https://medium.com/@ounane.farouk/reigniting-the-spark-of-creative-coding-366f92eeb485?source=rss-e46b852794b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/366f92eeb485</guid>
            <category><![CDATA[animation]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[art]]></category>
            <category><![CDATA[creative-coding]]></category>
            <dc:creator><![CDATA[Farouk Ounane]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 11:11:03 GMT</pubDate>
            <atom:updated>2026-09-11T15:16:53.998Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been 8 years since my last post on Medium. At the time, I owned a publication titled Farouk’s Home on the Internet which was about creative coding i.e. creating art using lines of code. I have since left the platform and forgotten how to write. It is time for me to start a new attempt :)</p><p>It is undeniable that times have changed since then, and the appearance of so-called LLMs has been a painful low-kick to a lot of creatives. Making art using code felt self-evident 8 years ago. Now that we have a cheat button at our disposal, not only is it very hard not to press it but it also destroys our desire to create. The piece of art you are thinking of is just a few prompts away anyway, so why bother making it.</p><p>For this first post, let’s try to reanimate our love for creative coding. For this purpose, the following animation seems fitting.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*1v-ap_a8wPhw89-_Z-D0Tg.gif" /></figure><p>The animation above was made exclusively by typing lines of (Java) code in a tool called Processing, which is a well known tool for creative coders. No AI was involved. In this post, I will explain the process of creating it and try to detail each step and the thinking that lies behind it.</p><p>I want this post to be as accessible as possible. As a prerequisite, you really need only a few programming basics. Most of the code is self explanatory, and I will make the effort to explain it even more. You don’t need to use Processing if you don’t want to, your favorite tool or programming language will do (as long as it allows you to draw line segments on the screen).</p><p>If you want, you can download Processing via the <a href="https://processing.org/download">official page</a>. Some tutorials are available <a href="https://processing.org/tutorials/">here</a>, although for understanding this post you don’t need them.</p><h4>Basic Processing Sketch</h4><p>Processing programs are called <em>sketches</em>. The basic structure of a Processing sketch is as follows:</p><pre>void setup() {<br>  size(640, 480);<br>}<br><br>void draw() {<br>  background(0, 0, 0);<br>}</pre><p>The important thing to know is that the procedure <strong><em>setup()</em></strong> will be executed only once, at the beginning of your program, whereas the <strong><em>draw()</em></strong> procedure will be re-executed continuously while your sketch is running. You can ‘stuff’ (for lack of a better word) each of the two procedures with the code you want.</p><p>This is to say that if your sketch is meant to be an animation with multiple frames, the drawing of each frame will be done by the <strong><em>draw()</em></strong> procedure. If your sketch is meant to be a game, then the <strong><em>draw() </em></strong>procedure will contain your “game loop”. On the other hand, the <strong><em>setup()</em></strong> procedure’s job is to prepare the ground for the <strong><em>draw() </em></strong>procedure.</p><p>In the code above, you can see that my <strong><em>setup()</em></strong> procedure contains the line of code <strong><em>size(640, 480)</em></strong>. This line of code creates a 640 x 480 pixels sized window. Changing these numbers will change the size of the window created.</p><p>The line <strong><em>background(0, 0, 0)</em></strong> paints the whole screen black. The color is by default encoded in RGB format (Red-Green-Blue). You can make the screen red by changing the line to <strong><em>background(255, 0, 0)</em></strong> and so on..</p><p>You are encouraged to play with the code as we go. There is no better way to understand what each line does.</p><h4>Introducing Time</h4><p>It wouldn’t be called an animation if the <strong><em>draw()</em></strong> procedure kept producing the same image again and again, right? To correct this issue, we need to introduce time. The way to do it is by creating a <em>global variable </em>i.e. a variable declared outside the procedures <strong><em>draw()</em></strong> and <strong><em>setup()</em></strong> (and any other procedures for that matter). The code is as follows:</p><pre>float time = 0.0;<br><br>void setup() {<br>  size(640, 480);<br>}<br><br>void draw() {<br>  background(0, 0, 0);<br><br>  time += 0.01; // increase the variable time by a value of 0.01<br>}</pre><p>You’ll notice that I have added the line <strong><em>time += 0.01 </em></strong>at the bottom of the <strong><em>draw() </em></strong>procedure. This line will increase the value of the variable time by <em>0.01</em> each time the procedure <strong><em>draw() </em></strong>is executed. In other terms, at each frame, <strong><em>time</em></strong> will be increased by <em>0.01</em>.</p><p>I chose the value <em>0.01</em> because it is decent for most animations, but feel free to increase it whenever you want your animation to be faster (but it can make your animation chunky) or lower it if you want your animation to be slower. The choice is yours.</p><p>Yeah, yeah, but this code doesn’t do anything more than the previous one!</p><p>Well, now that we have a variable that measures time let’s use it. For example, try the following code:</p><pre>float time = 0.0;<br><br>void setup() {<br>  size(640, 480);<br>}<br><br>void draw() {<br>  <br>  float factor = sin(time)*sin(time);<br>  background(30*factor, 120*(1-factor), 10);<br><br>  time += 0.01; // increase the variable time by a value of 0.01<br>}</pre><p>I have introduced a variable called <strong><em>factor</em></strong> that depends on <strong><em>time</em></strong> and have used it to change the color of the background. The code now makes the following animation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*_EXkI4QbCxpZSyQOX6N1ug.gif" /></figure><p>It is a boring animation but an animation nonetheless.</p><h4>An Animation a Tiny bit More Interesting</h4><p>As a first step towards our goal, let’s draw a moving line that extends horizontally from left to right. It is natural to choose the point of coordinates <em>(0, height/2)</em> as a starting point for our moving line. Here’s the code:</p><pre>float time = 0.0;<br><br>void setup() {<br>  size(640, 480);<br>}<br><br>void draw() {<br>  <br>  float speed = 200.0;<br>  line(0, height/2, speed * time, height/2);<br><br>  time += 0.01;<br>}</pre><p>The code is pretty self explanatory. At each frame, it draws a line that starts from the point of coordinates <em>(0, height/2)</em> and ends at the point of coordinates <em>(speed * time , height/2)</em>. Try it.</p><p>The most boring part about this animation is that after the line arrives at the right-most point of the window, nothing interesting happens. Our goal is a looping animation, so let’s make just that:</p><pre>float time = 0.0;<br><br>void setup() {<br>  size(640, 480);<br>  background(255, 255, 255); // draws a white background<br>}<br><br>void draw() {<br>  <br>  float speed = 200.0;<br>  line(0, height/2, speed * time, height/2);<br><br>  time += 0.01;<br>  if (speed * time &gt;= width) { // if the line has reached the right-most point<br>    time = 0.0;                // then reinitialize time at 0.0<br>    background(255, 255, 255); // and erase what was previously drawn<br>                               // by drawing a white background over it<br>  }<br>}</pre><p>With this code, when the line reaches the right-most point, we rewind time to the instant <em>0.0</em>. That much is clear. But we should also make sure to erase what was previously drawn by re-drawing a white background over it (Processing doesn’t do that automatically). We obtain the following looping animation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*RwbjqgeQkUSMsv2tnBvatw.gif" /></figure><h4>Drawing the graph of a function</h4><p>Since, we know how to draw a horizontal straight line, let’s draw more complicated mathematical functions. If you zoom closely at the the graph of any (smooth) function it will look like a straight line. Therefore, in order to draw the graph of a mathematical function, we can decompose it into small line segments. We can use the previous code as a basis and make something like that:</p><pre>final int UNIT_SPACE = 30;<br><br>float time = 0.0;<br><br>void setup() {<br>    size(640, 480);<br>    background(255, 255, 255);<br>}<br><br>void draw() {<br>  draw_graph();<br>  <br>  time += 0.1;<br>  if (time * UNIT_SPACE &gt;= width) {<br>    time = 0.0;<br>    background(255, 255, 255);<br>  }<br>}<br><br>void draw_graph() {<br>    float old_y = computeY(time - 0.1);<br>    float new_y = computeY(time);<br><br>    line((time - 0.1) * UNIT_SPACE, old_y * UNIT_SPACE, time * UNIT_SPACE, new_y * UNIT_SPACE);<br>}<br><br>float computeY(float t) {<br>    return sin(t) + 8; // I chose to plot the sine function. You can change this!<br>}</pre><p>This time the code is getting a bit long but the only changes made are really the addition of the procedure <strong><em>draw_graph() </em></strong>and the function <strong><em>computeY(float t)</em></strong>. The first one draws a line segment between two points. The first point corresponds to the position at the instant <em>time-0.1</em> and the second one corresponds to the actual position.<em> </em>The X-coordinates of these two points are computed using the formula <strong>time * UNIT_SPACE </strong>whereas the Y-coordinates are computed using the function <strong><em>computeY(float t), </em></strong>which, for this example, just returns the sine of t, but you can use any mathematical function of your choice.</p><p>The code above produces this animation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*xWZZr1UzyamoiiqYvLHaww.gif" /></figure><h4>EKG tracing</h4><p>To make it look (somewhat) like an EKG tracing, we just need to change the code of the <strong><em>computeY() </em></strong>function. I chose the following (maybe not very elegant) way of doing it.</p><pre>final float[] GRAPH = {0.0, 0.0, 2.0, -5.0, 0.0, 0.0, -0.5, -0.3};<br><br>/* the rest of the code */<br><br>float computeY(float t) {<br>    int i = int(t);<br><br>    float next_y = GRAPH[(i + 1) % 8] + 8;<br>    float old_y = GRAPH[i % 8] + 8;<br>    float lambda = t - i;<br>    float current_y = lambda * next_y + (1.0 - lambda) * old_y;<br>    return current_y;<br>}</pre><p>Our function just returns a linear interpolation between two Y-coordinates which are stored in the array I named GRAPH. I should also tell you that the values inside the array graph were found using the ancestral art of guessing and eyeballing.</p><p>The animation produced is as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*CpKAtSMffyojXEsutMatLg.gif" /></figure><h4>Stylize our Animation</h4><p>Instead of the boring <strong><em>background(255, 255, 255), </em></strong>let’s make a more interesting background. One that actually looks like the screen of an EKG monitor. We can just color the background with dark grey and draw a grid over it, like this:</p><pre>void draw_screen() {<br><br>  background(30); // shortcut for background(30, 30, 30);<br><br>  stroke(15, 45, 13); // Change the color of the stroke (encoded in RGB)<br>  strokeWeight(2); // You can imagine this as changing the size of the brush<br><br>  // Fill the window with equally spaced horizontal lines<br>  for (int i = 1; i &lt; height/UNIT_SPACE; i++) {<br>    line(0, i * UNIT_SPACE, width, i * UNIT_SPACE);<br>  }<br> <br>  // Fill the window with equally spaced horizontal lines<br>  for (int i = 1; i &lt; width/UNIT_SPACE; i++) {<br>    line(i * UNIT_SPACE, 0, i * UNIT_SPACE, height);<br>  }<br><br>}</pre><p>An other stylistic modification I made is to make the plot lines glowy by drawing them 3 times while changing the sizes and transparency values. It is a bit hacky but it works. Here’s the actual code:</p><pre>final float[] GRAPH = {0.0, 0.0, 2.0, -5.0, 0.0, 0.0, -0.5, -0.3};<br>final int UNIT_SPACE = 30;<br><br>float time = 0.0;<br><br>void setup() {<br>    size(640, 480);<br>    draw_screen(); // displays our new stylish background<br>}<br><br>void draw() {<br>  // I&#39;ve also added this loop to skip some frames<br>    for (int anim_step = 0; anim_step &lt; 10; ++anim_step) {<br>        draw_graph();<br><br>        time += 0.01;<br>        if (floor(time) * UNIT_SPACE &gt;= width) {<br>            time = 0.0;<br>            draw_screen();<br>        }<br>    }<br>}<br><br>void draw_graph() {<br>    float old_y = computeY(time - 0.1);<br>    float new_y = computeY(time);<br>    <br>    // glowy_lines instead of lines (the procedure glowy_lines is declared below)<br>    glowy_line((time - 0.1) * UNIT_SPACE, old_y * UNIT_SPACE, time * UNIT_SPACE, new_y * UNIT_SPACE);<br>}<br><br>void glowy_line(float x1, float y1, float x2, float y2) {<br>    // It draws 3 layers of lines, each one with different size and transparency.<br>    for (int layer = 1; layer &lt; 4; layer++) {<br>        stroke(20, 200, 20, 50 / (layer * layer));<br>        strokeWeight(3 * layer);<br><br>        line(x1, y1, x2, y2);<br>    }<br>}<br><br>float computeY(float t) {<br>    int i = int(t);<br><br>    float next_y = GRAPH[(i + 1) % 8] + 8;<br>    float old_y = GRAPH[i % 8] + 8;<br>    float lambda = t - i;<br>    float current_y = lambda * next_y + (1.0 - lambda) * old_y;<br>    return current_y;<br>}<br><br>void draw_screen() {<br><br>  background(30); // shortcut for background(30, 30, 30);<br><br>  stroke(15, 45, 13); // Change the color of the stroke (encoded in RGB)<br>  strokeWeight(2); // You can imagine this as changing the size of the brush<br><br>  // Fill the window with equally spaced horizontal lines<br>  for (int i = 1; i &lt; height/UNIT_SPACE; i++) {<br>    line(0, i * UNIT_SPACE, width, i * UNIT_SPACE);<br>  }<br> <br>  // Fill the window with equally spaced horizontal lines<br>  for (int i = 1; i &lt; width/UNIT_SPACE; i++) {<br>    line(i * UNIT_SPACE, 0, i * UNIT_SPACE, height);<br>  }<br><br>}</pre><p>The animation looks way cooler now:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*o0gscafBQfMPDCJhKwBm6Q.gif" /></figure><h4>Making a Heart (Mathematically)</h4><p>There is a well-known cartesian equation that produces a heart, the one below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/1*s_YoR0oQnZO_fH2IwTUnKA.png" /></figure><p>But, rather than a cartesian equation, we are interested in having a function y = f(x) (so we can plot it using the previous code). Let’s then solve for y.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/552/1*1pGqSalcTJsevYZ-NpP9iw.png" /></figure><p>One of the solutions corresponds to the lower part of the heart curve and the second one corresponds to upper half as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*VdwrvDTU1BZyXwQWGoqkQQ.png" /></figure><p>But why choose one solution or the other when we can oscillate between both. The key to do that is to put a <em>sin(ax)</em> just before the square root in the formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*QjLM0-puXezQ8SZXeKNRBw.png" /></figure><p>By taking the value of <em>a</em> sufficiently big, the graph of our function starts taking the shape of a heart as you can see:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*TieV-3IOdrJC0PFhCsweJw.gif" /></figure><p>We can now translate our formula into code and put it in the middle of our <strong><em>computeY </em></strong>function:</p><pre>final int BEGIN_HEART = 8;<br>final int END_HEART = 12;<br>/* these new global varibales determine when the heart should be drawn */<br><br>float computeY(float t) {<br>    int i = int(t);<br><br>    float scale = 2.0; // I&#39;ve added a scaling factor to adjust the heart&#39;s size.<br>    if (i &gt;= BEGIN_HEART &amp;&amp; i &lt;= END_HEART) {<br>        float x = (t - 2 * width / 160 - 2.3) / scale;<br><br>        // This the formula above transltated into code<br>        float x2 = x * x;<br>        float term1 = 0.5 * sqrt(max(0, pow(x2, 2.0 / 3.0) - 4.0 * x2 + 4.0)) * sin(50.0 * x);<br>        float term2 = 0.5 * pow(x2, 1.0 / 3.0);<br>        float y = -scale * (term1 + term2) + 8;<br><br>        return y;<br>    }<br><br>    float next_y = GRAPH[(i + 1) % 8] + 8;<br>    float old_y = GRAPH[i % 8] + 8;<br>    float lambda = t - i;<br>    float current_y = lambda * next_y + (1.0 - lambda) * old_y;<br>    return current_y;<br>}</pre><p>For the record, <strong><em>sqrt</em></strong> is the square root function and <strong><em>pow(flot a , float b) </em></strong>returns <em>a</em> to the power <em>b. </em>These two functions exist by default in processing just as the <strong><em>sin</em></strong> function I’ve used before.</p><h4>And Finally We’re Done!</h4><p>Here’s the final code, the one I’ve used to produce the animation I showed you in the beginning:</p><pre>final float[] GRAPH = {0.0, 0.0, 2.0, -5.0, 0.0, 0.0, -0.5, -0.3};<br>final int UNIT_SPACE = 30;<br>final int BEGIN_HEART = 8;<br>final int END_HEART = 12;<br><br>float time = 0.0;<br><br>void setup() {<br>    size(640, 480);<br>    draw_screen();<br>}<br><br>void draw() {<br>    for (int anim_step = 0; anim_step &lt; 10; ++anim_step) {<br>        draw_graph();<br><br>        time += 0.01;<br>        if (floor(time) * UNIT_SPACE &gt;= width) {<br>            time = 0.0;<br>            draw_screen();<br>        }<br>    }<br>}<br><br>void draw_graph() {<br>    float old_y = computeY(time - 0.1);<br>    float new_y = computeY(time);<br><br>    glowy_line((time - 0.1) * UNIT_SPACE, old_y * UNIT_SPACE, time * UNIT_SPACE, new_y * UNIT_SPACE);<br>}<br><br>void glowy_line(float x1, float y1, float x2, float y2) {<br>    for (int layer = 1; layer &lt; 4; layer++) {<br>        stroke(20, 200, 20, 50 / (layer * layer));<br>        strokeWeight(3 * layer);<br><br>        line(x1, y1, x2, y2);<br>    }<br>}<br><br>float computeY(float t) {<br>    int i = int(t);<br><br>    float scale = 2.0;<br>    if (i &gt;= BEGIN_HEART &amp;&amp; i &lt;= END_HEART) {<br>        float x = (t - 2 * width / 160 - 2.3) / scale;<br><br>        float x2 = x * x;<br>        float term1 = 0.5 * sqrt(max(0, pow(x2, 2.0 / 3.0) - 4.0 * x2 + 4.0)) * sin(50.0 * x);<br>        float term2 = 0.5 * pow(x2, 1.0 / 3.0);<br>        float y = -scale * (term1 + term2) + 8;<br><br>        return y;<br>    }<br><br>    float next_y = GRAPH[(i + 1) % 8] + 8;<br>    float old_y = GRAPH[i % 8] + 8;<br>    float lambda = t - i;<br>    float current_y = lambda * next_y + (1.0 - lambda) * old_y;<br>    return current_y;<br>}<br><br>void draw_screen() {<br>    background(30);<br>    stroke(15, 45, 13);<br>    strokeWeight(2);<br>    for (int i = 1; i &lt; 50; i++) {<br>        line(0, i * UNIT_SPACE, width, i * UNIT_SPACE);<br>        line(i * UNIT_SPACE, 0, i * UNIT_SPACE, height);<br>    }<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*1v-ap_a8wPhw89-_Z-D0Tg.gif" /></figure><p>If you’ve made it to the bottom, you have my sincere gratitude. I hope you enjoyed this little tutorial. Although there are a lot of things that could have been done better (give me your suggestions in the comments), I can say that I am satisfied with the end result. I am planning to post about more interesting works in the near future.</p><p>Ciao.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=366f92eeb485" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>