<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Lautaro Lobo</title>
    <description>The latest articles on Forem by Lautaro Lobo (@lautarolobo).</description>
    <link>https://forem.com/lautarolobo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F164705%2Fedd5cab4-cb27-40f0-91a3-28e5f6666470.jpg</url>
      <title>Forem: Lautaro Lobo</title>
      <link>https://forem.com/lautarolobo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/lautarolobo"/>
    <language>en</language>
    <item>
      <title>How to Install GCC on Windows with w64devkit</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Mon, 16 Feb 2026 16:18:09 +0000</pubDate>
      <link>https://forem.com/lautarolobo/how-to-install-gcc-on-windows-with-w64devkit-m14</link>
      <guid>https://forem.com/lautarolobo/how-to-install-gcc-on-windows-with-w64devkit-m14</guid>
      <description>&lt;p&gt;In this post, I’ll go over the process of installing &lt;code&gt;w64devkit&lt;/code&gt;, launching its pre-configured environment, and using &lt;code&gt;gcc&lt;/code&gt; to compile and run your C programs with some basic flags. Let’s get started!&lt;/p&gt;

&lt;h3&gt;
  
  
  Installing w64devkit
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;w64devkit&lt;/code&gt; provides an environment to run &lt;a href="https://en.wikipedia.org/wiki/GNU_C_Compiler" rel="noopener noreferrer"&gt;GCC&lt;/a&gt; without the hassle of complex installations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Download &lt;code&gt;w64devkit&lt;/code&gt; from the &lt;a href="https://github.com/skeeto/w64devkit/releases" rel="noopener noreferrer"&gt;official GitHub releases page&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Look for the most recent release and download the &lt;code&gt;.zip&lt;/code&gt; archive. This archive contains everything you need.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You might see &lt;code&gt;.exe&lt;/code&gt; installers, but for portability and simplicity, use the &lt;code&gt;.zip&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Next, extract all the contents of the downloaded &lt;code&gt;.zip&lt;/code&gt; file into your chosen folder (could be Downloads, Documents, a new folder you create…).&lt;/p&gt;

&lt;p&gt;That’s it! There’s no further setup or complex installation routines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Opening Your Local Development Environment
&lt;/h3&gt;

&lt;p&gt;With &lt;code&gt;w64devkit&lt;/code&gt; extracted, you now have a self-contained environment ready to use.&lt;/p&gt;

&lt;p&gt;Locate &lt;code&gt;w64devkit.exe&lt;/code&gt; within the folder where you extracted &lt;code&gt;w64devkit&lt;/code&gt; (e.g., &lt;code&gt;C:\w64devkit\w64devkit.exe&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;Double-click on &lt;code&gt;w64devkit.exe&lt;/code&gt;. This will open a pre-configured terminal window. This terminal is a &lt;a href="https://en.wikipedia.org/wiki/Mingw-w64" rel="noopener noreferrer"&gt;MinGW64&lt;/a&gt; shell.&lt;/p&gt;

&lt;p&gt;Once the &lt;code&gt;w64devkit&lt;/code&gt; terminal is open, you’ll want to navigate to the directory location where your C source files are. Use the standard &lt;code&gt;cd&lt;/code&gt; (change directory) command. For example, if your C project is in &lt;code&gt;C:\Users\YourUser\Documents\MyCProject&lt;/code&gt;, you would type:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd /c/Users/YourUser/Documents/MyCProject
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to use forward slashes (&lt;code&gt;/&lt;/code&gt;) for paths, as usual in Unix-based shells.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compiling and Running Your C Program with GCC
&lt;/h3&gt;

&lt;p&gt;Once your environment is ready and you’re in your project directory, the final step is to compile and run your C code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;gcc&lt;/code&gt; is the workhorse for compiling C (and C++) code. Its primary job is to take your source code files (&lt;code&gt;.c&lt;/code&gt; or &lt;code&gt;.cpp&lt;/code&gt;) and turn them into an executable program.&lt;/p&gt;

&lt;p&gt;For a simple program, you might use a command like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc main.c -o main_executable
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, &lt;code&gt;main.c&lt;/code&gt; is your source file, and &lt;code&gt;-o main_executable&lt;/code&gt; tells &lt;code&gt;gcc&lt;/code&gt; to name the resulting executable &lt;code&gt;main_executable.exe&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Understanding GCC Flags
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;gcc&lt;/code&gt; comes with a lot of flags to help catch errors at compilation time and enforce good practices. Here are some of the most common:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-Wall&lt;/code&gt;&lt;/strong&gt; : This flag stands for “Warning all.” It enables a comprehensive set of warning messages that help you catch potential issues. These aren’t strict errors, but they often point to logical flaws or common programming mistakes that could lead to bugs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-Wextra&lt;/code&gt;&lt;/strong&gt; : Going a step beyond &lt;code&gt;-Wall&lt;/code&gt;, this flag enables even more warnings, often related to niche but still important programming pitfalls. Combining &lt;code&gt;-Wall&lt;/code&gt; and &lt;code&gt;-Wextra&lt;/code&gt; provides excellent coverage.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-Werror&lt;/code&gt;&lt;/strong&gt; : This is a critical flag for professional development. It treats all compiler warnings as errors. This means if your code triggers even a single warning, the compilation process will fail. This will force you to address every potential issue, leading to more robust and reliable software.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-std=c99&lt;/code&gt;&lt;/strong&gt; : This flag specifies the &lt;a href="https://www.geeksforgeeks.org/c/c-programming-language-standard/" rel="noopener noreferrer"&gt;C programming language standard&lt;/a&gt; to use. &lt;code&gt;c99&lt;/code&gt; refers to the 1999 ISO C standard, which is widely adopted and provides a good balance of features and compatibility. Using a specific standard ensures your code is portable and behaves consistently across different compilers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;-o &amp;lt;output_executable&amp;gt;&lt;/code&gt;&lt;/strong&gt; : As mentioned before, this flag allows you to name the output executable file explicitly. If omitted, &lt;code&gt;gcc&lt;/code&gt; will default to &lt;code&gt;a.exe&lt;/code&gt; (or &lt;code&gt;a.out&lt;/code&gt; on Linux/macOS).&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Putting It All Together
&lt;/h3&gt;

&lt;p&gt;For a typical project involving different source files, like a &lt;a href="https://lautarolobo.xyz/blog/find-peak-of-array-c" rel="noopener noreferrer"&gt;&lt;code&gt;peak_finder&lt;/code&gt; algorithm&lt;/a&gt;, combining these flags gives you a powerful compilation command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gcc -Wall -Werror -Wextra -std=c99 main.c array_helpers.c -o peak_finder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command compiles &lt;code&gt;main.c&lt;/code&gt; and &lt;code&gt;array_helpers.c&lt;/code&gt; together, applies all the specified warnings (treating them as errors), adheres to the C99 standard, and creates an executable named &lt;code&gt;peak_finder.exe&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Running the Program
&lt;/h3&gt;

&lt;p&gt;Once &lt;code&gt;gcc&lt;/code&gt; compiles your program, you can run it from the &lt;code&gt;w64devkit&lt;/code&gt; terminal.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To run your executable, type &lt;code&gt;./&lt;/code&gt; followed by the executable’s name. The &lt;code&gt;./&lt;/code&gt; prefix is important because it tells the shell to look for the executable in the current directory.&lt;/li&gt;
&lt;li&gt;If your program expects command-line arguments, you can pass them directly:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./peak_finder test_array.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command would execute &lt;code&gt;peak_finder.exe&lt;/code&gt; and pass &lt;code&gt;test_array.txt&lt;/code&gt; as an argument, which your C program can then process.&lt;/p&gt;




&lt;p&gt;You can check some of my other posts in my personal blog; &lt;a href="https://lautarolobo.xyz/" rel="noopener noreferrer"&gt;lautarolobo.xyz&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this post helped you on your development journey. See you in the next post!&lt;/p&gt;

</description>
      <category>compilers</category>
      <category>c</category>
      <category>windows</category>
    </item>
    <item>
      <title>Some Notes I Took on Software Architecture</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Fri, 10 Oct 2025 00:00:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/some-notes-i-took-on-software-architecture-1n78</link>
      <guid>https://forem.com/lautarolobo/some-notes-i-took-on-software-architecture-1n78</guid>
      <description>&lt;p&gt;I watched a few videos, read some stuff online about Software Architecture, and took some notes in the process.&lt;/p&gt;

&lt;p&gt;I hope these make sense.&lt;/p&gt;




&lt;p&gt;First of all, you want to &lt;strong&gt;analyze:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the functional requirements&lt;/li&gt;
&lt;li&gt;the non-functional requirements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Functional requirements are the “what”, often captured in use cases, user stories, or a detailed list of features.&lt;br&gt;&lt;br&gt;
Non-functional requirements are the “how”. Like performance, reliability, security, maintainability, etc. You can look into ISO/IEC 25010 as a reference.&lt;/p&gt;

&lt;p&gt;When planning a software architecture, you want to put structure &lt;em&gt;over&lt;/em&gt; implementation. You need to take into consideration the budget, along with any restrictions you may have, like regulatory constraints (like &lt;a href="https://www.hhs.gov/hipaa/for-professionals/security/laws-regulations/index.html" rel="noopener noreferrer"&gt;HIPAA&lt;/a&gt;), industry standards, talent pool (the team you have), etc.&lt;/p&gt;

&lt;p&gt;Try to spot any conflicting requirements that could be problematic along the way. Catching these earlier will save you tons of time and overhead. If something needs to be rethought, this is the time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prioritize&lt;/strong&gt; the NFRs so you have a better understanding of the core business, what drives the solution, and the necessity behind it. This will make it clearer where you should focus and put more effort into, and what improvements could be added in later stages.&lt;/p&gt;

&lt;p&gt;With all this in mind, try to imagine how this system could grow and evolve in time.&lt;/p&gt;

&lt;p&gt;Next, you have to &lt;strong&gt;choose one&lt;/strong&gt;.&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-patterns.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-patterns.webp" alt="different software architecture patterns" width="800" height="484"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;And remember:&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-patterns-key-points.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-patterns-key-points.webp" alt="software architecture patterns key points" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;Do not forget about these three core concepts:&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-core-concepts.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-core-concepts.webp" alt="software architecture core concepts" width="800" height="277"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;You should always keep these in mind.&lt;/p&gt;

&lt;p&gt;It has to work, so it &lt;em&gt;needs&lt;/em&gt; to be &lt;strong&gt;performant.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It has to be &lt;strong&gt;scalable&lt;/strong&gt; , because you never know how big you can get.&lt;/p&gt;

&lt;p&gt;Focusing on &lt;strong&gt;maintainability&lt;/strong&gt; is also crucial. Maintainable systems are easier to understand, modify, and fix, benefiting both the dev experience and the client. Instead of creating something that only a few people can handle, you will build a system that is a joy to work with and a gift to those who use it.&lt;/p&gt;




&lt;p&gt;When you have a shared state between servers (which happens with a microservices architecture, or any other type of &lt;a href="https://www.baeldung.com/cs/distributed-systems-guide" rel="noopener noreferrer"&gt;distributed system&lt;/a&gt;), the CAP theorem applies.&lt;/p&gt;

&lt;p&gt;CAP stands for Consistency, Availability, and Partition Tolerance. The CAP theorem states that Partition Tolerance is required for distributed systems, so you can only choose one of the other two.&lt;/p&gt;

&lt;p&gt;The trade-offs usually are:&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;strong&gt;Consistency &amp;gt; Availability&lt;/strong&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;Often used for banking or in relational databases, when you block new writes to the DB, causing the system to go temporarily unavailable.&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;strong&gt;Availability &amp;gt; Consistency&lt;/strong&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;When writes happen at the same time, consistency may be lost. You need to implement a sorting or prioritization engine. This is often picked for social media or e-commerce apps.&lt;/p&gt;

&lt;p&gt;I believe the most used one is A+P (Availability + Partition tolerance).&lt;/p&gt;

&lt;p&gt;You need to manage these trade-offs gracefully, with some strategy to resolve inconsistencies quickly.&lt;/p&gt;




&lt;p&gt;With scaling comes latency and slower response times; that’s where &lt;strong&gt;cache&lt;/strong&gt; comes into play.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;cache&lt;/strong&gt; is a component that stores data so that requests that need the same data will be served faster.&lt;/p&gt;

&lt;p&gt;Some examples are in-memory cache, &lt;a href="https://www.cloudflare.com/learning/cdn/what-is-a-cdn/" rel="noopener noreferrer"&gt;CDNs&lt;/a&gt;, &lt;a href="https://redis.io/" rel="noopener noreferrer"&gt;Redis&lt;/a&gt;, &lt;a href="https://memcached.org/" rel="noopener noreferrer"&gt;memcached&lt;/a&gt;, etc.&lt;/p&gt;

&lt;p&gt;Every layer/component of an architecture can, and should, have a cache. But you can add this in later stages, as an optimization.&lt;/p&gt;




&lt;p&gt;And finally:&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-security.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fsoftware-architecture-security.webp" alt="security key points on software architecture" width="755" height="673"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;I think that’s pretty much it.&lt;/p&gt;




&lt;p&gt;See also:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;IBM’s &lt;a href="https://www.ibm.com/think/topics/microservices" rel="noopener noreferrer"&gt;Microservices Overview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.youtube.com/playlist?list=PL4JxLacgYgqTgS8qQPC17fM-NWMTr5GW6" rel="noopener noreferrer"&gt;Software Architecture and Design&lt;/a&gt; YouTube videos by Christian from &lt;a href="https://www.youtube.com/@ADevStory" rel="noopener noreferrer"&gt;@ADevStory&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS’s &lt;a href="https://docs.aws.amazon.com/wellarchitected/latest/framework/welcome.html" rel="noopener noreferrer"&gt;Well-Architected Framework&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>architecture</category>
      <category>microservices</category>
    </item>
    <item>
      <title>The Manhattan Tourist Problem</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Mon, 10 Feb 2025 00:00:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/the-manhattan-tourist-problem-ln5</link>
      <guid>https://forem.com/lautarolobo/the-manhattan-tourist-problem-ln5</guid>
      <description>&lt;p&gt;Hi there!&lt;/p&gt;

&lt;p&gt;I’ve been looking into some algorithmic problems lately. The Manhattan Tourist Problem is one of the most emblematic problems you could find online.&lt;/p&gt;

&lt;p&gt;Want to practice some Dynamic Programming? Let’s dive straight into it!&lt;/p&gt;

&lt;h3&gt;
  
  
  Statement of the Problem
&lt;/h3&gt;

&lt;p&gt;You and your family are taking a tour through downtown Manhattan. The van will leave you at the northwesternmost corner of the city, and another van will be waiting to pick you up at the southeasternmost corner. But here’s the thing: you can only move either to the south or to the east. You and your family are starting to develop a plan to visit as many attractions as possible, how would you do it?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Input:&lt;/strong&gt; A weighted grid G of size n*m.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Output:&lt;/strong&gt; A longest path in G from (0,0) to (n,m).&lt;/p&gt;

&lt;p&gt;Here’s an illustrated example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-example.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-example.webp" alt="Manhattan Tourist Problem example" width="500" height="327"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The weight (we could also call it length) of a path from the source to the sink is the overall number of attractions in the path or the sum of the weights of its edges.&lt;/p&gt;

&lt;p&gt;An important thing to remember is that you can’t go upward (to the north) or backward (to the west).&lt;/p&gt;

&lt;p&gt;A naive approach would be to calculate all the possible paths in the grid and select the longest path between them all. But this algorithm would be slow even with mid-sized grids, so it’s not an option.&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-meme.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-meme.webp" alt="A brute force algorithm was never an option" width="512" height="288"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;A different approach would be to use a greedy algorithm. But &lt;a href="https://brilliant.org/wiki/greedy-algorithm/" rel="noopener noreferrer"&gt;greedy algorithms only consider locally optimal choices&lt;/a&gt; at each step, which could lead to missing out on a globally optimal path. So a greedy algorithm is out of the equation.&lt;/p&gt;

&lt;p&gt;So let’s begin our analysis to come up with a &lt;a href="https://www.geeksforgeeks.org/dynamic-programming/" rel="noopener noreferrer"&gt;Dynamic Programming&lt;/a&gt; solution.&lt;/p&gt;
&lt;h3&gt;
  
  
  Finding a Dynamic Programming Solution
&lt;/h3&gt;

&lt;p&gt;At first glance, we can see that to solve the general problem, we need to find the solution to many sub-problems. Precisely to n*m sub-problems: the longest path to (i,j) with 0 &amp;lt;= i &amp;lt;= n and 0 &amp;lt;= j &amp;lt;= m.&lt;/p&gt;

&lt;p&gt;So instead of solving the Manhattan Tourist problem directly, we will solve the general problem, which is the longest path from the source vertex to an arbitrary sink vertex.&lt;/p&gt;

&lt;p&gt;First, let’s define our set of vertex S, and S(i,j) as the vertex in the i-th row and j-th column.&lt;/p&gt;

&lt;p&gt;Finding S(0,j) is trivial, you and your family can’t go in another direction than to the east. The weight of the path S(0,j) is the sum of weights of the first j city blocks. The same happens with S(i,0) since you can only move south.&lt;/p&gt;

&lt;p&gt;Having this in mind we can compute S(1,1), you can arrive at S(1,1) from S(0,1) or S(1,0). The weight of each of these paths is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S(0,1) + weight of the edge (block) between (0,1) and (1,1)&lt;/li&gt;
&lt;li&gt;S(1,0) + weight of the edge (block) between (1,0) and (1,1)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The longest path is the larger of the above values. In the sample grid shown before, that value would be 4 (1+3). We’ve found the longest path from (0,0) to (1,1).&lt;/p&gt;

&lt;p&gt;The same logic applies to S(2,1), S(3,1), etc. We can use this logic to compute S(1,2), S(1,3), etc.&lt;/p&gt;

&lt;p&gt;In general, having the first row and the entire S(-,j) column allows you to compute S(-,j+1). Knowing that to arrive at S(i,j) we need to go through S(i-1,j) or through S(i,j-1) leads to the following conclusion:&lt;/p&gt;

&lt;center&gt;&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-recurrence.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2Fmanhattan-tourist-problem-recurrence.webp" alt="S(i,j) = max(S(i-1,j) + weight of the edge between (i-1,j) and (i,j), S(i,j-1) + weight of the edge between (i,j-1) and (i,j))" width="512" height="106"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/center&gt;

&lt;p&gt;This recurrence allows you to compute every cell of S in a single sweep of the grid.&lt;/p&gt;

&lt;p&gt;The following algorithm written in pseudocode implements this procedure.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FUNCTION ManhattanTourist(n, m, down, right)  
// n, m: dimensions of the grid (number of rows and columns)  
// down[i][j]: weight of the edge going down from cell (i, j)  
// right[i][j]: weight of the edge going right from cell (i, j)  
// S[i][j]: maximum path sum to reach cell (i, j)

// Base case: starting cell
S[0][0] = 0

// Initialize first column (moving only down)
FOR i = 1 TO n
  S[i][0] = S[i-1][0] + down[i][0]
ENDFOR

// Initialize first row (moving only right)
FOR j = 1 TO m
  S[0][j] = S[0][j-1] + right[0][j]
ENDFOR

// Fill the rest of the table using dynamic programming
FOR i = 1 TO n
  FOR j = 1 TO m
    IF S[i-1][j] + down[i][j] &amp;lt; S[i][j-1] + right[i][j] THEN
      S[i][j] = S[i][j-1] + right[i][j]
    ELSE
      S[i][j] = S[i-1][j] + down[i][j]
    ENDIF  
  ENDFOR  
ENDFOR

RETURN S[n][m]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can implement this pseudocode in any programming language of your preference.&lt;/p&gt;




&lt;p&gt;I hope you have found the problem interesting, and it helped you get better at Dynamic Programming.&lt;/p&gt;

&lt;p&gt;In case you want to dive deeper, try answering the following questions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How would you change the algorithm if the source vertex differs from (0,0)?&lt;/li&gt;
&lt;li&gt;What would happen if downtown Manhattan had diagonal streets (which actually has)? Should you change the algorithm or would still give the correct answer?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;See ya in my next blog posts!&lt;/p&gt;

&lt;h3&gt;
  
  
  Related Content
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=wmIMeyWDZI0" rel="noopener noreferrer"&gt;Manhattan Tourist Problem Lecture&lt;/a&gt; by &lt;a href="https://en.wikipedia.org/wiki/Pavel_A._Pevzner" rel="noopener noreferrer"&gt;Pavel Pezner&lt;/a&gt;&lt;br&gt;&lt;br&gt;
&lt;a href="https://csbio.unc.edu/mcmillan/Comp555S16/Lecture12.html#Manhattan-Tourist-Problem-(MTP)" rel="noopener noreferrer"&gt;Lecture&lt;/a&gt; from a BioAlgorithms course dictated by &lt;a href="https://scholar.google.com/citations?user=z6cJOmMAAAAJ" rel="noopener noreferrer"&gt;Leonard McMillan&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Cover image generated using &lt;a href="https://labs.google/fx/tools/image-fx" rel="noopener noreferrer"&gt;ImageFX&lt;/a&gt; from &lt;a href="https://labs.google/" rel="noopener noreferrer"&gt;Google Labs&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>algorithms</category>
      <category>graphs</category>
      <category>computerscience</category>
      <category>dynamicprogramming</category>
    </item>
    <item>
      <title>Use JavaScript and HTML5 to Code a Fractal Tree</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Thu, 16 Apr 2020 15:40:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/use-javascript-and-html5-to-code-a-fractal-tree-2n69</link>
      <guid>https://forem.com/lautarolobo/use-javascript-and-html5-to-code-a-fractal-tree-2n69</guid>
      <description>&lt;p&gt;Fractals, those enigmatic figures that are everywhere, but can not be seen by the untrained eye. Today we’ll draw one of the best-known Fractals, using only Vainilla JS and the HTML5’s Canvas API. Let’s code!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Fractal Tree?
&lt;/h2&gt;

&lt;p&gt;To define a Fractal Tree first we must know the definition of Fractal, of course.&lt;/p&gt;

&lt;p&gt;Fractals are never-ending patterns created by repeating mathematical equations, which on any scale, on any level of zoom, look roughly the same. In other words, a geometric object which’s basic structure, rough or fragmented, repites itself in different scales.&lt;/p&gt;

&lt;p&gt;So if we split a Fractal, we’ll see a reduced-size copy of the whole.&lt;/p&gt;

&lt;p&gt;Benoit Mandelbrot, which coined the term Fractal in 1975, said:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;A Fractal is a shape made of parts similar to the whole in some way.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Pretty clear, right?&lt;/p&gt;

&lt;p&gt;Here are some examples:&lt;/p&gt;

&lt;center&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Ff%2Ffd%2FVon_Koch_curve.gif" alt="Animated Von Koch Curve" width="300" height="312"&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;td&gt;&lt;center&gt;Von Koch Curve&lt;/center&gt;&lt;/td&gt;&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F2%2F28%2FAnimated_Sierpinski_carpet.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F2%2F28%2FAnimated_Sierpinski_carpet.gif" alt="Animated Sierpinski Carpet" width="750" height="750"&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;&lt;td&gt;&lt;center&gt;Sierpinski Carpet&lt;/center&gt;&lt;/td&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/center&gt;

&lt;p&gt;Now, what is a Fractal Tree?&lt;/p&gt;

&lt;p&gt;Imagine a branch, and branches coming out of it, and then two branches coming out of each branch, and so on… that’s what a Fractal Tree looks like.&lt;/p&gt;

&lt;p&gt;Its form comes from the Sierpinski triangle (or Sierpinski gasket).&lt;/p&gt;

&lt;p&gt;As you can see, one becomes the other when changing the angle between branches:&lt;/p&gt;

&lt;center&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Fa%2Fa9%2FFractal_tree.gif" alt="From Sierpinski Triangle to Fractal Tree" width="400" height="400"&gt;
&lt;/center&gt;

&lt;p&gt;Today we’ll end up with a figure similar to the final form of that gif.&lt;/p&gt;

&lt;h2&gt;
  
  
  Writing the Fractal Tree in Vanilla JS
&lt;/h2&gt;

&lt;p&gt;First of all, here’s the final product (you can tweak it along the way):&lt;/p&gt;

&lt;center&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2FfractalTree-39b48caf.webp" alt="Final Fractal Tree" width="800" height="400"&gt;
&lt;/center&gt;

&lt;p&gt;Now let’s draw that, step by step.&lt;/p&gt;

&lt;p&gt;First of all, we initialize our index.html file, with a canvas of any reasonable dimensions, and a script tag where all our JS code will be.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we start writing our JavaScript.&lt;/p&gt;

&lt;p&gt;We initialize our canvas element on JS, by accessing it through the myCanvas variable and creating the 2D rendering context with the ctx (context) variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my_canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So yeah, the getContext method adds properties and methods that allow you to draw, in this case, in 2D.&lt;/p&gt;

&lt;p&gt;Now it’s time to think. How can we define the algorithm to draw a Fractal tree? Hm… 🤔&lt;/p&gt;

&lt;p&gt;Let’s see, we know that the branches keep becoming smaller. And that each branch ends with two branches coming out of it, one to the left and one to the right.&lt;/p&gt;

&lt;p&gt;In other words, when a branch is long enough, attach two smaller branches to it. Repeat.&lt;/p&gt;

&lt;p&gt;It kinda sounds like we shall use some recursive statement somewhere, isn’t it?&lt;/p&gt;

&lt;p&gt;Back to the code, we now define our function &lt;code&gt;fractalTree&lt;/code&gt; that should take at least four arguments: the X and Y coordinates where the branch starts, the length of its branch and its angle.&lt;/p&gt;

&lt;p&gt;Inside our function, we begin the drawing with the beginPath() method, and then save the state of the canvas with the save() method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my_canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;        
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The beginPath method is often used when you start a new line or figure that has a fixed style, like the same color along the entire line, or the same width. The save method just saves the entire state of the canvas by pushing the current state onto a stack.&lt;/p&gt;

&lt;p&gt;Now we’ll draw our Fractal Tree, by drawing a line (branch), rotating the canvas and drawing the next branch, and so on. It goes like this (I’ll explain each method below the code sample):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my_canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lineTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So we first add three methods, translate, rotate and moveTo, which ‘moves’ the canvas, its origin and our ‘pencil’ so we can draw the branch in our desired angle. It’s like we are drawing a branch, then centering this branch (by moving the hole canvas) and then drawing a new brand from the end of our previous branch.&lt;/p&gt;

&lt;p&gt;The last two methods before the if statement are lineTo and stroke, the first adds a straight line to the current path and the second one renders it, you can think of it like this: lineTo gives the order and stroke executes it.&lt;/p&gt;

&lt;p&gt;Now we have an if statement that tells when to stop the recursion, when to stop drawing. The restore method, as stated in the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/restore" rel="noopener noreferrer"&gt;MDN Docs&lt;/a&gt;, “restores the most recently saved canvas state by popping the top entry in the drawing state stack”.&lt;/p&gt;

&lt;p&gt;After the if statement we have the recursive call, and another call to the restore method. And then a call to the function that we just finished.&lt;/p&gt;

&lt;p&gt;Now run the code in your browser. You’ll see, finally, a Fractal Tree!&lt;/p&gt;

&lt;center&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flautarolobo.xyz%2Fimages%2FfractalTree1-4748f669.webp" alt="Fractal Tree First Iteration" width="800" height="400"&gt;
&lt;/center&gt;

&lt;p&gt;Awesome, right? Now let’s make it even better.&lt;/p&gt;

&lt;p&gt;We’ll add a new parameter to our draw function, branchWidth, to make our Fractal Tree more realistic.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my_canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lineWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lineTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in every iteration, we are making each branch thinner. I’ve also changed the angle paramater in the recursive call, to make a more “open” tree.&lt;/p&gt;

&lt;p&gt;Now, let’s add some color! And shadows, why not.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;html&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"en"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;head&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;charset=&lt;/span&gt;&lt;span class="s"&gt;"UTF-8"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/head&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;canvas&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"my_canvas"&lt;/span&gt; &lt;span class="na"&gt;width=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;height=&lt;/span&gt;&lt;span class="s"&gt;"800"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/canvas&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;my_canvas&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;ctx&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;myCanvas&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;2d&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;lineWidth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;beginPath&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;strokeStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fillStyle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;green&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;startX&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;startY&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;rotate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;angle&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;PI&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;moveTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;lineTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shadowBlur&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;shadowColor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;rgba(0,0,0,0.8)&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;len&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;angle&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;branchWidth&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nx"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;restore&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;600&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;       
    &lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both color methods are self-explanatory (strokeStyle and fillStyle). Also the shadow ones, shadowBlur and shadowColor.&lt;/p&gt;

&lt;p&gt;And that’s it! Save the file and open it with your browser to see the final product.&lt;/p&gt;

&lt;p&gt;Now I encourage you to play with the code! Change the shadowColor, the fillStyle, make a shorter or longer Fractal Tree, change the angle or try to add leaves, that should be challenging 😉&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond the Fractal Tree
&lt;/h2&gt;

&lt;p&gt;As I showed you at the beginning of this post, there are different Fractals. Ain’t gonna be easy to make all them with the Canvas API, but it should be possible. I made some of those in the C programming language, and I’ve also played around with p5.js.&lt;/p&gt;

&lt;p&gt;p5.js is an Open Source JavaScript library made by artists, for artists, based in the &lt;a href="https://processing.org/" rel="noopener noreferrer"&gt;Processing language&lt;/a&gt;. You can draw, or animate, anything imaginable. If you are interested in making art with code, it’s a must. They have a great &lt;em&gt;get-started&lt;/em&gt; page that you can check out &lt;a href="https://p5js.org/get-started/" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I’ve also found recently a website that makes a Fractal Tree in JS using L-Systems. Really cool. Take a look into &lt;a href="https://thefractal.zone/" rel="noopener noreferrer"&gt;The Fractal Zone&lt;/a&gt;! Code is &lt;a href="https://github.com/Rizz0S/the-fractal-zone" rel="noopener noreferrer"&gt;here&lt;/a&gt; 🤓&lt;/p&gt;




&lt;p&gt;Well, that’s it for now! Thanks for reading, comment any questions and see you in my next post! 🧔&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Cover by &lt;a href="https://pixabay.com/users/socialtrendspr0-1358346/" rel="noopener noreferrer"&gt;socialtrendspr0&lt;/a&gt; from &lt;a href="https://pixabay.com" rel="noopener noreferrer"&gt;Pixabay&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>javascript</category>
      <category>fractals</category>
      <category>html</category>
      <category>beginners</category>
    </item>
    <item>
      <title>February of Fortran</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Sat, 29 Feb 2020 18:07:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/february-of-fortran-29k7</link>
      <guid>https://forem.com/lautarolobo/february-of-fortran-29k7</guid>
      <description>&lt;h2&gt;
  
  
  What is Fortran?
&lt;/h2&gt;

&lt;p&gt;Fortran is a 63 y.o. programming language developed by IBM for scientific and engineering applications. Its name is an acronym from &lt;strong&gt;FORmula TRANslation&lt;/strong&gt; , and still being in use for that purpose.&lt;/p&gt;

&lt;p&gt;It’s a general-purpose programming language, but best suited for computationally intensive areas like computational physics, computational chemistry, high-performance computing and so.&lt;/p&gt;

&lt;p&gt;Many programming languages were based on or influenced by, Fortran. And it has received many updates among the years, last one in 2018.&lt;/p&gt;

&lt;p&gt;It was originally conceived as FORTRAN, all uppercase, in 1956. 5 updates later, in the 90s, it became Fortran. The update also added many other changes like free-form source, inline comments, modules, recursive procedures, dynamic memory allocation and many other changes that make the language &lt;em&gt;modern-er&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to Compile and Run a Fortran Program
&lt;/h2&gt;

&lt;p&gt;Let’s say you want to compile and run your first Fortran program, like this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight fortran"&gt;&lt;code&gt;&lt;span class="k"&gt;program&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;HelloWorld&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="k"&gt;implicit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;none&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"hello world"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="k"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"hello world"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="k"&gt;end&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;program&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c1"&gt;! it should return:&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;! hello world&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c1"&gt;! hello world&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Well, you should make a series of things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;a href="https://gcc.gnu.org/wiki/GFortran"&gt;gfortran&lt;/a&gt;, which is a Fortran compiler.&lt;/li&gt;
&lt;li&gt;Save your code with .f90 extension (even if you are writing in Fortran 2015, .f90 it’s the standard file extension).&lt;/li&gt;
&lt;li&gt;Compile with gfortran.&lt;/li&gt;
&lt;li&gt;Run your program as you would run any C program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And that’s how you do it!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is Fortran Used For
&lt;/h2&gt;

&lt;p&gt;Fortran is still in use in HPC (High Performace Computing). All that is mathematical chunk is probably done with Fortran. It’s widely used in scientific computing from Chemistry and Physics to Astronomy and Mathematics.&lt;/p&gt;

&lt;p&gt;I can almost hear the masses… why not Python?&lt;/p&gt;

&lt;p&gt;In fact, you can use Python in those areas. But even if Python is a better choice in many cases, you wouldn’t use it in HPC, since Fortran is &lt;em&gt;performant-er&lt;/em&gt;. It may take more time to write, but sometimes code performance means everything.&lt;/p&gt;

&lt;p&gt;You know, even that Python has evolved, wasn’t born exclusively for Physicists and Mathematicians.&lt;/p&gt;

&lt;p&gt;As I’ve read somewhere:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;At the end of the day, Physicists are writing very different programs than Computer Scientists with very different goals and concerns.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You may say that Physicists are not willing to change, or that there’s a lot of Fortran legacy code out there, but even then, Fortran keeps being the best choice for some HPC projects, or Physics calculations.&lt;/p&gt;

&lt;p&gt;But that doesn’t mean that you can only use Fortran. Other programming languages used in HPC are C and C++, both being faster than Fortran in many cases, or the somehow-new &lt;a href="https://julialang.org/"&gt;Julia&lt;/a&gt; that is &lt;a href="https://www.hpcwire.com/2020/01/14/julia-programmings-dramatic-rise-in-hpc-and-elsewhere/"&gt;slowly entering the market&lt;/a&gt;, is also faster than Fortran and it was developed by MIT exclusively for HPC and all scientific computing.&lt;/p&gt;

&lt;p&gt;If you want to see a detailed comparison between Python, C++, and Fortran on scientific computing, check out &lt;a href="http://downloads.hindawi.com/journals/sp/2014/870146.pdf"&gt;this amazing paper&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>fortran</category>
      <category>beginners</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>January of JavaScript</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Wed, 22 Jan 2020 14:01:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/january-of-javascript-3p3f</link>
      <guid>https://forem.com/lautarolobo/january-of-javascript-3p3f</guid>
      <description>&lt;p&gt;It’s January. Time to talk about JavaScript. How was it born? Why is it called like that? Is it really that popular? Let’s find out!&lt;/p&gt;

&lt;h2&gt;
  
  
  A Little Bit Of History
&lt;/h2&gt;

&lt;p&gt;JavaScript was born in December of 1995 when Netscape announced it’s rollout. The guy behind the work? Brendan Eich, a Computer Scientist working at that time in Netscape. He’s known as the father of JavaScript, because of his titanic work on the language before it’s rollout.&lt;/p&gt;

&lt;p&gt;Fun fact: JavaScript was named Mocha, then LiveScript, and finally they changed it once and for all to the name that we all know now.&lt;/p&gt;

&lt;p&gt;And why is it called ‘Java’-‘Script’? Well, quoting Brendan:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;[…] It was all within six months from May till December (1995) that it was Mocha and then LiveScript. And then in early December, Netscape and Sun did a license agreement and it became JavaScript. And the idea was to make it a complementary scripting language to go with Java, with the compiled language.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A co-marketing deal between Netscape and Sun.&lt;/p&gt;

&lt;p&gt;In fact, Oracle acquired Sun Microsystems in 2009, so “JAVASCRIPT” is a trademark of Oracle. How crazy is that?&lt;/p&gt;

&lt;p&gt;In 1997, ECMAScript was born. But what is ECMAScript? It’s a standard, a specification of a programming language, published by ECMA (European Computer Manufacturers Association) International. So JavaScript is a dialect of the ECMAScript standard.&lt;/p&gt;

&lt;p&gt;That’s right, ECMAScript &lt;em&gt;defines&lt;/em&gt; a programming language, and JavaScript &lt;em&gt;is&lt;/em&gt; the programming language.&lt;/p&gt;

&lt;p&gt;There were different versions of the standard since it first came out. Today, every modern web browser supports ECMAScript 5.1, and almost everyone supports the latest version, ECMAScript 6. Newer versions are still in the early stages of development.&lt;/p&gt;

&lt;p&gt;Are you confused yet? To make it simpler, ECMAScript is like the version, and JavaScript is the language itself.&lt;/p&gt;

&lt;p&gt;For a more-of-a-timeline of the history of JavaScript, check:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/codediodeio/the-weird-history-of-javascript-2bnb"&gt;The Weird History of JavaScript&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Weird Stuff
&lt;/h2&gt;

&lt;p&gt;When using JS, you may find some weird stuff going one, like that NaN (which stands for Not a Number) it’s a… number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// number&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And NaN it’s not NaN ¿?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that NaN is an infinite number. Wait… what?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;isFinite&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="c1"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you know what’s the weirdest part? You should expect JS to behave like this! I mean, this is all on the specs.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fencrypted-tbn0.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcRyc9EZ9yNplhUMcNiPLP-p1Qm4J3GThI5y76-Ltx6rlqOxOgCYGA%26s" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fencrypted-tbn0.gstatic.com%2Fimages%3Fq%3Dtbn%3AANd9GcRyc9EZ9yNplhUMcNiPLP-p1Qm4J3GThI5y76-Ltx6rlqOxOgCYGA%26s" width="265" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can take a look at more weird stuff here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/qjlee/do-you-know-these-weird-parts-of-javascript-48pg"&gt;Do you know these weird parts of JavaScript?&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s Next?
&lt;/h2&gt;

&lt;p&gt;As I said before, there are some newer versions of the ECMAScript standard on development. But in so early stages that we shouldn’t expect JS to change much anytime soon.&lt;/p&gt;

&lt;p&gt;After all, you can already use JS on almost anything: Videogames, AI, Back-End, Front-End, Art, Data Analytics…&lt;/p&gt;

&lt;p&gt;And many frameworks and libraries are popping up every day. &lt;a href="https://svelte.dev/" rel="noopener noreferrer"&gt;Svelte&lt;/a&gt; has changed the paradigm of website rendering. There’s this thing called &lt;a href="https://cssinjs.org/?v=v10.0.3" rel="noopener noreferrer"&gt;CSS-in-JS&lt;/a&gt;. You can even write Artificial Neural Networks with &lt;a href="https://www.tensorflow.org/js" rel="noopener noreferrer"&gt;Tensorflow.js&lt;/a&gt;, develop videogames with &lt;a href="https://github.com/BabylonJS/Babylon.js" rel="noopener noreferrer"&gt;Babylon.js&lt;/a&gt;, make art using &lt;a href="https://p5js.org/" rel="noopener noreferrer"&gt;p5.js&lt;/a&gt;, &lt;a href="https://medium.com/dailyjs/how-i-automated-my-job-with-node-js-94bf4e423017" rel="noopener noreferrer"&gt;automate stuff with NodeJS&lt;/a&gt;, &lt;a href="https://observablehq.com/@dakoop/learn-js-data" rel="noopener noreferrer"&gt;even make charts based on .csv files!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Dang that’s broad, right?&lt;/p&gt;

&lt;p&gt;So yeah, it’s a smart move to learn JavaScript. It’s used all around the web and even in non-web environments, for good or bad. In fact, from the &lt;a href="https://insights.stackoverflow.com/survey/2019" rel="noopener noreferrer"&gt;Stack Overflow Developer Survey of 2019&lt;/a&gt; we can say that it’s the most commonly used programming language. And the top Libraries and Frameworks are also JS-based.&lt;/p&gt;

&lt;p&gt;It seems like JS is staying with us for a while.&lt;/p&gt;




&lt;p&gt;Hey, thanks for reading until this far! If you are starting your journey on JavaScript, or just want to train yourself a bit, check my &lt;a href="https://lautarolobo.xyz/blog/7-days-of-js-factorial-and-average/" rel="noopener noreferrer"&gt;#7DaysJS Challenge!&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See ya!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
    <item>
      <title>#7DaysJS: Primes Until n</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Thu, 05 Dec 2019 11:16:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7daysjs-primes-until-n-c7h</link>
      <guid>https://forem.com/lautarolobo/7daysjs-primes-until-n-c7h</guid>
      <description>&lt;p&gt;Welcome to day 7 of 7 Days of JavaScript!&lt;/p&gt;

&lt;p&gt;Today, on the last day of this challenge, we will tackle a hard one.&lt;/p&gt;

&lt;p&gt;Write a function that takes a Natural number &lt;code&gt;n&lt;/code&gt;, which returns all the primes from 0 to &lt;code&gt;n&lt;/code&gt; and a string at the end with some phrase.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;primesUntil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Why the string?&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hint: you may want to use a helper function.&lt;/p&gt;

&lt;p&gt;Give it time. If you feel frustrated, go take a walk and then sit down to try it again.&lt;/p&gt;

&lt;p&gt;And then, read the solution &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-7-of-7-days-of-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>beginners</category>
    </item>
    <item>
      <title>#7DaysJS: myElement + n</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Wed, 04 Dec 2019 12:25:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7-days-of-js-myelement-n-3ohj</link>
      <guid>https://forem.com/lautarolobo/7-days-of-js-myelement-n-3ohj</guid>
      <description>&lt;p&gt;Welcome to day 6 of 7 Days of JavaScript!&lt;/p&gt;

&lt;p&gt;Let’s see, I got a nice one for today.&lt;/p&gt;

&lt;p&gt;Given an array and a number &lt;code&gt;n&lt;/code&gt;, return the array with each element summed to &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="n"&gt;sumToArray&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;])&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want, you can also return the output as a string - If that makes it easier for you, it’s OK.&lt;/p&gt;

&lt;p&gt;You can check out the solution algorithm &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-6-of-7-days-of-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>beginners</category>
    </item>
    <item>
      <title>#7DaysJS: Where is My Element</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Tue, 03 Dec 2019 20:20:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7daysjs-where-is-my-element-1gho</link>
      <guid>https://forem.com/lautarolobo/7daysjs-where-is-my-element-1gho</guid>
      <description>&lt;p&gt;Welcome to day 5 of 7 Days of JavaScript! Today we will code a classic function that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Takes two parameters: an element and an array of elements&lt;/li&gt;
&lt;li&gt;Returns the position of the element inside the array. If the element is not in the array, returns -1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Wish you luck!&lt;/p&gt;

&lt;p&gt;You can see the solution &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-5-of-7-days-of-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>beginners</category>
    </item>
    <item>
      <title>#7DaysJS: Reverse a String</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Mon, 02 Dec 2019 17:43:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7daysjs-reverse-a-string-j3l</link>
      <guid>https://forem.com/lautarolobo/7daysjs-reverse-a-string-j3l</guid>
      <description>&lt;p&gt;Welcome to day 4 of 7 Days of JavaScript!&lt;/p&gt;

&lt;p&gt;Today we will see how to reverse a string. It’s probably the most asked question ever on technical interviews.&lt;/p&gt;

&lt;p&gt;So the statement is quite simple, although the problem has an unexpected complexity when you face it for the first time: write a function that takes a string and returns the string reversed.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;reverseString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Japan&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;napaJ&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Give it a try.&lt;/p&gt;

&lt;p&gt;You can see the solutions I made &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-4-of-7-days-of-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>challenge</category>
      <category>beginners</category>
    </item>
    <item>
      <title>#7DaysJS: Read My Sign</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Sun, 01 Dec 2019 21:22:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7daysjs-read-my-sign-1b0n</link>
      <guid>https://forem.com/lautarolobo/7daysjs-read-my-sign-1b0n</guid>
      <description>&lt;p&gt;Welcome to day 3 of 7 of Days of JavaScript!&lt;/p&gt;

&lt;p&gt;Today’s challenge is to write a function that takes an array and says how many numbers are positives, how many numbers are negatives, and how many are zeros.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;,-&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="nl"&gt;zeros:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nl"&gt;positives:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nl"&gt;negatives:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; 
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Good luck!&lt;/p&gt;

&lt;p&gt;You can see the solution &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-3-of-7-days-of-js/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>challenge</category>
    </item>
    <item>
      <title>#7DaysJS: Even or Odd</title>
      <dc:creator>Lautaro Lobo</dc:creator>
      <pubDate>Sat, 30 Nov 2019 15:17:00 +0000</pubDate>
      <link>https://forem.com/lautarolobo/7-days-of-js-even-or-odd-5f2g</link>
      <guid>https://forem.com/lautarolobo/7-days-of-js-even-or-odd-5f2g</guid>
      <description>&lt;p&gt;Welcome to day 2 of 7 Days of JavaScript!&lt;/p&gt;

&lt;p&gt;Let’s begin our journey today. We need to write a function that takes an array and gives back two values: one with the sum of all the odd numbers of the array, and other with the sum of all the even numbers on the array.&lt;/p&gt;

&lt;p&gt;It can’t be that hard right?&lt;/p&gt;

&lt;p&gt;You can read the solution to today’s challenge &lt;a href="https://lautarolobo.xyz/blog/solution-to-day-2-of-7-days-of-js" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>challenge</category>
    </item>
  </channel>
</rss>
