<?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>DEV Community: spenceryonce</title>
    <description>The latest articles on DEV Community by spenceryonce (@spenceryonce).</description>
    <link>https://dev.to/spenceryonce</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%2F306503%2Fda29e4b7-e257-4eb4-b7b9-7899bd8dcab1.png</url>
      <title>DEV Community: spenceryonce</title>
      <link>https://dev.to/spenceryonce</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/spenceryonce"/>
    <language>en</language>
    <item>
      <title>Automate WEBP To PNG With A Simple .Bat File</title>
      <dc:creator>spenceryonce</dc:creator>
      <pubDate>Mon, 29 Apr 2024 07:24:53 +0000</pubDate>
      <link>https://dev.to/spenceryonce/automate-webp-to-png-with-a-simple-bat-file-2n05</link>
      <guid>https://dev.to/spenceryonce/automate-webp-to-png-with-a-simple-bat-file-2n05</guid>
      <description>&lt;h2&gt;
  
  
  Automate Your Image Conversion with a Simple Batch Script
&lt;/h2&gt;

&lt;p&gt;Managing different file formats efficiently is crucial in various development projects, from web development to organizing personal media. To streamline this task, I've developed a handy batch script that automates the conversion of WEBP images to PNG or PPM formats. This script was inspired by a discussion I came across on a GitHub Gist thread, highlighting the need for a reusable, effective solution.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inspiration Behind This Tool
&lt;/h3&gt;

&lt;p&gt;The idea for this script originated from a GitHub Gist conversation where developers shared their struggles with converting WEBP files using &lt;code&gt;dwebp.exe&lt;/code&gt;. Most solutions were temporary fixes rather than sustainable ones. Reminded of the user-friendly philosophy behind my previous project, VSGraph, I set out to craft a tool that would handle batch conversions and clean up afterward efficiently.&lt;/p&gt;

&lt;h3&gt;
  
  
  What the Script Does
&lt;/h3&gt;

&lt;p&gt;Using &lt;code&gt;dwebp.exe&lt;/code&gt; from Google's WebP toolkit, this script efficiently converts WEBP images into PNG or PPM formats and offers an option to automatically delete the original files after conversion. It is designed to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Detect and Convert Images Automatically:&lt;/strong&gt; It locates all &lt;code&gt;.webp&lt;/code&gt; files in the execution directory and converts them to the specified format.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Manage Clean-Up Effectively:&lt;/strong&gt; After conversion, it can remove the original &lt;code&gt;.webp&lt;/code&gt; files to save space and keep the directory tidy.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  How to Use the Script
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Setup
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Download &lt;code&gt;dwebp.exe&lt;/code&gt;:&lt;/strong&gt; Download this executable from Google at &lt;a href="https://developers.google.com/speed/webp/download"&gt;WebP Download&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prepare Your Script Environment:&lt;/strong&gt; Place &lt;code&gt;dwebp.exe&lt;/code&gt; in the same directory as your WEBP files or a globally accessible directory included in your system's PATH.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Using the Script
&lt;/h4&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Create the Script:&lt;/strong&gt; Write your own script using the guidelines below or download the full script from my GitHub Gist.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the Script:&lt;/strong&gt; Navigate to your image directory in the command prompt and type &lt;code&gt;convert_webp.bat&lt;/code&gt; for PNG output or &lt;code&gt;convert_webp.bat -ppm&lt;/code&gt; for PPM output.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight batchfile"&gt;&lt;code&gt;@echo &lt;span class="na"&gt;off&lt;/span&gt;
&lt;span class="nb"&gt;setlocal&lt;/span&gt;

&lt;span class="c"&gt;REM Convert all WEBP files to PNG or PPM and then delete the WEBP files&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="vm"&gt;%%f&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="o"&gt;(*&lt;/span&gt;.webp&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Converting&lt;/span&gt; &lt;span class="vm"&gt;%%f&lt;/span&gt;...
    &lt;span class="kd"&gt;dwebp&lt;/span&gt;&lt;span class="err"&gt;.exe&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="vm"&gt;%%f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="na"&gt;-o &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="vm"&gt;%%~nf&lt;/span&gt;&lt;span class="s2"&gt;.png"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;errorlevel&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Failed&lt;/span&gt; &lt;span class="kd"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;convert&lt;/span&gt; &lt;span class="vm"&gt;%%f&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;
        &lt;span class="nb"&gt;del&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="vm"&gt;%%f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Deleted&lt;/span&gt; &lt;span class="vm"&gt;%%f&lt;/span&gt;
    &lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="kd"&gt;Conversion&lt;/span&gt; &lt;span class="kd"&gt;complete&lt;/span&gt;.
&lt;span class="nb"&gt;pause&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Get the Full Script
&lt;/h3&gt;

&lt;p&gt;If you prefer not to build the script yourself or want to see the full implementation, you can find it on my GitHub Gist. Simply visit this link to view or download the complete script: &lt;a href="https://gist.github.com/spenceryonce/e849800e7d7fcbb8645431f7f8abaa81"&gt;Convert WEBP to PNG/PPM Batch Script&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  How It Works
&lt;/h3&gt;

&lt;p&gt;Like connecting nodes in VSGraph, this script uses simple loops and conditions to manage file conversions. It's designed to be accessible and easy to use, just like a visual shader graph editor.&lt;/p&gt;

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

&lt;p&gt;You tell me! This is fully open-source code and would love to see what the community does with it.&lt;/p&gt;

&lt;p&gt;If you have suggestions for improvements or additional features, or if you've found creative ways to use this tool, please share your thoughts in the comments below!&lt;/p&gt;

</description>
      <category>bat</category>
      <category>batch</category>
      <category>image</category>
      <category>tip</category>
    </item>
    <item>
      <title>VSGraph - A Visual Shader Graph Editor</title>
      <dc:creator>spenceryonce</dc:creator>
      <pubDate>Tue, 27 Feb 2024 19:14:20 +0000</pubDate>
      <link>https://dev.to/spenceryonce/vsgraph-a-visual-shader-graph-editor-3di0</link>
      <guid>https://dev.to/spenceryonce/vsgraph-a-visual-shader-graph-editor-3di0</guid>
      <description>&lt;h2&gt;
  
  
  What I've Been Building
&lt;/h2&gt;

&lt;p&gt;Over the past couple months, I've been working on a tool for creating shaders, but without writing code. It uses HTML canvas to render all the nodes, a node tree for managing the execution, and dynamically builds GLSL on the fly based on the way the nodes are connected up visually. &lt;/p&gt;

&lt;p&gt;Here's a little preview of the canvas interface so you can get an idea of what I'm talking about. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqob9h9g4a90g3kube5v1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqob9h9g4a90g3kube5v1.png" alt="vsgraph preview" width="800" height="284"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Over on the left hand side, we have the what's called the 'Graph'. This is where you will make new nodes and edit existing node connections. It supports using 'Shift + A' for showing the Add panel, and allows for zooming in an out wherever the mouse currently is with the scroll wheel for easier reading and dragging of node's edges.&lt;/p&gt;

&lt;p&gt;On the right hand ride, we have the 'Viewer' this is where all output nodes, output their data to. Shader isn't the only output node available, there is also a color, number, and historical numerical graph output nodes. Each of them outputs their respective data types neatly into the viewer. &lt;/p&gt;

&lt;p&gt;Here's a little screenshot that shows you an example of using 3 different output types at once, to visual the data being produced by your graph.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2be4p9j065earm4ql1h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fn2be4p9j065earm4ql1h.png" alt="vsgraph preview" width="800" height="282"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I went through a ton of iterations on the style and exact way the nodes connected. Here's how the nodes used to look at the beginning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozh3ofeg7xmll0snnw2o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fozh3ofeg7xmll0snnw2o.png" alt="Image description" width="800" height="432"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These then progressed onto the below photo, adding colors to denote inputs and outputs. The colors at the point were still much to harsh to read, so I keep iterating.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F697dt54athkx1dvlhsjz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F697dt54athkx1dvlhsjz.png" alt="vsgraph preview" width="800" height="261"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Figured out that the input and output nodes would look much more readable with a lighter color, so I tried that too. Now we are getting something looking quite nice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8kz9fd2do4rvzkmcpaj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8kz9fd2do4rvzkmcpaj.png" alt="vsgraph preview" width="800" height="289"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that the colors were decently readable as to not bother me, I moved on to implementing the Color output node. This one will take a vec3 node's output and display the color within the viewer for the user to inspect. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F05f1gbyvncisn61kb43y.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F05f1gbyvncisn61kb43y.png" alt="vsgraph preview" width="800" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was working quite well, so I starting adding a new type of nodes (Booleans). These were to be denoted with red node edge circles, and to go along with the theme, I made it so that all data type have their own distinct color on the node's edges so that the user doesn't have to guess which is which.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxr66v1yturj5sjw0mklj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fxr66v1yturj5sjw0mklj.png" alt="vsgraph preview" width="800" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One of the last changes I made thus far, was changing the Input and Output node colors yet once again. I really liked the new colors. Made the whole thing 10x more readable with such a simple change.  &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10n757vopoz338vk6r4j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F10n757vopoz338vk6r4j.png" alt="Image description" width="800" height="283"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Does it Work?
&lt;/h2&gt;

&lt;p&gt;In essence, each node is a simple JSON object, with some data describing it's name, inputs, outputs, an execute function that describe what operation takes place when the node should be executed (updated), and a glsl function that describes exactly what that node is translated to in GLSL. It uses a dynamically allocated id system for new nodes, so that &lt;strong&gt;VSGraphs&lt;/strong&gt; can be saved and reloaded later in app, or exported directly into glsl for use in game engines or or shadershop.dev or any other platform that uses GLSL.&lt;/p&gt;

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

&lt;p&gt;Given what we have made so far, I am working on adding 50+ node types, and restructuring the way the nodes are added from the Add menu, so that it feels more similar to Blender, but modern. &lt;/p&gt;

&lt;p&gt;I would love to hear your thoughts on how you would use this tool, and what features you would like!&lt;/p&gt;

&lt;p&gt;Please let me know in the comments!&lt;/p&gt;

</description>
      <category>shaders</category>
      <category>glsl</category>
      <category>webdev</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Understanding Perceptrons Through a Practical Web Example</title>
      <dc:creator>spenceryonce</dc:creator>
      <pubDate>Sun, 18 Feb 2024 00:47:14 +0000</pubDate>
      <link>https://dev.to/spenceryonce/understanding-perceptrons-through-a-practical-web-example-11l4</link>
      <guid>https://dev.to/spenceryonce/understanding-perceptrons-through-a-practical-web-example-11l4</guid>
      <description>&lt;p&gt;What we will be making!&lt;/p&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/spenceryonce/embed/WNmmrWG?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;




&lt;p&gt;Perceptrons are the simplest form of a neural network, designed for binary classification tasks. Invented in 1957 by Frank Rosenblatt, perceptrons paved the way for deep learning and modern artificial intelligence. This article aims to demystify perceptrons by guiding you through a practical web-based example: a decision-making tool that determines whether you should engage in various activities based on certain criteria.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a Perceptron?
&lt;/h2&gt;

&lt;p&gt;A perceptron is a type of artificial neuron that uses a linear binary classifier to decide whether an input, represented by a vector of numbers, belongs to a particular class. The decision is made by weighing the input signals, summing them up, and then passing them through a step function to produce an output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Theoretical Background
&lt;/h2&gt;

&lt;p&gt;The perceptron model is defined by three components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Inputs (x)&lt;/strong&gt;: Values received from the external environment.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weights (w)&lt;/strong&gt;: Values that signify the importance of the corresponding inputs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Threshold (θ)&lt;/strong&gt;: A value that the weighted sum of the inputs must exceed for the perceptron to fire (output a 1).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The formula used by a perceptron to make a decision is as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wb34pno3af8fjn6a3co.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wb34pno3af8fjn6a3co.png" alt="formula for perceptron" width="411" height="61"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;where (f) is the step function that returns 1 if the sum is greater than the threshold, and 0 otherwise.&lt;/p&gt;

&lt;h2&gt;
  
  
  Practical Example: Decision-Making Tool
&lt;/h2&gt;

&lt;p&gt;To illustrate how a perceptron works, we'll create a simple web tool that helps decide whether to engage in activities like going to a concert, eating out, or studying tonight. The decision is based on several weighted criteria, such as budget, weather, and personal interest.&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 1: Setting Up the HTML Structure
&lt;/h3&gt;

&lt;p&gt;We begin with a basic HTML setup that includes a form for inputting decision criteria and a script for the perceptron logic.&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&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;title&amp;gt;&lt;/span&gt;Perceptron Decision Maker&lt;span class="nt"&gt;&amp;lt;/title&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;h1&amp;gt;&lt;/span&gt;Should I Go to the Concert?&lt;span class="nt"&gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;form&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"decisionForm"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="c"&gt;&amp;lt;!-- Criteria checkboxes go here --&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;button&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"button"&lt;/span&gt; &lt;span class="na"&gt;onclick=&lt;/span&gt;&lt;span class="s"&gt;"calculateDecision()"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Decide&lt;span class="nt"&gt;&amp;lt;/button&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/form&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"result"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

    &lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class="c1"&gt;// Perceptron logic will be added here&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;h3&gt;
  
  
  Step 2: Adding CSS for Styling
&lt;/h3&gt;

&lt;p&gt;We aim for a modern look similar to NextUI's light theme, focusing on simplicity and readability.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;'Arial'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#f0f0f0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#333&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;form&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;select&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fff&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#ccc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-radius&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt; &lt;span class="m"&gt;15px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;cursor&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;pointer&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nf"&gt;#result&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;margin-top&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;#fafafa&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;border-left&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#0070f3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 3: Implementing the Perceptron Logic in JavaScript
&lt;/h3&gt;

&lt;p&gt;We use JavaScript to dynamically generate the form based on the decisions data, calculate the decision using perceptron logic, and display the result.&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decisionsData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;concert&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="s2"&gt;title&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Will I go to the concert?&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;category&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Entertainment&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;threshold&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;criteria&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="p"&gt;{&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;artistGood&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;label&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Artists is Good&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;weight&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="c1"&gt;// Additional criteria&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="c1"&gt;// Other decisions&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;calculateDecision&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decisionKey&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;decisionsData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;decisionKey&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&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;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;criteria&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;criterion&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;isChecked&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="nx"&gt;criterion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;checked&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;1&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;sum&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="nx"&gt;isChecked&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;criterion&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;weight&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;threshold&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Yes&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;No&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&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;result&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Step 4: Dynamically Generating Decisions and Categories
&lt;/h3&gt;

&lt;p&gt;To enhance user experience, we allow users to select a decision category before presenting them with specific decision criteria.&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;populateCategorySelector&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;categories&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decisionsData&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;decision&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;categorySelector&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="s1"&gt;categorySelector&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;categories&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;category&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;option&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;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;option&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;category&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nx"&gt;categorySelector&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;option&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Function to filter decisions by category&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;filterDecisionsByCategory&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;selectedCategory&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="s1"&gt;categorySelector&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;createFormsFromData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;selectedCategory&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Perceptrons, despite their simplicity, lay the groundwork for understanding more complex neural networks. By implementing a perceptron in a real-world application, we gain a practical understanding of its decision-making process. This example serves as a stepping stone to exploring more advanced concepts in machine learning and artificial intelligence.&lt;/p&gt;




&lt;p&gt;That about wraps it up! I hope you enjoyed this article and would love to add your own decisions to this library of perceptrons!&lt;/p&gt;

&lt;p&gt;Add your own decisions as a comment under this post in the correct data format and I'll add them to the library!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>perceptron</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Discovering Distances with Hanging Ropes and Catenaries: A Practical Guide</title>
      <dc:creator>spenceryonce</dc:creator>
      <pubDate>Wed, 12 Jul 2023 06:10:08 +0000</pubDate>
      <link>https://dev.to/spenceryonce/discovering-distances-with-hanging-ropes-and-catenaries-a-practical-guide-2lkb</link>
      <guid>https://dev.to/spenceryonce/discovering-distances-with-hanging-ropes-and-catenaries-a-practical-guide-2lkb</guid>
      <description>

&lt;h1&gt;
  
  
  Discovering Distances with Hanging Ropes and Catenaries: A Practical Guide
&lt;/h1&gt;

&lt;p&gt;&lt;em&gt;Author: Spencer Yonce&lt;/em&gt;&lt;br&gt;
&lt;em&gt;Publish Date: July 10, 2023&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;SEO Keywords: Catenary calculations, Hanging rope problem, Python for math, Javascript for math, Physics problem solving, Mathematical modeling, Real world math, Distance calculations, Adventures in coding, Learning Python and Javascript, Outdoor math problems&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Welcome to a fascinating journey where we mix the thrill of outdoor adventures with the magic of math and coding. You're out on a hike and you see a rope bridge hanging between two cliffs. The rope dips down in the middle, forming a beautiful curve. Here's a question: Can you figure out the distance between the cliffs knowing the length of the rope and the dip's height? &lt;/p&gt;

&lt;p&gt;Even if you're new to math and coding, this is a problem you can solve! With some basic physics, a sprinkle of geometry, and a dose of Python or Javascript code, we can unravel this mystery together. Let's dive in!&lt;/p&gt;
&lt;h2&gt;
  
  
  The Magic Curve: Understanding Catenaries
&lt;/h2&gt;

&lt;p&gt;When a rope hangs freely from two points, it forms a special curve called a catenary. A catenary curve is like the shape a necklace makes when you hold it by the ends. &lt;/p&gt;

&lt;p&gt;In math, we describe shapes using equations. For a catenary, we use this equation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.flickr.com/photos/141738109@N05/53040211564/in/dateposted-public/" title="cosh_01"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jYndTpZ2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://live.staticflickr.com/65535/53040211564_6484135d94_o.png" alt="cosh_01" width="233" height="87"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;y&lt;/code&gt; is the height of the rope at any point.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;x&lt;/code&gt; is the horizontal distance from the lowest point of the curve (the dip in the middle).&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;a&lt;/code&gt; is a number that determines the curve's shape.&lt;/li&gt;
&lt;li&gt;(\cosh) is a special function called the hyperbolic cosine.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We also know the total length of the rope is along the curve of the catenary. The equation to calculate this is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.flickr.com/photos/141738109@N05/53040211559/in/dateposted-public/" title="cosh_02"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bq2L4Q9X--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://live.staticflickr.com/65535/53040211559_a5e047022c_o.png" alt="cosh_02" width="199" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where &lt;code&gt;s&lt;/code&gt; is the length of the rope and &lt;code&gt;d&lt;/code&gt; is the distance between the cliffs we want to find.&lt;/p&gt;
&lt;h2&gt;
  
  
  Cracking the Code with Python and Javascript
&lt;/h2&gt;

&lt;p&gt;Armed with our equations, let's solve them using Python and Javascript. These are popular languages that are great for solving math problems. &lt;/p&gt;

&lt;p&gt;First, we'll look at how to solve this with Python:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;scipy.optimize&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;fsolve&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sinh&lt;/span&gt;

&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;450&lt;/span&gt;  
&lt;span class="n"&gt;y_sag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;   

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;catenary_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="nf"&gt;sinh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;equation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;vars&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;vars&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;catenary_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;y_sag&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;a_initial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
&lt;span class="n"&gt;d_initial&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;

&lt;span class="n"&gt;a_final&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d_final&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;fsolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;equation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a_initial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;d_initial&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

&lt;span class="n"&gt;d_final&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running this code, you'll find that the distance between the cliffs is approximately 136.91 feet.&lt;/p&gt;

&lt;p&gt;Now, let's do the same with Javascript. Javascript doesn't have built-in functions for &lt;code&gt;sinh&lt;/code&gt; and &lt;code&gt;fsolve&lt;/code&gt;, but we can use the math.js library:&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="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;math&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;mathjs&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;s&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;450&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;y_sag&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&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;catenary_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sinh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;d&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&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;equation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vars&lt;/span&gt;&lt;span class="p"&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;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;vars&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;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;vars&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&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="nx"&gt;s&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;catenary_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;d&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;y_sag&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&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;initial_guess&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&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;solution&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;fsolve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;equation&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;initial_guess&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;d_final&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;solution&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Running this code will give you the same result: the distance between the cliffs is about 136.91 feet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further Exploration and Practice Problems
&lt;/h2&gt;

&lt;p&gt;Congratulations on solving the hanging rope problem! If you enjoyed this, there are plenty of other real-world problems you can tackle with your new skills. Here are some ideas:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Changing rope lengths:&lt;/strong&gt; What happens if the rope is longer or shorter? How does this affect the distance between the cliffs?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Different dips:&lt;/strong&gt; How does the height of the dip in the middle affect the distance between the cliffs?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;More complex scenarios:&lt;/strong&gt; What if there are more than two cliffs and multiple ropes? Can you calculate the distances between all the cliffs?&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Other uses of catenaries:&lt;/strong&gt; Catenaries aren't just for ropes and bridges. They're also used in architecture, in electricity and telecommunications cables, and even in the shape of a perfectly hung chain. Can you find other real-world uses of catenaries and apply your calculations there?&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Remember, the world is full of math problems waiting to be solved. So keep exploring, keep learning, and most of all, have fun!&lt;/p&gt;




</description>
      <category>catenary</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>python</category>
    </item>
  </channel>
</rss>
