<?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: Contra</title>
    <description>The latest articles on DEV Community by Contra (@avantcontra).</description>
    <link>https://dev.to/avantcontra</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%2F142298%2F6f337e3e-7f5a-458d-aa7a-c47afb22a885.png</url>
      <title>DEV Community: Contra</title>
      <link>https://dev.to/avantcontra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/avantcontra"/>
    <language>en</language>
    <item>
      <title>Fourier Series visualization using Unity</title>
      <dc:creator>Contra</dc:creator>
      <pubDate>Sun, 03 Nov 2019 12:47:37 +0000</pubDate>
      <link>https://dev.to/avantcontra/fourier-series-visualization-using-unity-5eif</link>
      <guid>https://dev.to/avantcontra/fourier-series-visualization-using-unity-5eif</guid>
      <description>&lt;p&gt;&lt;strong&gt;"Coding Druid"&lt;/strong&gt; series is my &lt;strong&gt;horizontal programming&lt;/strong&gt; practice notes, each part around a topic like mathematical, physics, electronic, graphics, sound, etc., implemented in several programming languages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Coding Druid&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Part&lt;/strong&gt;: Math&lt;br&gt;
&lt;strong&gt;Chapter&lt;/strong&gt;: Fourier Series&lt;br&gt;
&lt;strong&gt;Section&lt;/strong&gt;: Unity&lt;/p&gt;

&lt;p&gt;In the previous Chapter, I visualized Trigonometric function (Sine and Unit Circle) separately using &lt;a href="https://www.floatbug.com/2019/07/04/trigonometric-function-visualization-using-maxmsp%e2%80%8a-%e2%80%8acoding-druid/"&gt;MaxMSP&lt;/a&gt;, &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-javascript-react-3b85"&gt;JavaScript (React)&lt;/a&gt;, &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-python-2ogo"&gt;Python&lt;/a&gt;, and &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747"&gt;Unity&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--egHeYy9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1lwa8c2fi4f0p4pvcp3n.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--egHeYy9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1lwa8c2fi4f0p4pvcp3n.gif" alt="sine-unity-croped"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This chapter I implement &lt;strong&gt;Fourier Series&lt;/strong&gt; curve visualization.&lt;br&gt;
And &lt;strong&gt;Unity&lt;/strong&gt; this section.&lt;br&gt;
When it comes to Fourier transform or Fourier analysis, it is usually divided into two parts: &lt;strong&gt;Fourier series&lt;/strong&gt; and &lt;strong&gt;Continuous Fourier transform&lt;/strong&gt;. This chapter focuses on the &lt;strong&gt;Fourier series&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In mathematics, a Fourier series is a periodic function composed of harmonically related sinusoids, combined by a weighted summation.&lt;br&gt;
(&lt;a href="https://en.wikipedia.org/wiki/Fourier_series"&gt;wikipedia&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For example, suppose there is a square wave, and it can be interpreted into sine waves.&lt;br&gt;
The more sine waves you have, the preciser square wave you will get:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3B0bpZRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_and_transform.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3B0bpZRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_and_transform.gif" width="800px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;More graphic explanations and formula derivation, see the previous section: &lt;a href="https://dev.to/avantcontra/fourier-series-visualization-using-react-hooks-1he9"&gt;Fourier Series Visualization Using React Hooks&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;The effect of the previous section:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpn1Oa1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/fs-js-5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpn1Oa1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/fs-js-5.gif" alt="fs-js-5"&gt;&lt;/a&gt;&lt;br&gt;
&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now let's try &lt;strong&gt;Unity&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Have written an note &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747"&gt;Sine function visualization using Unity3D&lt;/a&gt;. So on the basis of its code, the drawing formula can be modified from the trigonometric function to the lower Fourier series：&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--J4Xzc9Y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-mathshot-5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--J4Xzc9Y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-mathshot-5.png" alt="fs-mathshot"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nUvTUB8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/carbon.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nUvTUB8g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/carbon.png" alt="code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The full code can be seen later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final effect&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SxJeN8Jp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/clo01w70qdti67xxivmv.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SxJeN8Jp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/clo01w70qdti67xxivmv.gif" alt="fs-unity"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Fourier_series"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747"&gt;Sine function visualization using Unity3D&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://dev.to/avantcontra/fourier-series-visualization-using-react-hooks-1he9"&gt;Fourier Series Visualization Using React Hooks&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://catlikecoding.com/unity/tutorials/basics/building-a-graph/"&gt;Building a Graph Visualizing Math&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Talk is cheap. Show me the code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo and the &lt;strong&gt;Coding Druid&lt;/strong&gt; series is open source here:&lt;br&gt;
&lt;a href="https://github.com/avantcontra/coding-druid"&gt;https://github.com/avantcontra/coding-druid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You may &lt;strong&gt;buy me a coffee&lt;/strong&gt; in my &lt;a href="https://www.patreon.com/avantcontra"&gt;Patreon&lt;/a&gt;. There are many articles, patches, source code and some &lt;strong&gt;advanced Patron-only content&lt;/strong&gt; there. &lt;/p&gt;

&lt;p&gt;Also you can get some free patches/codes in &lt;a href="https://gumroad.com/avantcontra"&gt;Gumroad shop&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Your encouragement is my driving energy!&lt;/p&gt;

&lt;p&gt;Cheers~&lt;/p&gt;

&lt;p&gt;Contra&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Website: &lt;a href="https://www.floatbug.com"&gt;floatbug.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://facebook.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram: &lt;a href="https://www.instagram.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Gumroad (buy codes directly): &lt;a href="https://gumroad.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon (advanced content): &lt;a href="https://www.patreon.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>unity</category>
      <category>fourierseries</category>
      <category>visualization</category>
      <category>math</category>
    </item>
    <item>
      <title>Fourier Series Visualization Using React Hooks</title>
      <dc:creator>Contra</dc:creator>
      <pubDate>Sat, 31 Aug 2019 16:15:30 +0000</pubDate>
      <link>https://dev.to/avantcontra/fourier-series-visualization-using-react-hooks-1he9</link>
      <guid>https://dev.to/avantcontra/fourier-series-visualization-using-react-hooks-1he9</guid>
      <description>&lt;p&gt;&lt;strong&gt;"Coding Druid"&lt;/strong&gt; series is my &lt;strong&gt;horizontal programming&lt;/strong&gt; practice notes, each part around a topic like mathematical, physics, electronic, graphics, sound, etc., implemented in several programming languages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Coding Druid&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Part&lt;/strong&gt;: Math&lt;br&gt;
&lt;strong&gt;Chapter&lt;/strong&gt;: Fourier Series&lt;br&gt;
&lt;strong&gt;Section&lt;/strong&gt;: Javascript (React)&lt;/p&gt;

&lt;p&gt;In the previous Chapter, I visualized Trigonometric function (Sine and unit circle) separately using &lt;a href="https://www.floatbug.com/2019/07/04/trigonometric-function-visualization-using-maxmsp%e2%80%8a-%e2%80%8acoding-druid/"&gt;MaxMSP&lt;/a&gt;, &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-javascript-react-3b85"&gt;JavaScript (React)&lt;/a&gt;, &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-python-2ogo"&gt;Python&lt;/a&gt;, and &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747"&gt;Unity&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EnieUS0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/sine-unity-croped.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EnieUS0K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/sine-unity-croped.gif" alt="sine-unity-croped"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This chapter I implement &lt;strong&gt;Fourier Series&lt;/strong&gt; curve visualization.&lt;br&gt;
And start with &lt;strong&gt;JavaScript and React&lt;/strong&gt; this section.&lt;/p&gt;



&lt;h3&gt;
  
  
  Mathematics
&lt;/h3&gt;

&lt;p&gt;In mathematics, a Fourier series is a periodic function composed of harmonically related sinusoids, combined by a weighted summation.&lt;br&gt;
(&lt;a href="https://en.wikipedia.org/wiki/Fourier_series"&gt;wikipedia&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;And it can be explained as expressing a repetitive curve as sum of sine curves. (&lt;a href="http://bilimneguzellan.net/en/purrier-series-meow-and-making-images-speak/"&gt;Purrier Series (Meow) and Making Images Speak&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;For example, suppose there is a square wave, and it can be interpreted into sine waves:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3B0bpZRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_and_transform.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3B0bpZRJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_and_transform.gif" width="800px"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The more sine waves you have, the preciser square wave you will get.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ejqh5XZL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/474px-Fourier_Series.svg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ejqh5XZL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/474px-Fourier_Series.svg.png" height="600px"&gt;&lt;/a&gt;&lt;/p&gt;





&lt;p&gt;Now Let's see the process of Fourier series expansion.&lt;/p&gt;

&lt;p&gt;Assume that &lt;code&gt;f(x)&lt;/code&gt; is a periodic function for &lt;code&gt;x∈[−π,π]&lt;/code&gt;, and its period is &lt;code&gt;2π&lt;/code&gt;.&lt;br&gt;
Its expression:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uMJmNNGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/u0hziw8rdcvijzph8sr2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uMJmNNGN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/u0hziw8rdcvijzph8sr2.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Then its trigonometric expression of Fourier series (sine-cosine form) is like:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8jZcDnT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e6ohbxzdnv7vmsz29ydc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Z8jZcDnT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/e6ohbxzdnv7vmsz29ydc.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;And Fourier coefficients of $f(x)$ is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--REXWq25C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/reorvbf7aqr4bqy5iao1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--REXWq25C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/reorvbf7aqr4bqy5iao1.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Finally&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--21i_A_7M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/swi9cek92qchwwsba6ws.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--21i_A_7M--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/swi9cek92qchwwsba6ws.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Above content refers to &lt;a href="https://www.amazon.com/s?k=9787810824088&amp;amp;i=stripbooks&amp;amp;linkCode=qs"&gt;"Advanced Mathematics - (Engineering Course) (Vol.2)"&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;And the original Fourier series definition and detail explanation will be found in &lt;a href="https://en.wikipedia.org/wiki/Fourier_series"&gt;wikipedia&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;



&lt;p&gt;Sums of lengths the first four terms, and showing how the approximation to a square wave:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vkh3v8ct--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vcz8wxkobevzgihvla4n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vkh3v8ct--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vcz8wxkobevzgihvla4n.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aevyhYEc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_square_wave_circles_animation.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aevyhYEc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/Fourier_series_square_wave_circles_animation.gif" width="500px"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;h3&gt;
  
  
  Visualization
&lt;/h3&gt;

&lt;p&gt;Now to visualize this curve using React.&lt;br&gt;
I have forked and refactored a &lt;a href="https://dev.to/avantcontra/sine-function-visualization-using-javascript-react-3b85"&gt;sine visualization&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sIeL9Q90--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/sine-visualization-reactjs.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sIeL9Q90--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/sine-visualization-reactjs.gif" alt="sine-visualization-reactjs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I will do the Fourier stuff on the basis of above code.&lt;/p&gt;

&lt;p&gt;It’s really clear to write code using React:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ldtEGOxZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ldtEGOxZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-0.png" alt="fs-js-carbon-0"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dpZnc0eW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x7l2n15zfwa6it1vr4k4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dpZnc0eW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x7l2n15zfwa6it1vr4k4.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Nqi8Sw72--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Nqi8Sw72--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-1.png" alt="fs-js-carbon-1"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Still use &lt;strong&gt;React Hooks&lt;/strong&gt; to update the data binded with Components:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--SBmzH2fs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--SBmzH2fs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://floatcc.intplusplus.org/fs-js-carbon-2.png" alt="fs-js-carbon-2"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Final curve&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fpn1Oa1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/fs-js-5.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fpn1Oa1J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/http://floatcc.intplusplus.org/fs-js-5.gif" alt="fs-js-5"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As n increases, that is, the sine wave increases, the synthesized waveform gets closer to the square wave.&lt;/p&gt;



&lt;h4&gt;
  
  
  References
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://en.wikipedia.org/wiki/Fourier_series"&gt;Wikipedia&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="http://bilimneguzellan.net/en/purrier-series-meow-and-making-images-speak/"&gt;Purrier Series (Meow) and Making Images Speak&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://thecodingtrain.com/CodingChallenges/125-fourier-series.html"&gt;CodingChallenges by Daniel Shiffman&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.amazon.com/s?k=9787810824088&amp;amp;i=stripbooks&amp;amp;linkCode=qs"&gt;Advanced Mathematics - (Engineering Course) 高等数学（工科类）&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.amazon.com/Signals-Systems-2nd-Alan-Oppenheim/dp/0138147574"&gt;Signals &amp;amp; Systems (Second Edition) by Alan V. Oppenheim&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://zhuanlan.zhihu.com/p/35679341"&gt;[干货]---Fourier级数&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;&lt;a href="https://www.youtube.com/watch?v=0LuyxzqI3Hk"&gt;傅立叶变换如何理解？美颜和变声都是什么原理？李永乐老师告诉你&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;Talk is cheap. Show me the code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo and the &lt;strong&gt;Coding Druid&lt;/strong&gt; series is open source here:&lt;br&gt;
&lt;a href="https://github.com/avantcontra/coding-druid"&gt;https://github.com/avantcontra/coding-druid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more resources in my site &lt;a href="https://www.floatbug.com"&gt;floatbug.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You may &lt;strong&gt;buy me a coffee&lt;/strong&gt; in my &lt;a href="https://www.patreon.com/avantcontra"&gt;Patreon&lt;/a&gt;. There are many articles, patches, source code and some &lt;strong&gt;advanced Patron-only content&lt;/strong&gt; there. &lt;/p&gt;

&lt;p&gt;Also you can get some free patches/codes in &lt;a href="https://gumroad.com/avantcontra"&gt;Gumroad shop&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Your encouragement is my driving energy!&lt;/p&gt;

&lt;p&gt;Cheers~&lt;/p&gt;

&lt;p&gt;Contra&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Website: &lt;a href="https://www.floatbug.com"&gt;floatbug.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://facebook.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram: &lt;a href="https://www.instagram.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Gumroad (buy codes directly): &lt;a href="https://gumroad.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon (advanced content): &lt;a href="https://www.patreon.com/avantcontra"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>fourierseries</category>
      <category>visualization</category>
      <category>math</category>
    </item>
    <item>
      <title>Sine function visualization using Unity3D</title>
      <dc:creator>Contra</dc:creator>
      <pubDate>Fri, 12 Jul 2019 07:10:05 +0000</pubDate>
      <link>https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747</link>
      <guid>https://dev.to/avantcontra/sine-function-visualization-using-unity3d-4747</guid>
      <description>&lt;p&gt;&lt;strong&gt;"Coding Druid"&lt;/strong&gt; series is my &lt;strong&gt;horizontal programming&lt;/strong&gt; practice notes, each part around a topic like mathematical, physics, electronic, graphics, sound, etc., implemented in several programming languages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Coding Druid&lt;/strong&gt;&lt;br&gt;
Part: Math&lt;br&gt;
Chapter: Trigonometric Function&lt;br&gt;
Section: Unity3D&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In other sections, I visualized Trigonometric function (Sine and unit circle) by &lt;a href="https://www.patreon.com/posts/sine-function-28131990/" rel="noopener noreferrer"&gt;MaxMSP&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28238879" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28178275" rel="noopener noreferrer"&gt;JavaScript(React)&lt;/a&gt;:&lt;/em&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f4dw6woj7rd1ows1gw.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f4dw6woj7rd1ows1gw.gif" alt="trig-sine-visualization-reactjs" width="720" height="304"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time I use &lt;strong&gt;Unity3D&lt;/strong&gt; to implement it.&lt;/p&gt;

&lt;p&gt;In the Python version, the data visualization Library Matplotlib was used. With Unity I just draw it according to the trigonometric function algorithm.&lt;/p&gt;

&lt;p&gt;Firstly, Let a point move with the Sine function curve.&lt;/p&gt;

&lt;p&gt;Put a Sphere in the scene, and let its &lt;code&gt;position.x&lt;/code&gt; increase at a constant speed, then &lt;code&gt;position.y = sin(position.x)&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Vector3 posSine = sphere.localPosition;&lt;br&gt;
posSine.x += speed;&lt;br&gt;
posSine.y = Mathf.Sin(posSine.x);&lt;br&gt;
sphere.localPosition = posSine;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-sineball.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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-sineball.gif" alt="sine-unity-sineball" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Next, draw a path of the sphere moving along the unit circle.&lt;/p&gt;

&lt;p&gt;Note that here, set the radius of the unit circle to 1, and set the period length of Sine to 2Pi. That is as shown in the previous sections, the unit circle shares a coordinate system with Sine.&lt;/p&gt;

&lt;p&gt;Formula to drawing a circle:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;x = cos(t);&lt;br&gt;
y = sin(t);&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The param &lt;code&gt;t&lt;/code&gt; here, in fact is the &lt;code&gt;position.x&lt;/code&gt; of the Sine in previous step.&lt;/p&gt;

&lt;p&gt;Then move the center of the circle to the left, to make the rotating starting point of the unit circle consistent with the starting point of Sine.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Vector3 posCircle = posSine;&lt;br&gt;
posCircle.x = Mathf.Cos(posSine.x) - 1f;&lt;br&gt;
posCircle.y = Mathf.Sin(posSine.x);&lt;br&gt;
circleDot.localPosition = posCircle;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-circleball.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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-circleball.gif" alt="sine-unity-circleball" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;Combine the Sine and unit circle:&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-sinecircleball.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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-sinecircleball.gif" alt="sine-unity-sinecircleball" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;



&lt;p&gt;In the previous articles, I drew the path of the curve to make it more clearly, such as Python:&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-py-effect-0.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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-py-effect-0.gif" alt="sine python effect" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I plan to be lazy with Unity. &lt;br&gt;
Add the &lt;code&gt;Trail Renderer&lt;/code&gt; directly to the two spheres, and let them draw path trail effect themselves.&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-trail0.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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-trail0.gif" alt="sine-unity-trail0" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Well, The default trail is a bit strong...&lt;/p&gt;

&lt;p&gt;OK let's change it. After searching &lt;code&gt;trail&lt;/code&gt; in the Unity Assets Store I find a free &lt;a href="https://assetstore.unity.com/packages/vfx/particles/spells/particle-ribbon-42866" rel="noopener noreferrer"&gt;good track effect&lt;/a&gt;：&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg8qwwws48sb60bjq2dm.jpg" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvg8qwwws48sb60bjq2dm.jpg" alt="unity-trail" width="516" height="389"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After installation the asset there are a lot of effects. Then pick a material by liking:&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-trail-material.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-unity-trail-material.png" alt="sine-unity-trail-material" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Attach the material to the Trail Renderer.&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;Final Effect&lt;/strong&gt;:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.gif" alt="sine-unity-croped" width="720" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In the released source code, I added &lt;code&gt;Trail Renderer&lt;/code&gt; to an empty &lt;code&gt;GameObject&lt;/code&gt; and moved with the sphere. I didn't add the track directly to the sphere. There is no special reason, just practice of Unity newbie.&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Reference article: &lt;a href="https://catlikecoding.com/unity/tutorials/basics/building-a-graph/" rel="noopener noreferrer"&gt;Building a Graph Visualizing Math&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Talk is cheap. Show me the code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo of the "Coding Druid" series is open source here:&lt;br&gt;
&lt;a href="https://github.com/avantcontra/coding-druid" rel="noopener noreferrer"&gt;https://github.com/avantcontra/coding-druid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more resources in my site &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;.&lt;br&gt;
 Or you may &lt;strong&gt;buy me a coffee&lt;/strong&gt; in my &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;Patreon&lt;/a&gt;. Your encouragement is my driving energy!&lt;/p&gt;

&lt;p&gt;Cheers~&lt;/p&gt;

&lt;p&gt;Contra&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Website: &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://facebook.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram：&lt;a href="https://www.instagram.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon (&lt;strong&gt;buy me a coffee&lt;/strong&gt; XD): &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>unity3d</category>
      <category>math</category>
      <category>sine</category>
      <category>visualization</category>
    </item>
    <item>
      <title>Sine function visualization using Python</title>
      <dc:creator>Contra</dc:creator>
      <pubDate>Fri, 12 Jul 2019 04:07:23 +0000</pubDate>
      <link>https://dev.to/avantcontra/sine-function-visualization-using-python-2ogo</link>
      <guid>https://dev.to/avantcontra/sine-function-visualization-using-python-2ogo</guid>
      <description>&lt;p&gt;&lt;strong&gt;"Coding Druid"&lt;/strong&gt; series is my &lt;strong&gt;horizontal programming&lt;/strong&gt; practice notes, each part around a topic like mathematical, physics, electronic, graphics, sound, etc., implemented in several programming languages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Coding Druid&lt;/strong&gt;&lt;br&gt;
Part: Math&lt;br&gt;
Chapter: Trigonometric Function&lt;br&gt;
Section: Python&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In other sections, I visualized Trigonometric function (Sine and unit circle) by &lt;a href="https://www.patreon.com/posts/sine-function-28131990/" rel="noopener noreferrer"&gt;MaxMSP&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28178275" rel="noopener noreferrer"&gt;JavaScript(React)&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28291611" rel="noopener noreferrer"&gt;Unity3D&lt;/a&gt;:&lt;/em&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.gif" alt="trig-sine-visualization-unity" width="720" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time I use Python to implement it.&lt;/p&gt;

&lt;p&gt;For the quick goal, directly Google "python data visualization lib" these keywords, get the lib, sort by the number of stars in github, found the old and strong &lt;a href="https://matplotlib.org/" rel="noopener noreferrer"&gt;Matplotlib&lt;/a&gt;. So, it was so pleasant to decide.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Matplotplib Install&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Consider the follow-up exercises, I select the whole-family-bucket installation method provided by &lt;a href="https://www.anaconda.com" rel="noopener noreferrer"&gt;Anaconda&lt;/a&gt;. It includes a bunch of libraries related to scientific data analysis including Matplotlib.&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%2Fwww.anaconda.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fdistro-01-1.png" 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%2Fwww.anaconda.com%2Fwp-content%2Fuploads%2F2018%2F11%2Fdistro-01-1.png" alt="Anaconda" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Due to the recent unfixed working computer and location, I've deployed a remote development environment (VSCode Remote rocks!). The code is deploying and running on the Azure server. I just use a old notebook to edit the code and view the effect. &lt;br&gt;
So I choose the Linux version for the server environment.&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/http%3A%2F%2Ffloatcc.intplusplus.org%2FAnaconda-python3.0.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2FAnaconda-python3.0.png" alt="Anaconda Python 3.0" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;, the Python 3.x version on the left is preferred here, because Matplotlib 3.0 and above only supports Python 3.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Matplotlib 3.0 is Python 3 only.&lt;/p&gt;

&lt;p&gt;For Python 2 support, Matplotlib 2.2.x will be continued as a LTS release and updated with bugfixes until January 1, 2020.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then you can start coding after Matplotlib installing.&lt;/p&gt;

&lt;p&gt;(In fact, after writing a few lines, I found that remotely developing Python, it is still not convenient to view the result graphics in real time. So I also installed &lt;a href="https://jupyter.org/" rel="noopener noreferrer"&gt;Jupyter Notebook&lt;/a&gt; and coding directly in the browser, WYSIWYG.)&lt;/p&gt;

&lt;p&gt;In addition, ffmpeg is installed too, to save the animation obtained by Matplotlib to mp4.&lt;br&gt;
Also used Anaconda to install ffmpeg.&lt;br&gt;
&lt;code&gt;conda install -c conda-forge ffmpeg&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;With Matplotlib, the Sine function animation part, in fact, there is not a few code. Most is actually the coordinate configuration, and draw some auxiliary lines and so on.&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-py-carbon.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsine-py-carbon.png" alt="sine python script" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Basically coding by according to the tutorial and some reference articles. The characteristics of this library, most of the ideas focus on the algorithmic logic of the mathematical formula itself.&lt;/p&gt;

&lt;p&gt;A nice reference article:&lt;br&gt;
&lt;a href="https://towardsdatascience.com/animations-with-matplotlib-d96375c5442c" rel="noopener noreferrer"&gt;Animations with Matplotlib&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Effect&lt;/strong&gt;:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0jrp6164dlqdp61tdrs.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft0jrp6164dlqdp61tdrs.gif" alt="sine-visualization-reactjs" width="676" height="397"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Talk is cheap. Show me the code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo of the "Coding Druid" series is open source here:&lt;br&gt;
&lt;a href="https://github.com/avantcontra/coding-druid" rel="noopener noreferrer"&gt;https://github.com/avantcontra/coding-druid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more resources in my site &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;.&lt;br&gt;
 Or you may &lt;strong&gt;buy me a coffee&lt;/strong&gt; in my &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;Patreon&lt;/a&gt;. Your encouragement is my driving energy!&lt;/p&gt;

&lt;p&gt;Cheers~&lt;/p&gt;

&lt;p&gt;Contra&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Website: &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://facebook.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram：&lt;a href="https://www.instagram.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon (&lt;strong&gt;buy me a coffee&lt;/strong&gt; XD): &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>math</category>
      <category>sine</category>
      <category>visualization</category>
    </item>
    <item>
      <title>Sine function visualization using JavaScript (React)</title>
      <dc:creator>Contra</dc:creator>
      <pubDate>Fri, 12 Jul 2019 03:57:31 +0000</pubDate>
      <link>https://dev.to/avantcontra/sine-function-visualization-using-javascript-react-3b85</link>
      <guid>https://dev.to/avantcontra/sine-function-visualization-using-javascript-react-3b85</guid>
      <description>&lt;p&gt;&lt;strong&gt;"Coding Druid"&lt;/strong&gt; series is my &lt;strong&gt;horizontal programming&lt;/strong&gt; practice notes, each part around a topic like mathematical, physics, electronic, graphics, sound, etc., implemented in several programming languages.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Coding Druid&lt;/strong&gt;&lt;br&gt;
Part: Math&lt;br&gt;
Chapter: Trigonometric Function&lt;br&gt;
Section: Javascript (React)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;In other sections, I visualized Trigonometric function (Sine and unit circle) by &lt;a href="https://www.patreon.com/posts/sine-function-28131990/" rel="noopener noreferrer"&gt;MaxMSP&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28238879" rel="noopener noreferrer"&gt;Python&lt;/a&gt;, &lt;a href="https://www.patreon.com/posts/sine-function-28291611" rel="noopener noreferrer"&gt;Unity3D&lt;/a&gt;:&lt;/em&gt;&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fbks0ojn8y8fe375j96o0.gif" alt="trig-sine-visualization-unity" width="720" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This time I use javascript to implement it.&lt;/p&gt;

&lt;p&gt;There are kinds of ways to draw graphic in javascript in browser:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Directly in Canvas or WebGL&lt;/li&gt;
&lt;li&gt;d3js&lt;/li&gt;
&lt;li&gt;p5js&lt;/li&gt;
&lt;li&gt;pixijs&lt;/li&gt;
&lt;li&gt;SVG + CSS&lt;/li&gt;
&lt;li&gt;More and more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I found a &lt;a href="https://codepen.io/HunorMarton/pen/ggQGqQ" rel="noopener noreferrer"&gt;React + SVG example&lt;/a&gt; by chance, and I very like it.&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/http%3A%2F%2Ffloatcc.intplusplus.org%2FWX20190706-174205%402x.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2FWX20190706-174205%402x.png" alt="React + SVG example" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The SVG descripted Sine function in a marked way:&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsvg.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2Fsvg.png" alt="svg" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And binding and updating the value of param &lt;code&gt;degree&lt;/code&gt; along x-axis taking advantage of the updating mechanism of React State. &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/http%3A%2F%2Ffloatcc.intplusplus.org%2Freactstate.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2Freactstate.png" alt="reactstate" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I think its a beautiful and charming way.&lt;/p&gt;



&lt;p&gt;I rarely used SVG in my past projects. Then I learn it from this example and cool! Thanks for its &lt;a href="https://codepen.io/HunorMarton/pen/ggQGqQ" rel="noopener noreferrer"&gt;author&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;While React is my most commonly used library in front-end projects for years. But I'm new with its latest features like &lt;strong&gt;React Hooks&lt;/strong&gt;. So I study and refactor the React State part of the example using React Hooks.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://reactjs.org/docs/hooks-intro.html" rel="noopener noreferrer"&gt;Hooks official document&lt;/a&gt; is great. I just followed its rules and implemented the functions like that:&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/http%3A%2F%2Ffloatcc.intplusplus.org%2Freacthooks.png" 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/http%3A%2F%2Ffloatcc.intplusplus.org%2Freacthooks.png" alt="reacthooks" width="800" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Hooks is simple and powerful, but you should take care the performance issue. Because the &lt;code&gt;useEffect()&lt;/code&gt; will run both after the first render and after &lt;strong&gt;every&lt;/strong&gt; update. &lt;a href="https://reactjs.org/docs/hooks-effect.html#tip-optimizing-performance-by-skipping-effects" rel="noopener noreferrer"&gt;The offical tips here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final Effect&lt;/strong&gt;:&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f4dw6woj7rd1ows1gw.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg2f4dw6woj7rd1ows1gw.gif" alt="sine-visualization-reactjs" width="720" height="304"&gt;&lt;/a&gt;&lt;br&gt;
I changed the color style to make a distinction with the original example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Talk is cheap. Show me the code!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This demo of the "Coding Druid" series is open source here:&lt;br&gt;
&lt;a href="https://github.com/avantcontra/coding-druid" rel="noopener noreferrer"&gt;https://github.com/avantcontra/coding-druid&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can find more resources in my site &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;.&lt;br&gt;
 Or you may &lt;strong&gt;buy me a coffee&lt;/strong&gt; in my &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;Patreon&lt;/a&gt;. Your encouragement is my driving energy!&lt;/p&gt;

&lt;p&gt;Cheers~&lt;/p&gt;

&lt;p&gt;Contra&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Website: &lt;a href="https://www.floatbug.com" rel="noopener noreferrer"&gt;floatbug.com&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Github: &lt;a href="https://github.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Facebook: &lt;a href="https://facebook.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twitter: &lt;a href="https://twitter.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Instagram：&lt;a href="https://www.instagram.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Patreon (&lt;strong&gt;buy me a coffee&lt;/strong&gt; XD): &lt;a href="https://www.patreon.com/avantcontra" rel="noopener noreferrer"&gt;avantcontra&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>math</category>
      <category>sine</category>
      <category>visualization</category>
    </item>
  </channel>
</rss>
