<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Andy Flatiron on Medium]]></title>
        <description><![CDATA[Stories by Andy Flatiron on Medium]]></description>
        <link>https://medium.com/@andyflatiron?source=rss-2b4cf9c25141------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*e2r25XvqG_B0RRGkcX5tmA.png</url>
            <title>Stories by Andy Flatiron on Medium</title>
            <link>https://medium.com/@andyflatiron?source=rss-2b4cf9c25141------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 14:20:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@andyflatiron/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Useful functions in Unity]]></title>
            <link>https://andyflatiron.medium.com/useful-functions-in-unity-c88efbd00494?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/c88efbd00494</guid>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 24 Dec 2020 23:08:06 GMT</pubDate>
            <atom:updated>2020-12-24T23:19:19.688Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve been working with Unity now, pushing to learn the language of C# and the program itself and it’s been quite the journey this past week. Most of the material I’ve been learning is from the <a href="https://learn.unity.com/">Unity Learn </a>website, but also from the <a href="https://www.amazon.com/Unity-Game-Development-Cookbook-Virtual/dp/1491999152">“Unity Game Development Cookbook”</a> by O’Reilly Publishing.</p><p>Here are some useful tips and functions that I will continue to reference as they will really help me out as I work on my personal project, hopefully they will help you too.</p><p>Spawning New Obstacles Every Few Seconds. Here we need to use the “<strong>Invoke Repeating</strong>” Method and call it on start, with this method we pass it, the function to call, the amount of time before spawning, and the set interval.</p><p>Here’s an example of how to use invoke repeating ( note these aren’t working examples they are coming out of my notebook, so some of the syntax and capitalization may be wrong,<em> but nothing </em><strong><em>visual studio</em></strong><em> can’t fix!</em></p><pre>public GameObject obstaclePrefab</pre><pre>void start(){<br>  invokeRepeating(&quot;SpawnObstacles&quot;, 1, 2) </pre><pre>}</pre><pre>void SpawnObstacles(){<br>  Instantiate(obstaclePrefab, new Vector3(x, y, z), obstaclePrefab.transform.rotation)<br>}</pre><p>This will instantiate a new instance of the obstacle prefab game object that we passed into this SpawnController</p><p>Another useful function to now is how to know which object that your current object has collided with is to use the compare tag and set it to the name of the object. So for example if you are trying to keep track of when your player comes into contact with your enemy. In your inspector add a tag to your object, and then use the following method.</p><pre>OnCollisionEnter(Collision collision){<br>   if(collision.gameObject<strong>.CompareTag(&quot;Enemy&quot;)</strong>{<br>     Debug.Log(&quot;Player has collided with Enemy&quot;)<br>   }</pre><pre>}</pre><p>What if we wanted to make our player object move horizontally how would we do that? Easy we first need to set a certain speed that we want it to move, then we just need to get the Axis from the built in Axis Finder. Then we can just transform the movement and multiply it by our horizontal input as follows</p><pre>public Speed = 10f;//using public here so we can adjust in the inspector and find the perfect number! <br>public float HorizontalInput;</pre><pre>void update(){<br> horizontalInput = <strong>Input.GetAxis(&quot;Horizontal&quot;)<em>(1)</em><br> </strong>transform.Translate(<strong>Vector3.left)<em>(2) * </em></strong>Time.DeltaTime * speed)<em>3</em><br>}</pre><ol><li>We are getting the coordinates from the user on horizontal axis — pulling from the left or right keys</li><li>.left on the Vector3 automatically sets the position and movement of the object</li><li>Multiply the vector with time and speed and you have an object that moves naturally in the environment</li></ol><p>Now your update method is programmed to keep on watching from any input on either the left or right arrow keys. If there is movement, Vector3.left, will multiply with the integer that horizontal input is providing it. Very useful method for the future!</p><p>To this point how can we add jumps with physics! ? It’s also important here to make sure that we don’t Double Jump! Let’s set some variables such as our jump force (to make our jump more realistic), a gravity modifier that we’ll make public so we can use at any time and our rigid body of our player, which holds our gravity settings!</p><pre>public float jumpForce;<br>public float gravityModifier;<br>public RigidBody playerRb;</pre><pre><em>1</em></pre><ol><li>We are setting our variables all public so that we can reference them in the inspector and adjust our settings in the future — and RigidBody needs to be public so we can access it outside of this class</li></ol><pre>void start(){<br>playerRb = GetComponent&lt;RigidBody&gt;(); <br>Physics.gravity *= gravityModifier<br>}</pre><p>In the start method we are selecting the Rigidbody and setting it to the player variable — afterward we are multiplying and setting the gravity of the object to the gravityModifier, which we can edit it in the inspector.</p><pre>void update(){</pre><pre>if input.getKeyDown(keyCode.Space <strong><em>1</em></strong>){</pre><pre> playerRb.AddForce(Vector3.up * JumpForce, forceMode.Impulse <strong><em>2</em></strong>)<br>}</pre><ol><li>KeyCode you can set any of the keys and they trigger upon touch, if you hold it doesn’t repeat like Get Axis</li><li>forceMode.Impulse puts all the force on the object at once so it’s not spread out over time, you can see a direct impact of the space bar.</li></ol><p>One more thing you can do is add a boolean and say that onGround is false once you press the space bar, this way you can’t double jump.</p><p>Let’s set up an on trigger event. So to set an on trigger, first you need to make sure that your ‘on trigger’ is selected on the mesh collidor and we need to apply tags similar to the onCollision.</p><pre>private void onTriggerEnter(collider other){</pre><pre>  if(other.compare_tag(&quot;powerup&quot;){<br>    hasPowerUp = true<br>  }</pre><pre>}</pre><p>In this function when an object is collided with another object that has a trigger it will change the hasPowerUp Variable to true. This is helpful to use, with another object that has a trigger vs. onCollisionEnter which is used for more physics based interactions.</p><p>Lastly, let’s set up a coroutine, used as a counter, which doesn’t require the use of the update function!</p><pre>IEnumerator PowerUpCountdown(){<br>  yield return WaitForSeconds(2)<br>  hasPowerUp = false<br>}</pre><p>here we are using the IEnumerator and Yield statements to allow us to use the WaitForSeconds() method which is built in to Unity. When the Coroutine is called, wait for seconds, will wait 2 seconds before applying the rest of the method. We can call the coroutine in the start() method</p><pre>public bool hasPowerUp = true; //public to test in the inspector</pre><pre>private void onTriggerEnter(collider other){</pre><pre>   if(other.compareTag(&quot;PowerUp&quot;){<br>      hasPowerUp = true</pre><pre>      startCoroutine(powerUpCountdown())   <br> <br>   }<br>}</pre><p>When we collide with the powerUp object, it is automatically set to true and then we start the coroutine, when the coroutine is finished, it sets the boolean to false, so that the powerUp is no longer active!</p><p>Those are just some helpful functions to get started, hopefully they will help you along your coding journey!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c88efbd00494" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a hello world app in Unity]]></title>
            <link>https://andyflatiron.medium.com/creating-a-hello-world-app-in-unity-703fb0791222?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/703fb0791222</guid>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Fri, 18 Dec 2020 00:51:24 GMT</pubDate>
            <atom:updated>2020-12-18T00:51:24.317Z</atom:updated>
            <content:encoded><![CDATA[<p>My adventure getting started in Unity</p><p>First you need to get Unity Hub, create a personal account for free and then go ahead and download Unity. Once you’re all set with your license you can easily download unity through the website <a href="https://unity3d.com/get-unity/update">https://unity3d.com/get-unity/update</a> or the hub</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gSNG2eKMIVp4MzJDDIABTw.png" /><figcaption>Unity Hub Download Setup Page</figcaption></figure><p>Your license will automatically be added and Unity Visual Studio will download approximately 1.3 gb of data to your disk. Through the Hub they have lot’s of different features — along with install base.</p><p>You can checkout the tutorials, learn how to create specific projects and also start and create your own project.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*peHfpBn_Hyst9lexLutBCg.png" /><figcaption>Learn Section on the Unity App with Projects and Tutorial</figcaption></figure><p>Now that Unity is installed I’ll go ahead and open it and create a new project we’ll call it “Hello My New World” since Unity has an option to code in Javascript, I’ll be working with Javascript and hold on C# for now…let’s figure out how to create that code. It’s actually taking quite a bit to install so I’m going to hold off for a minute. And start with a quick tangent. Let’s find a cool rails gem that changes colors while loading a script maybe on rails db:seed…wow this rails stuff is also taking a while to set up, but it looks like it installed faster than Unity :) I’m going to CD into my “loading-genie” project and I’m going to create a really large seed file that creates a new model each time. So let’s generate a resource called largeDevil</p><pre>rails g resource large_devils </pre><p>I added a string and an integer to the large_devils area</p><pre>class CreateLargeDevils &lt; ActiveRecord::Migration[6.0]<br>  def change<br>    create_table :large_devils do |t|<br>     t.string :name<br>     t.integer :data<br>      t.timestamps<br>    end<br>  end<br>end</pre><p>and I migrated the data</p><p>Now I’m going to seed 100,000 of these large devils with a random number also I’m going to faker a name for each of these, which will take even more time, since it has to pull from the API</p><ul><li>* unity is still installing **</li></ul><p>Added the faker gem</p><p>gem ‘faker’</p><pre>100000.times do <br> LargeDevil.create(name: Faker::Name.name, data: rand(1..100000))<br>end</pre><p>Making 100000 large devils</p><p>Actually I’m just going to make 10,000 so I an see how it ends</p><pre>10000.times do <br>  puts (&quot;creating large devil&quot;) <br>  LargeDevil.create(name: Faker::Name.name, data: rand(1..100000))<br>end</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EVcPTZ55QLTP95asYukzZA.png" /><figcaption>Current Procedure</figcaption></figure><p>Looks like this when creating the large devil. But let’s try this gem by janlelis called whirly</p><pre>gem install whirly<br>gem &#39;whirly&#39;, &#39;~&gt; 0.2.6&#39;</pre><p>Also installing a gem called paint that whirly recommends to make the terminal text look colorful</p><pre>gem &#39;paint&#39;</pre><p>and it looks like we need to wrap this inside a method while the block executes</p><pre>10000.times do <br>  Whirly.start do<br>  puts (&quot;creating large devil&quot;)<br>  LargeDevil.create(name: Faker::Name.name, data: rand(1..100000))<br>  sleep 5<br> end <br>end</pre><p>Cool, now it looks like every 5 seconds emojis cycle through each other to indicate a loading bar</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/380/1*rndS_UvwMcyU3JPxQahVbA.png" /><figcaption>emoji loading animations</figcaption></figure><p>by default the whirly is emoji’s, we can configure it to display dots instead</p><pre>Whirly.configure spinner: &quot;dots&quot;</pre><p>and let’s set sleep to 10 seconds and it works! And I’m happy with the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/46/1*YGevjBQCOAAtihtSgZzDzA.png" /><figcaption>loading animations</figcaption></figure><p>and Unity finally finished installing. so let’s create a new project and we’ll make it 3D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-QpXuwcWNqAKO5WRjQrCA.png" /></figure><p>I have no clue what I’m doing here — but I’ll give it a shot!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*n3ecIjBG8FLTldUAcuufAA.png" /></figure><p>doing some more install things, so i’ll continue to create my ruby file…or not, it looks like it’s finished.</p><p>Now that Unity window is open, I’m going to create a new C# script, I named it helloWorld and opened it up in Sublime</p><p>To make sure that the script is connected to Unity we need to add a console.log, similar to javascript but in Csharp its called Debug.Log</p><pre>void Start()<br>    {<br>     Debug.Log(&quot;Hello World&quot;);<br>    }</pre><p>Now we need to attach the script to an Object, so we’ll create an empty object to attach the script too</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/326/1*VAN26PBssGPz2zhI2wSh6Q.png" /></figure><p>and we’ll rename the empty object to “Debug” and we’ll drag and add the script to the object. Now we’re officially connected to the object and when the scene runs it outputs hello world into our text!</p><p>And now when the scene runs, the cSharp file will be executed and we’ll see “hello world” outputting in our console!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*VrIqM6v1U4kBKagWpIxvTA.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=703fb0791222" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Image Recognition in Ruby]]></title>
            <link>https://andyflatiron.medium.com/image-recognition-in-ruby-71231f7e41f3?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/71231f7e41f3</guid>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 17 Dec 2020 23:53:46 GMT</pubDate>
            <atom:updated>2020-12-17T23:53:46.597Z</atom:updated>
            <content:encoded><![CDATA[<p>A few steps you can use to help you get started with image recognition in ruby</p><p>This blog post is documentation through my journey through the Google API documentation, which you can view <a href="https://codelabs.developers.google.com/codelabs/cloud-vision-api-ruby/index.html?index=..%2F..cloudai#0">here</a></p><p><strong>Google Cloud Vision </strong>is an API allowing developers to understand the content of an image, by implementing Google Machine learning and artificial intelligence learning models. Some interesting use cases of image recognition include.</p><h3>Competitive Landscape</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*QE4OuavyJUGijQvd.jpeg" /></figure><p><em>courtesy of kairos</em></p><p>Google, Amazon, and Microsoft are the most popular vision API’s and although each of the companies has the same end-user result, I choose to work with Google because it connects to the entire google cloud, and once you have it set up, it gives you access to many different artificial intelligence capabilities. I also found their documentation easy to follow, so if you’re reading this and haven’t yet take a look and then come back to this article, for my own personal experience.</p><p>You can get started for free with up to $300, but with a pro plan</p><ul><li>they offer Tech Support</li><li>You’re killing it</li></ul><p>Many smaller companies offer compelling use cases as well.</p><h3>Use Cases</h3><p><strong>Authentication and Emotion</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8CWvQ6vBsy8RrtnP.png" /></figure><p>Microsoft Project Oxford AI</p><p>Microsoft’s Project Oxford offers facial recognition to easily recognize users and certain photos and allow users to log into phones using authentication. Used as a tool for marketing companies to gauge success metrics.</p><p><strong>A Self Driving Future</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*xmO5PMW9-PzN-3pv.gif" /></figure><p>Self-driving car image classification</p><p>Self-driving cars perform something known as image classification, which is trained to recognize various objects such as other cars and pedestrians. Images are detected or classified. The classified images get passed to the neural network and get localized where the artificial intelligence connects the input with a valid suggestion or result.</p><p><strong>Augmented Reality</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wyrHWpTHh91Vt0X_.jpeg" /></figure><p>Marker Based Augmented Reality</p><p>Marker Based augmented reality works of triggers in your local environment. These markers, which work off of image recognition, can provide users with entire experiences based on their location and in-situ environments.</p><h3>Getting Started</h3><p><strong>Create a new Google Cloud Project</strong></p><p>a) Sign up quickly using your GMAIL account.</p><p>b) On the dashboard tap the “My First Project” dropdown and select “New Project”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*OhVD0taL0NKAf4M8.png" /></figure><p>c) Enter your project name and hit create</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LSuq7pcECPi9ICwt.png" /></figure><p>d) You should see an empty dashboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*i229oxMQdWdqqWOs.png" /></figure><p>Google Cloud Platform Dashboard</p><p><strong>Start cloud shell</strong></p><p>In order to run the cloud environment, you need to have a server running, instead of downloading a server, for the purposes of this article you can use the <a href="https://cloud.google.com/cloud-shell/">Google Cloud Shell</a>, which is a command-line environment that runs in the cloud</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JkotJ91i5LcbSIvH.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dnQi8VPGmb4m7Z7n.png" /></figure><p>Run the following command to confirm that you are authenticated</p><pre>gcloud auth list</pre><p><strong>Command Output</strong></p><pre>Credentialed accounts:<br> - &lt;myaccount&gt;@&lt;mydomain&gt;.com (active)</pre><p>Run this code next</p><pre>gcloud config list project</pre><p><strong>Command Output</strong></p><pre>project = &lt;PROJECT_ID&gt;</pre><p><strong>3. Enable the vision API</strong></p><p>Run this in the cloud shell</p><pre>gcloud services enable vision.googleapis.com</pre><p><em>Command Output</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*mJA-LyJlYfGUXTgD" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*luYY0Ko3YItatNj7.png" /></figure><h3>4. Create a service account</h3><p>In order to use the API, you need to create a service account to make requests. There are a few different ways to go about this step, and it is the most complex, but here’s what worked best for me.</p><ol><li><a href="https://console.cloud.google.com/apis/credentials/serviceaccountkey?_ga=2.145626289.425672379.1595857515-190320903.1595526570">Go to the Service Account Key Page</a></li><li>From the <strong>Service account</strong> list, select <strong>New service account</strong>.</li><li>In the <strong>Service account name</strong> field, enter a name.</li><li>From the <strong>Role</strong> list, select <strong>Project</strong> &gt; <strong>Owner</strong>.</li><li>Click <strong>Create</strong>. A JSON file that contains your key downloads to your computer.</li><li>Remember the save location as you will need to access it in the next step</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*62fbcjonNggxl_14" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*gpm07NGqL82Vvu4k.png" /></figure><p>After creating and downloading your service account key in JSON. Locate your file path in the terminal and copy it into your clipboard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*xO3qRlckSwzSAT-l" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/564/0*jvCyKLO6XFqqbGIu.png" /></figure><p>After confirming the file works and is opening properly set this file two proper keys <strong>in your terminal input</strong> the following</p><pre><strong>export </strong>GOOGLE_APPLICATION_CREDENTIALS=&quot;/Users/AndyXcode/Downloads/Mod-3-Blogpost-fff77bdf1b10.json&quot;t</pre><p>This sets your application credentials</p><pre><strong>export</strong> GOOGLE_CLOUD_PROJECT=&quot;/Users/AndyXcode/Downloads/Mod-3-Blogpost-fff77bdf1b10.json&quot;</pre><p>This sets your cloud project credentials, note both of these are pointed to the same JSON file. Note if your file name has any spaces, make sure to edit the file name before setting the credentials. Once you have this set up the rest is pretty straightforward.</p><h3>5. Install the Cloud Vision Gem</h3><pre>gem install google-cloud-vision -v 0.27.0</pre><h3>6. Download the sample ruby repository</h3><pre>git clone <a href="https://github.com/GoogleCloudPlatform/ruby-docs-samples.git">https:<em>//github.com/GoogleCloudPlatform/ruby-docs-samples.git</em></a><br>cd ruby-docs-samples<br>git checkout &quot;a902f30dd449ce82469cc315610c8a3d4888ff5a&quot;</pre><p>change directory into ruby-docs-samples/vision</p><pre>cd vision</pre><p>Run bundle install in your vision folder</p><h3>7. Start IRB</h3><pre>irb --noecho</pre><h3>8. Sample an Image</h3><p>Run the following code in your IRB</p><pre>require &quot;google/cloud/vision&quot;</pre><pre>vision = Google::Cloud::Vision.new<br>**select an image**<br>image  = vision.image &quot;images/otter_crossing.jpg&quot;</pre><h3>9. Explore API</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/60/0*TpWrg7_p4oUQ8C_Q" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/792/0*WrJOBFkMo0X1nKz4.png" /></figure><p>The vision API offers many different options of ways to analyze and image and they also provide ruby files with information on how to use each of its different features.</p><h3>10. Perform image analysis</h3><p>Here’s the code Google Provides for us to identify landmarks. The goes into the image and calls landmarks, and pastes the landmark’s description. The code also then puts both the latitude and longitude of landmark</p><pre>image.landmarks.each do |landmark|<br>    puts landmark.descriptionlandmark.locations.each do |location|<br>      puts &quot;#{location.latitude}, #{location.longitude}&quot;<br>    end<br>  end</pre><p>Let’s run this image</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*881_UjytNhx0kwPh.png" /></figure><p>A caption will be provided by Google… shortly</p><pre>image = vision.image &quot;images/imagine.png&quot; =&gt; [#&lt;Google::Cloud::Vision::Annotation::Entity mid: &quot;/m/013397&quot;, locale: &quot;&quot;, description: &quot;Strawberry Fields (memorial)&quot;, score: 0.416331022977829, confidence: 0.0, topicality: 0.0, bounds: 4, locations: 1, properties: {}&gt;]</pre><p>It successfully pulled the image description — and it’s location property</p><pre>Strawberry Fields (memorial)40.775744, -73.975281</pre><p>Let’s paste that location into google maps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CdvSYAndpcJ8dmjH.png" /></figure><p>Strawberry Fields (memorial) 40.775744, -73.975281</p><p>Let’s try and perform text detection on that image as well, see if the API can pick up on the text “imagine”</p><pre>puts image.text</pre><p>close…</p><pre>IMAG NE=&gt; nil</pre><p>it’s missing the ‘i’ in imagine.</p><p><strong>Now for the final test</strong></p><pre>Take screenshot of student in the class and run an emotion detection</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/170/0*mxVb7LaVfG7yaynb.png" /></figure><p>image coming soon</p><pre>JOY: <br>ANGER: <br>SORROW:<br>SUPRISE:</pre><p>As you can tell once you have the available data from the image input there are a lot of different directions that you can take this app. The API offers unlimited possibilities. The next step for me would be to take the API from IRB and bring it into a functional javascript application that I can work with. All of the possibilities make Google Vision API one of the most exciting developments in the industry.</p><p>As you can tell once you have the available data from the image input there are a lot of different directions that you can take this app. The API offers unlimited possibilities. The next step for me would be to take the API from IRB and bring it into a functional javascript application that I can work with. All of the possibilities make Google Vision API one of the most exciting developments in the industry.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=71231f7e41f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React audio player]]></title>
            <link>https://andyflatiron.medium.com/creating-a-react-audio-player-36f4a29f7c1b?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/36f4a29f7c1b</guid>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[javacript]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 10 Dec 2020 15:17:13 GMT</pubDate>
            <atom:updated>2020-12-10T15:17:13.226Z</atom:updated>
            <content:encoded><![CDATA[<p>Using the Web Audio Api, here’s my process to leveraging the initial setup to create a React music player. Thank you to Mozilla and Web Audio Api for the wonderful <a href="https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API/Using_Web_Audio_API">documentation</a> to help me complete this tutorial. This player gives you the ability to pause/play a track, add and remove gain and also pan the audio from left to right. If I have enough time, I will try to implement the drag and drop interface to enable custom sliders. Let’s get started!</p><p>First things first, let’s create a new react project</p><pre>npx create-react-app spatialsound</pre><p>If you’d like to set up version control you can create a repo through github and then ‘git init’ the folder in the terminal. Once your react app is created enter the directory and open it up in your favorite text editor.</p><p>To get started with the Web Audio API, let’s begin by changing our App.js from a function to a class and the first thing we are going to do is add an Audio element to the dom.</p><pre>&lt;audio src=&quot;&quot;&gt;&lt;/audio&gt;</pre><p>Since we are anticipating changing this song in the near future, let’s set ‘song’ to state and let source equal the state of song</p><pre>&lt;audio src={this.state.song}&gt;&lt;/audio&gt;</pre><p>Now we’ll need to create a state and let’s also make sure to save a song in the public folder that we can reference in our state. The song I choose is called thedeli.mp3. Once it’s added to the public folder, you can set it to state as follows:</p><pre>state = {<br>    song: process.env.PUBLIC_URL + &#39;thedeli.mp3&#39;,<br>  }</pre><p>Awesome, now song is set to state, but how do we play the sound? First I’m going to double check that the song is being properly called as an Audio Element and I’m going to do this by calling console.log(this.state) in the render function…great looks like we’re all set.</p><p>Let’s now create a componentDidMount function. Here we have to do an initial set up to make sure our app is properly connected to the framework.</p><pre>componentDidMount(){<br>const AudioContext = window.AudioContext || window.webkitAudioContext;<br>const audioContext = new AudioContext();<br>}</pre><p>Here we are creating a new constant that has access to the Web Audio API. Once we have the constant we create a new instance of AudoiContext so that we can use it and play a sound.</p><p>Next, save audioContext to state, since we’ll need to access it in future functions and it may need to be altered as we are switching songs. So make sure to add audioContext as an option in state and then set this instance of audioContext to your state</p><pre>state = {<br>    song: process.env.PUBLIC_URL + &#39;thedeli.mp3&#39;,<br>    audioContext: null<br>  }</pre><pre>//componentDidMount<br>this.setState(audioContext: audioContext)</pre><p>Now that audio context is set we need to find the audio element, the actual div holding the audio file and connect the audio context to it. In order to do that, we need to access the audio element by using the document query selector and then setting the audioElement to state.</p><pre>const audioElement = document.querySelector(&#39;audio&#39;);<br>this.setState({audioElement:audioElement})</pre><p>Now we just have to take both the elements that we created a combine them together using the createMediaElementSource. We can conveniently label this section ‘track’ because this is going to be what is playing through the speakers. Then we just connect the track to the destination. And wallah, the sound is ready to be played.</p><pre>componentDidMount(){<br>    const AudioContext = window.AudioContext ||      window.webkitAudioContext;<br>    const audioContext = new AudioContext();<br>    this.setState({audioContext: audioContext})<br>    const audioElement = document.querySelector(&#39;audio&#39;);<br>    this.setState({audioElement:audioElement})<br>    const track = audioContext.createMediaElementSource(audioElement);<br>    track.connect(audioContext.destination);<br>  }</pre><p>Now we can manipulate the audio element, to pause it and play it</p><pre>audioElement.play();<br>audioElement.pause();</pre><p>But wait…why is it not playing? The reason is because the browser doesn’t allow auto play without the user prompted some form of button to start or stop a track. So because of this, let’s create a play button!</p><p>In order to do this we’ll start with a click handler in App.js. I will call it ‘playClickHandler’. Let’s also create a new JS file called PlayClick JS , and import it into App.JS. I’m also going to add a state called ‘playing’ in app.js which will be a boolean to signify if the button has been pressed.</p><pre>//PlayClick.js</pre><pre>import React from React</pre><pre>export default class PlayClick extends React.Component{<br> render(){<br>  return(<br>   &lt;h1&gt; PlayClick &lt;/h1&gt; <br>  )<br> }<br>}</pre><p>In App.js</p><pre>import PlayClick from &#39;./PlayClick&#39;</pre><p>Now let’s add a handler and pass the handler into PlayClick, add a button to PlayClick which will then flip the state of playing to its opposite</p><pre>playClickHandler = (e) =&gt; {<br>    console.log(e)<br>  }</pre><pre>render(){<br>    console.log(this.state)<br>    return(<br>      &lt;div&gt; <br>        &lt;h1&gt; Hello &lt;/h1&gt; <br>        &lt;audio src={this.state.song}&gt;&lt;/audio&gt;<br>        &lt;PlayClick playClickHandler={this.playClickHandler}/&gt;<br>      &lt;/div&gt;</pre><pre>)<br>  }<br>}</pre><p>Make sure it’s properly passing</p><pre>import React from &#39;react&#39;</pre><pre>export default class PlayClick extends React.Component{<br> render(){<br>  console.log(this.props)<br>  return(<br>    &lt;button&gt; Play &lt;/button&gt; <br>  )<br> }<br>}</pre><p>We want to make sure the button says ‘play’ when the song is paused and ‘pause’ when the song is playing. So we’re going to need to use state here.</p><p>Add a simple ternary statement that changes the text based on the state…currently its false, but let’s set it so every-time we click it changes and also calls the prop function</p><pre>&lt;button onClick={<br>     (e) =&gt; {<br>      this.setState({playing:!this.state.playing},<br>       this.props.playClickHandler(this.state.playing)<br>      )<br>     }<br>    }&gt;</pre><p>OnClick we are setting state to the opposite boolean and then we are calling the playClickHandler function and passing it the state of the boolean. Which we will then set in app.js</p><p>Now we just need to resume AudioContext which is required in order to initialize a track upon page load</p><pre>this.state.audioContext.resume();</pre><p>And let’s add a simple if statement that says if the state is equal to playing then play the sound otherwise pause the sound</p><pre>if(this.state.playing === false){<br>      console.log(&quot;playing&quot;)<br>      this.state.audioElement.play()<br>    }else if(this.state.playing === true){<br>      console.log(&quot;notplaying&quot;)<br>      this.state.audioElement.pause()<br>    }</pre><p>Now you’re all set! You have audio in your browser and you can pause and play it to your hearts desire! I hope to dive deep further in using effects such as gain and pan, but that is it for now, I hope you enjoyed reading!</p><p>Until next time,</p><p>Andy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36f4a29f7c1b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Drag and Drop System in React]]></title>
            <link>https://javascript.plainenglish.io/drag-and-drop-in-react-79d926fd666e?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/79d926fd666e</guid>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 03 Dec 2020 02:04:46 GMT</pubDate>
            <atom:updated>2020-12-10T15:29:20.600Z</atom:updated>
            <content:encoded><![CDATA[<p>Here’s my method for creating a drag and drop system in React. It’s not too complicated and I’m excited to share my process with you in this blogpost.</p><p>First let’s create a new React app.</p><pre>npx create-react-app emoji-fun-app</pre><p>I entitled it “emoji-fun-app” because I think it would be cool to drag around emojis and create different ‘scenes’</p><p>To get started I start by restructuring my App.js file, turn it into a class and removing any unnecessary details. The isn’t going to do much, it’s only going to fetch the API for Emojis and hold our components .</p><p>I downloaded every emoji from Emoji API, sliced the array, took the first 10 emoji’s and then set the Emoji’s to the state of the app. I’m going to pass the emojis to another component and map through them</p><pre>import logo from &#39;./logo.svg&#39;;<br>import &#39;./App.css&#39;;<br>import React from &#39;react&#39;</pre><pre>export default class App extends React.Component{<br>  <br>  state = {<br>    emojis: [],<br>    url: &quot;<a href="https://emoji-api.com/emojis?access_key=baf562ed274edd3bda0cdbf65ff31eba1e658f1a">https://emoji-api.com/emojis?access_key=baf562ed274edd3bda0cdbf65ff31eba1e658f1a</a>&quot;<br>  }</pre><pre>componentDidMount(){<br>    fetch(this.state.url)<br>    .then(response =&gt; response.json())<br>    .then(data =&gt; data.slice(0,10))<br>    .then(data =&gt; this.setState({emojis: data}))<br>  }</pre><pre>render(){<br>    return(<br>      &lt;div&gt; <br>        &lt;h1&gt; Hello &lt;/h1&gt;<br>      &lt;/div&gt;<br>    )<br>  }<br>}</pre><p>I created an EmojiContainer and I’m passing in the Emoji data as a prop</p><pre>&lt;EmojiContainer emojis = {this.state.emojis} /&gt;</pre><p>In the EmojiContainer I map through each emoji and create an EmojiCard for each (to display the emoji)</p><pre>//EmojiContainer.js<br>let emojis = this.props.emojis.map(emoji =&gt; &lt;EmojiCard emoji = {emoji} /&gt;)</pre><pre>//EmojiCard.js<br>&lt;h1&gt; {this.props.emoji.character} &lt;/h1&gt;</pre><p>In the emoji card, i’m working on selecting a specific emoji, so I added an on click event and ran a quick console log</p><pre>&lt;div onClick={(e)=&gt; {<br>     console.log(e.target)<br>    }}&gt; {this.props.emoji.character} &lt;/div&gt;</pre><p>Through this I was able to select a single emoji, so it may work in order to drag multiple while loading them on to the page at once</p><p>Now I’m going to set the style of the DIV and set the position to absolute, so that they are not fixed to any parent div and can be moved freely.</p><pre>&lt;div style ={{<br>      position: &quot;absolute&quot;,<br>      top: 100,<br>      left: 200,<br>      border: &quot;3px solid #73AD21&quot;</pre><pre>}}</pre><p>I’m going to add state for positioning both X+Y coordinates and set their initial values to 100</p><pre>state={<br>  selectedEmoji: &quot;&quot;,<br>  elementX: 100, <br>  elementY: 100<br> }<br>  //change the style from hardcoded numbers to reflect state<br>  top: this.state.elementY + &#39;px&#39;,<br>  left: this.state.elementX + &#39;px&#39;,</pre><p>Now I’m going to change the onClick to a React event called onDragOver. The idea here is that since the browser gives us access to the mouse position of the page, while we are dragging, let’s set the state of elementY and elementX to the position of the mouse on the page. This was my original hypothesis and after some tinkering it actually works…</p><pre>onDragOver={(e)=&gt; {<br>     e.stopPropagation();<br>     e.preventDefault();<br>     const yAxis = e.pageY<br>     const xAxis = e.pageX</pre><pre>this.setState({elementY: yAxis})<br>    }}&gt; {this.props.emoji.character}</pre><p>It’s quite simple…just to walk you through, we start by preventing some of the default behavior that automatically occurs when dragging, we then define the y and x axis by setting them to the value of the users mouse on the page. Afterwords we are setting the state, the axis we defined and automatically adjusting the style and positioning of the page as we drag.</p><p><em>I’m running into a slight issue now of actually selecting the emojis. I think it’s because Emoji’s read as strings not as images, making them difficult to drag</em></p><p>From my understanding and my current approach I’m not sure this demo is going to work any more since strings are not draggable. Maybe I can create a div that the emojis are placed in, make it invisible and drag that instead of the emoji…</p><p>It turns out the string wasn’t the issue at all! In fact the error was that I didn’t set draggable to be true when creating the div. If we go ahead and set that</p><pre>&lt;div draggable=&quot;true&quot; className = &quot;rectangle&quot; style ={{<br>      position: &quot;absolute&quot;,<br>      top: this.state.elementY + &#39;px&#39;,<br>      left: this.state.elementX + &#39;px&#39;,<br>   }}onDragOver={(e)=&gt; {<br>    console.log(e)<br>     e.stopPropagation();<br>     e.preventDefault();<br>     const yAxis = e.pageY <br>     const xAxis = e.pageX</pre><pre>this.setState({elementY: yAxis})<br>    }}&gt; {this.props.emoji.character} &lt;/div&gt;<br>   &lt;/div&gt;</pre><p>We can now drag the emojis up and down. Right now I’m only working with the Y Axis to make sure that works and once I’m all set there I’m going to start on the X Axis</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*-avq_NDYsU8DNKS_JsQYxg.gif" /><figcaption>Dragging on the Y Axis</figcaption></figure><p>Awesome, now that the Y-Axis is working. We can start on the X-Axis by adding the following lines of code</p><pre>//setting the x-axis to the mouse position of the mouse on the page<br>const xAxis = e.pageX</pre><pre>//set state to the mouse position<br>this.setState({elementX: xAxis})</pre><pre>//update the style &#39;left&#39; from the staet<br>left: this.state.elementX + &#39;px&#39;,</pre><p>Now that we’ve set the X-Axis we should have full access to drag our Emoji’s across the page!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*jzE_bNvwz_lb7DSOJMMz4w.gif" /></figure><p>Your Emoji’s are free at last!</p><p>There’s a minor bug here, which I can’t seem to figure out but when setting the state you need to subtract 10 from the mouse position. If you have any thoughts on how to fix that please let me know in the comments!</p><p>Until next week,</p><p>Andy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79d926fd666e" width="1" height="1" alt=""><hr><p><a href="https://javascript.plainenglish.io/drag-and-drop-in-react-79d926fd666e">Creating a Drag and Drop System in React</a> was originally published in <a href="https://javascript.plainenglish.io/">JavaScript in Plain English</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring the Swift Documentation]]></title>
            <link>https://andyflatiron.medium.com/exploring-the-swift-documentation-b23c6b5dd3cb?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/b23c6b5dd3cb</guid>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 26 Nov 2020 16:21:05 GMT</pubDate>
            <atom:updated>2020-11-26T17:50:00.381Z</atom:updated>
            <content:encoded><![CDATA[<h3>Swift Experimentation</h3><p>Things are off to a great start learning Swift! I’ve been enjoying the Stanford lectures <a href="https://cs193p.sites.stanford.edu/">(CS193P)</a>. To better internalize the reading assignment, I’m going to code along here, and review my thought process. Since I’m not in a physical class, this gives me a great opportunity to express myself and internalize my thoughts as I learn the vigorous course material.</p><p>The layout for today&#39;s blog post will be the following. To the best of my ability, I will read and then summarize a certain section in the <a href="https://swift.org/">Swift Documentation</a>, afterwords I will showcase an example to demonstrate the concept.</p><h4>Type Safety and Type Inference</h4><p>Type safety makes sure that you specify the type of code you are working with. For example, if you are going to use a string, such as “hello world,” you can’t just set it to a var. Var hello= “hello world” would not work because the system is not aware that “hello world” is a string. So, in this case, you would need to specify what <em>type </em>the var hello is — a string. So instead, it would look like the following</p><pre>var hello: String = &quot;Hello World&quot;</pre><p>By assigning the Var “hello” to a string, you let the system know that this variable will always be a string. If you wanted to set hello to an integer or a boolean in the future, you can’t. Once you set a type param, it locks into its type and cannot be manipulated.</p><p>for example, the following code</p><pre>var hello:String = &quot;Hello, World&quot;<br>hello = 1<br>print(str)</pre><p>will print out an error “<strong>cannot assign the value of type ‘Int’ to type ‘String’”</strong></p><p>Coming from Javascript, this took a bit of getting used to; however, I’m starting to see some of the benefits. When a language is type-safe, it prevents the code from even compiling two types that are not the same. Also, type safety helps you eliminate time-consuming type errors developed from multiple types interacting with one another.</p><p>However<strong>, </strong>unlike languages such as C or Objective-C<strong>, </strong>Swift has <strong>type inference </strong>which during certain declarations allows you to leave out the Type Variables as they will automatically be inferred</p><p>So, for demonstration purposes, I didn’t mention this in the original example, but if you set var hello = “Hello World”, swift will infer that “hello world” is a string and automatically set the type</p><p>In the following example, we are creating a function to check the type of the argument</p><pre>func printInfo (value: Any){<br>    let t = type(of: value)<br>    print(&quot;\(value) of type \(t)&quot; )<br>}var hello:String = &quot;Hello, World&quot;<br>hello = 1<br>print(str)</pre><p>You can see if we introduce a number argument without specifying the type and print its information</p><pre>var number = 5<br>printInfo(value: number)</pre><p>We see that the number type is an integer</p><pre>5 of type Int</pre><p><strong>Also, </strong>I’m not sure if this is exactly related to this topic, but functions require params to be written both when calling the function and in the function itself. This is great, as it allows you to know what you’re argument is doing in the function itself.</p><p>So in the case of this function</p><pre><strong>func</strong> printInfo (value: <strong>Any</strong>){}</pre><p>In order to pass in a value, you’ll need to specify “value: <em>argument</em>” before sending in the argument</p><pre>var number = 5<br>printInfo(value: <strong>number</strong>)</pre><p>If you don’t want to specify the parameter type, you can put an underscore before the argument in the function, which will allow you to call</p><pre>func printInfo (<strong>_</strong> value: Any){}<br>printInfo(number)</pre><p>Also, <strong>Any </strong>means that you can input any type into the function. Similar to strong type the parameter needs to have a specified type and return function, but if you use any, it takes in any type and returns any type</p><p>For example, if you did this:</p><pre><strong>func</strong> printInfo (value: String)</pre><p>and tried passing an integer into the function</p><pre>var number = 5<br>printInfo(value: number)</pre><p>The program would error out as it “Cannot convert Int into String”. That’s a bit on type safety and inference in Swift, now I’d like to test out an example.</p><p>In Javascript, you could get the following error based on the arguments that you send into the function</p><pre>const funFunction = (a,b) =&gt; {<br>    console.log(a + b.toUpperCase())<br>}</pre><p>toUpperCase is a function that could only be called on Strings, but Javascript allows you to send an Int into the function…and if you send in Int as ‘b’ the code will error out. So this can be frustrating of only some arguments are working with your function. In more complex cases, you wouldn’t even be sure where the error is coming from and it could be a long process of debugging.</p><p>In Swift, however, you wouldn’t even try to pass in an integer because the function so clearly states <strong>we only accept string</strong></p><pre>func funFunction(_ a: String, _ b:String){<br>    let b = (b.uppercased())<br>    print (a + b)<br>}</pre><pre>funFunction(&quot;hello&quot;, 1)</pre><p>And not to mention the function would error out before even calling the function — saying the following</p><pre>error: eligible-.playground:14:22: error: cannot convert value of type &#39;Int&#39; to expected argument type &#39;String&#39;<br>funFunction(&quot;hello&quot;, 1)</pre><p>That’s it for the safe type and type inference section for today’s reading.</p><h4>Numeric Type Conversion</h4><p>Numeric type conversion makes sure that you don’t combine two different number types accidentally. Swift recommends typically using ‘Int’ or ‘Double’ as it will function universally throughout your code, however, if you are looking to do more complex computing, or working upstream into memory efficiency, you may use different types of integers.</p><p>Here are the different types of integer formats you may encounter</p><blockquote>UInt8 (min: 0, max: 255)</blockquote><blockquote>UInt16( min: 0, max: 65535)</blockquote><blockquote>UInt32(min: 0, max: 4294967295)</blockquote><blockquote>UInt64(min: 0, max: 18446744073709551615)</blockquote><p>Note, none of these integer types have the ability to be less than zero. And what if you have an integer in the negatives that you’re looking to compute … how would you go about doing it?</p><p>So let’s say we have an Int at “-40”</p><pre><strong>let</strong> negativeForty:Int = -40</pre><p>And if want to take another variable and subtract it…actually it looks like this can’t be done because there is no way to convert a UInt to an Int — unless you use something called a bit pattern, which I’m not going to digest today…</p><p>But nevertheless, let’s explore some of the possibilities of type-conversions. So, if you have a UInt16 it won’t add with a UInt32. But, Swift has built-in extensions that allow the conversions between the two numerical structures.</p><p>So for example if we try to add number1 and number2 which are different number formats, it won&#39;t compute properly :</p><pre>let number1: UInt16 = 120<br>let number2: UInt8 = 4<br>let outputNum = (number1+number2)<br>print(outputNum)</pre><pre>=&gt; overloads for &#39;+&#39; exist with these partially matching parameter lists: (UInt16, UInt16)</pre><p>But we can add a numeric type conversion</p><pre>UInt16(number2)</pre><p>Which is an extension within the UInt16 class, which will allow us to add the numbers as follows:</p><pre>var number1: UInt16 = 120<br>var number2: UInt8 = 4<br>//adding number 1 to convert number 2 to 16 bit from 8<br>var outputNum = (number1+UInt16(number2))<br>print(outputNum)<br> <br>=&gt; 124</pre><h3>Tuples</h3><p>A touple lets you group many different types into one variable. It functions similarly to an array, but is not reccomended to be used in multiple data types. With a tuple, you can also rename multiple variables at once for easier access to your intended data type.</p><pre>let chance = (&quot;dog&quot;, false, 3)<br>let (animal, good, age) = chance<br>print((&quot;\(good)&quot;))</pre><pre>=&gt; false <br>//the value of false is automatically linked up to the value of &#39;good&#39; in the tupple</pre><p>The documentation mentions tuples work best with functions that return multiple arguments,so let’s give it a shot — we’ll have a function that returns a recipe, with amount of ingredients (Int) and Main Ingredient (String)</p><pre>func recipe(ingredientsCt:Int, mainIngredient: String ){<br>    let recipe = (ingredientsCt, mainIngredient)<br>    print(&quot;You&#39;re going to cook \(recipe.0) portion of \(recipe.1)&quot;)<br>}<br>recipe(ingredientsCt: 1, mainIngredient: &quot;Rice&quot;)</pre><p>In the above example I set recipe to a tuple and was able to easily access the different argument variables by calling (0 and 1) on the tuple. This seems like a good way to handle function execution.</p><p>These are some initial examples that I created to showcase the initial reading and experiementation with the Swift documentation. It’s been great, so far.</p><p>Until Next,</p><p>Andy</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b23c6b5dd3cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a swift command line to-do list app]]></title>
            <link>https://andyflatiron.medium.com/creating-a-swift-command-line-to-do-list-app-a955f8593ea?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/a955f8593ea</guid>
            <category><![CDATA[arrays]]></category>
            <category><![CDATA[swit]]></category>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Thu, 19 Nov 2020 23:29:52 GMT</pubDate>
            <atom:updated>2020-11-19T23:29:52.684Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m new to Swift, but here goes nothing. My first to-do list app in a new language! I’m going to walk you through the steps I’m taking to make it happen — I will for sure be working closely with documentation at the same time. So onto creating a basic to-do list app using the swift command line, arrays, and some functions. All of this is going to be done in the Xcode playground. If you don&#39;t have Xcode downloaded — use <a href="https://apps.apple.com/us/app/xcode/id497799835?mt=12">this link </a>to download and install the necessary files to follow along. Also, I would like to have the ability to sort the list. For this tutorial, I’m not going to use views, just straight out playground code.</p><p>To get started, I’m going to create an empty array called to-do-list…how do I create an array?</p><p>There are a few ways to create an array.</p><pre>let Numbers = [7,8,9,10,13,14]</pre><p>or you can set string elements</p><pre>let streets = [&quot;Albemarle&quot;, &quot;Brandywine&quot;, &quot;Chesapeake&quot;]</pre><p>both of these dynamically infer the type of element you are putting in the array, but since this is a to-do list app, we need to start with an empty array, so there’s nothing to infer.</p><p>For clarity purposes and typing good code, I’m going to use the full type name. I am trying to practice leveraging Swift’s strong type language capabilities, which I am not familiar with through Rails and Javascript.</p><p>So to create my to-do-list, I’m going to create an empty array called toDoList using the full type name.</p><pre><strong>var</strong> toDolist: Array&lt;String&gt; = Array()</pre><pre>=&gt; <strong>[]</strong></pre><p>Now we have the empty array, so it’s time to create our first task. Since each task will be a constant, I intentionally used let instead of var when defining the variable.</p><pre>let task1: String = “Brush Teeth”</pre><p>Now append the task to the array.</p><pre>toDolist.append(task1)<br>=&gt; [&quot;Brush Teeth&quot;]</pre><p>So we have one task in there, what if we wanted to append multiple more at once? We can use the contentsOf method provided for you in the append function</p><pre>toDolist.append(contentsOf:[task1, task2, task3])<br>print(toDolist)<br>=&gt; <strong>[&quot;Brush Teeth&quot;, &quot;Comb Hair&quot;, &quot;Call Holly&quot;]</strong></pre><p>Let’s create a simple function to add a new task to the todo list array.</p><pre><strong>func</strong> newTask(task: String) -&gt; Array&lt;String&gt;  {</pre><pre>toDolist.append(task)</pre><pre><strong>return</strong> toDolist</pre><pre>}</pre><pre>print(newTask(task: &quot;Make Breakfast&quot;))<br><strong>=&gt; [&quot;Brush Teeth&quot;, &quot;Comb Hair&quot;, &quot;Call Holly&quot;, &quot;Make Breakfast&quot;]</strong></pre><p>I was pretty happy when this started to work…I created a function called new task and set the parameters of the task to a string…I set the return value to an Array of Strings. This was my first time successfully setting a return value in a function in Swift.</p><p>I then appended the task to the toDoList and returned the toDoList array. Initially, I didn’t have the return statement, I just tried to append, and the function didn’t run. This makes sense because I told the function I would return an array, and if I’m appending, I’m not returning anything…</p><p>Now I have a new issue, each time I run the function the last item in the array is not saving and being overwritten. How do I commit the array to memory so that I can continuously add items from the function? It turns out that was a format issue with how I was calling and printing the function within the same line — the better way to test out the function would be as follows</p><pre>newTask(task: &quot;Eat Breakfast&quot;)<br>newTask(task: &quot;Cook Dinner&quot;)</pre><pre>print(toDolist)<br>=&gt; <strong>[&quot;Eat Breakfast&quot;, &quot;Cook Dinner&quot;]</strong></pre><p>Now that I have the function set up I’m going to streamline my playground set up a bit…</p><pre><strong>var</strong> toDolist: Array&lt;String&gt; = Array();</pre><pre><strong>func</strong> newTask(task: String) -&gt; Array&lt;String&gt;  {</pre><pre>toDolist.append(task)</pre><pre><strong>return</strong> toDolist</pre><pre>}</pre><pre>newTask(task: &quot;Eat Breakfast&quot;)</pre><pre>newTask(task: &quot;Cook Dinner&quot;)</pre><pre><br>print(toDolist)</pre><p>Ok, now let’s say I completed one of the tasks, how can I mark it as complete?</p><p>I’m going to create a function that checks to see if the typed task is in the current list — if it is in the delete it, if not, create the task</p><p>First, let’s check to find a task</p><pre><strong>let</strong> foundTask = toDolist.firstIndex(of: &quot;Cook Dinner&quot;)<br>=&gt; <strong>Optional(1)</strong></pre><p><em>First Index</em> automatically sets the index as an optional, so if there is nothing there when searching, it will set the value as nil and therefore not stop the code from running. We can then take the found object and remove it from the to-do list.</p><pre>toDolist.remove(at: foundTask!) </pre><p>I started out by creating a function that takes in a string, locates it within the Array, and then removes it</p><pre><strong>func</strong> taskMachine(task: String) -&gt; Array&lt;String&gt;{</pre><pre><strong>var</strong> chosenTask: Int = toDoList.firstIndex(of: task) ?? -1</pre><pre>toDoList.remove(at: chosenTask)</pre><pre><strong>return</strong> toDoList</pre><pre>}</pre><pre>print(taskMachine(task: &quot;Cook Dinner&quot;))</pre><p>The line below implies that if toDoList does not have the index of task, then set the task to negative 1. Since an array will never be a negative number, so I think, I set -1 as the value</p><pre><strong>var</strong> chosenTask: Int = toDoList.firstIndex(of: task) ?? -1</pre><p>I then created an if-else statement which implies that if the index number does not equal -1 that means it is, in fact, a string within the array, so take the chosenTask number and remove it from the array</p><pre><strong>if</strong> (chosenTask != -1) {</pre><pre>toDoList.remove(at: chosenTask)</pre><pre><strong>return</strong> toDoList</pre><pre>}</pre><p>else create append the string to the toDoList</p><pre>else{<br> toDoList.append(task)<br> return toDoList<br> }</pre><p>So as you can see, here’s the simple to-do list that we made using the Swift Playground! I hope to implement the views soon! But will continue on this project, it seems like a great way to learn the basics of Swift!</p><p>Demonstration:</p><pre>print(toDoList) </pre><pre><strong>=&gt; []</strong></pre><pre>taskMachine(task: &quot;Refry the beans&quot;)</pre><pre>taskMachine(task: &quot;Take a cold shower&quot;)</pre><pre>taskMachine(task: &quot;Comb my hair&quot;)</pre><pre><strong>=&gt;</strong> <strong>[&quot;Refry the beans&quot;, &quot;Take a cold shower&quot;, &quot;Comb my hair&quot;]</strong></pre><p>Here you can see that the tasks have been added to the array, and if we add the same task again</p><pre>taskMachine(task: “Refry the beans”)<br><strong>=&gt; [&quot;Take a cold shower&quot;, &quot;Comb my hair&quot;]</strong></pre><p>It gets removed from the array!</p><p>And that’s my first Swift post, I hope you enjoyed it</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a955f8593ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a React 360 App for Visualizing 3D models]]></title>
            <link>https://andyflatiron.medium.com/creating-a-react-360-app-for-visualizing-3d-models-7f5e0c41f9f9?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f5e0c41f9f9</guid>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Wed, 11 Nov 2020 17:20:36 GMT</pubDate>
            <atom:updated>2020-11-11T17:25:44.240Z</atom:updated>
            <content:encoded><![CDATA[<p>Exploring the React 360 Framework and Visualizing 3D models</p><h4>Thanks for reading…</h4><p>To get started let’s go ahead and set up React and Download the necessary frameworks —</p><pre>npm install -g react-360-cli</pre><p>Great, now that you have the latest version of React 360 installed on your machine we can now create a new project on our system.</p><p>Make sure you CD into the proper directory</p><pre>CD Blogposts </pre><p>Once you’re in the proper folder execute</p><pre>react-360 init My3DProject</pre><p>After the init statement you can name your project anything. This command will create a folder named “My 3D Project” and place the foundation of React 360 into the necessary sub-directories.</p><p>Once that’s finished installing you can go ahead and enter that directory</p><pre>cd My3DProject</pre><h4>Exploring the Code</h4><p>If you run</p><pre>NPM Start</pre><p>And then route to Localhost:8081/Index.html. This starts the React Native Package Manager and hosts the initial “hello world” view</p><p>If you are properly set up you should see the following screen displayed on your server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FR6f8m9WFIe49MyhPV8ywA.png" /><figcaption>React 360 Baseline Homepage</figcaption></figure><p><em>Pretty Cool Already, Isn’t It?</em></p><p>This page allows you to experience React 360 off the bat, you can scroll around with your mouse to view the 3D environment. Before we add a model and change the background Image, let’s first understand what is going on here.</p><p>Go ahead and open up the folder in VSCode or another text editor. First we’ll check out the Index.JS folder.</p><pre>import React from &#39;react&#39;;</pre><pre>import {</pre><pre>AppRegistry,</pre><pre>StyleSheet,</pre><pre>Text,</pre><pre>View,</pre><pre>} from &#39;react-360&#39;;</pre><pre>export default <strong>class</strong> My3DProject <strong>extends</strong> React.Component {</pre><pre>render() {</pre><pre>return (</pre><pre>&lt;View style={styles.panel}&gt;</pre><pre>&lt;View style={styles.greetingBox}&gt;</pre><pre>&lt;Text style={styles.greeting}&gt;</pre><pre>Welcome to React 360</pre><pre>&lt;/Text&gt;</pre><pre>&lt;/View&gt;</pre><pre>&lt;/View&gt;</pre><pre>);</pre><pre>}</pre><pre>};</pre><pre><strong>const</strong> styles = StyleSheet.create({</pre><pre>panel: {</pre><pre><em>// Fill the entire surface</em></pre><pre>width: 1000,</pre><pre>height: 600,</pre><pre>backgroundColor: &#39;rgba(255, 255, 255, 0.4)&#39;,</pre><pre>justifyContent: &#39;center&#39;,</pre><pre>alignItems: &#39;center&#39;,</pre><pre>},</pre><pre>greetingBox: {</pre><pre>padding: 20,</pre><pre>backgroundColor: &#39;#000000&#39;,</pre><pre>borderColor: &#39;#639dda&#39;,</pre><pre>borderWidth: 2,</pre><pre>},</pre><pre>greeting: {</pre><pre>fontSize: 30,</pre><pre>},</pre><pre>});</pre><pre>AppRegistry.registerComponent(&#39;My3DProject&#39;, () <strong>=&gt;</strong> My3DProject);</pre><p>The structure looks pretty similar to what we are used to seeing in React. At the top we are important components that will be used throughout the document.</p><p><strong>App Registry</strong> allows us to connect components of the Index page to the ./Client.JS, which is the runtime and the code that actually displays the code onto the screen. React separated the runtime in order to make the code run quicker and more efficiently as it already takes lots of CPU.</p><p><strong>StyleSheet </strong>gives us the ability to customize our Views and Text within the Index.js document so we don’t need to work with an external stylesheet.</p><p><strong>View </strong>allows us to create a 2D surface, it also functions as a DIV container. So always make sure to surround the React documents with Views. The functions are similar to React Native. Also, just like a Div, you can style the <strong>View </strong>component by specifying its size, background color, content justification, etc. All of this can be done through the Stylesheet component</p><p><strong>Text </strong>allows us to add text to 3D space. Text is typically nestled within a view component. It can also be styled in the Stylesheet.</p><p>Under the Render and Return functions you can see a standard React Layout with “View” instantiating the hierarchy instead of the typical Div Structure. You can see we have a parent View styled by <em>Panel</em> giving it a width of 1000 and a height of 600. The panel also specifies the color and opacity levels. We have other Views and text nestled within, all styled individually.</p><p>Under the Styles Panel (which on it’s own is very similar to CSS, so I assume you’re comfortable with it) we have the following line</p><pre>AppRegistry.registerComponent(&#39;My3DProject&#39;, () <strong>=&gt;</strong> My3DProject);</pre><p>From what I under this line is registering the Class ‘My3DProject’ and instantiating it to be accessible from the runtime, client.js. If we remove this line the entire class will disappear from the screen. Although we created a styled this view, the runtime actually places it in space.</p><p>This naturally leads us to the client.js document</p><p>If you open <strong>Client.js </strong>you will see the following</p><pre>import {ReactInstance} from &#39;react-360-web&#39;;</pre><pre><strong>function</strong> init(bundle, parent, options = {}) {</pre><pre><strong>const</strong> r360 = new ReactInstance(bundle, parent, {</pre><pre><em>// Add custom options here</em></pre><pre>fullScreen: true,</pre><pre>...options,</pre><pre>});</pre><pre><em>// Render your app content to the default cylinder surface</em></pre><pre>r360.renderToSurface(</pre><pre>r360.createRoot(&#39;My3DProject&#39;, { <em>/* initial props */</em> }),</pre><pre>r360.getDefaultSurface()</pre><pre>);</pre><pre><em>// Load the initial environment</em></pre><pre>r360.compositor.setBackground(r360.getAssetURL(&#39;360_world.jpg&#39;));</pre><pre>}</pre><pre>window.React360 = {init};</pre><p>I want to focus on the renderToSurface() function.</p><pre>r360.renderToSurface(</pre><pre>r360.createRoot(&#39;My3DProject&#39;, { <em>/* initial props */</em> }),</pre><pre>r360.getDefaultSurface()<br>);</pre><p>Remember the App Registry we set up in the index.js? Well, this is where it connects. When you create a class intended for 2D, you need to create a surface in the runtime and connect the Registered Class to the component. You then run getDefaultSurface so you don’t need to specify any more information regarding the location of the surface and its position in space.</p><h4>Modifying the document</h4><p>Under the function, you will see the following line</p><pre>r360.compositor.setBackground(r360.getAssetURL(&#39;360_world.jpg&#39;));</pre><p>This line here sets the background property, let’s start modifying our project by editing this photo. If you take a look at the <a href="https://facebook.github.io/react-360/docs/photos-and-videos.html">react documentation</a> there are multiple different ways to set the background and many different formats you can use as an image. The background can also be set in Index.js, but that is only necessary if the background is switching multiple times in an app. We are going to use a 360 Mono Equirectangular formatted image.</p><p>This can be easily sourced on the web, just search for it.</p><p>On Google, you might want to specify the Size to “Large for enhanced” visual clarity when landing on the site.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kwa0fAJph-masZWjKwicAg.png" /></figure><p>I found this nice photo of an Airplane Hanger</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LKuJ0QgCSpabd2l41EeCDA.jpeg" /></figure><p>Now we just need to upload the photo to the static_assets folder of our project. <em>If you look at Index.HTML, you can see that the source folder is already configured to “static_assets” so we don’t need to reference it every time.</em></p><p>Once it’s uploaded, change the compositor/setbackground function to search for the “‘Airplane.jpg’” image you just uploaded. If you refresh the page, you should see your image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1W8ItXlIJ4U_2nod-gsYRg.png" /></figure><p>Now let’s go ahead and modify the Index.js container to change the styles of the Wrapper Container, make it smaller, and change the text to say Come Hang in My Hanger!”</p><p>If you look at my styles you can see I adjusted the height of the wrapper View, adjusted the font size, and border color.</p><pre><strong>/index.js</strong></pre><pre><strong>const</strong> styles = StyleSheet.create({</pre><pre>panel: {</pre><pre><em>// Fill the entire surface</em></pre><pre>width: 1000,</pre><pre>height: 200,</pre><pre>backgroundColor: &#39;rgba(255, 255, 255, 0.4)&#39;,</pre><pre>justifyContent: &#39;center&#39;,</pre><pre>alignItems: &#39;center&#39;,</pre><pre>},</pre><pre>greetingBox: {</pre><pre>padding: 20,</pre><pre>backgroundColor: &#39;rgba(255, 255, 255, 0.1)&#39;,</pre><pre>borderColor: &#39;#00B0FF&#39;,</pre><pre>borderWidth: 2,</pre><pre>},</pre><pre>greeting: {</pre><pre>fontSize: 80,</pre><pre>},</pre><pre>});</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*erAqpugMmUO0r1JjIoDCBA.png" /></figure><p>Let’s go ahead and add an airplane 3D model under the header.</p><p>In order to do that, let’s first start by sourcing a 3D model online. React 360 <a href="https://facebook.github.io/react-360/docs/objects.html">only supports GLTF2 and OBJ files</a>. I typically start by visiting Google Poly for the models as they have an array of objects offered in different formats.</p><p>So, I checked out the site, searched for a plane, and found a low-poly jet that looks pretty cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kfIjftCGuPdEMF5U05wmAw.png" /></figure><p>Now how do we add it to the scene?</p><p>First, download the Obj Files and add both the OBJ and MTL files to the static-assets folder</p><p>Next, React 360 has a component type called <strong>Entity </strong>which allows us to render 3D objects to the scene. So let’s create a new file called “plane.js” and start creating our entity</p><pre>import {asset, Entity} from &#39;react-360&#39;</pre><p>Since we are importing an Asset into an Entity component we need to import both asset and Entity from React 360. Now let’s create the class and add the Entity. We create a View container and within the view, we’ll create an Entity component pointing to the source files of our object</p><pre>&lt;Entity</pre><pre>source={{</pre><pre>obj: asset(&#39;Plane.obj&#39;),</pre><pre>mtl: asset(&#39;Plane.mtl&#39;)</pre><pre>}}<br>/&gt;</pre><p>Next, we can style the entity, let’s start by transforming it’s scale, so it’s not overwhelming when we see it first on the page. We can do this by adding the style attributes to the entity itself. Your final Plane class should look like this</p><pre>import React from &#39;React&#39;</pre><pre>import {asset, Entity} from &#39;react-360&#39;</pre><pre>export default <strong>class</strong> Plane <strong>extends</strong> React.Component{</pre><pre>render(){</pre><pre>return(</pre><pre>&lt;View&gt;</pre><pre>&lt;Entity</pre><pre>source={{</pre><pre>obj: asset(&#39;Plane.obj&#39;),</pre><pre>mtl: asset(&#39;Plane.mtl&#39;)</pre><pre>}}</pre><pre>style={{transform:[</pre><pre>{scaleX: 0.05 },</pre><pre>{ scaleY: 0.05 },</pre><pre>{ scaleZ: 0.05 },</pre><pre>]}}</pre><pre>/&gt;</pre><pre>&lt;/View&gt;</pre><pre>)}}</pre><p>Now, we just need to link the model up with Index.JS by importing the file</p><pre>import Plane from &#39;./entities/Plane&#39;</pre><p>Awesome, now you’re all linked up, but why is the plane not showing?</p><p>Don’t you have to render it within Index.Js?</p><p>No, we actually need to first Register the component and then register it in Client.JS. So add this line to the bottom of your index.js file</p><pre>AppRegistry.registerComponent(&#39;Plane&#39;, () <strong>=&gt;</strong> Plane);</pre><p>We’re not done yet…let’s shift back over to the Client.js and place the object in the scene.</p><p>In order to place a 3D object to a scene we need to render it to a location, different from rendering a surface, we need to start by importing the Location Component from React 360 and then setting the coordinates of the component</p><pre><strong>client.js</strong><br>const location = new Location([0, -1, -2]);</pre><p>This location is one step down from the user and two back, so it should be easily viewable upon page load.</p><p>And now we’ll render the plane to the location using the following function and attached the registered class to the Root</p><pre><strong>const</strong> location = new Location([0, -1, -2]);</pre><pre>r360.renderToLocation(</pre><pre>r360.createRoot(‘Plane’),</pre><pre>location,</pre><pre>);</pre><p>Upon page load, you should now see the 3D model of the plane in your environment next to your views.</p><p>With that, I’m going to end off today’s blog! In the next one, I’ll be focusing on interacting with the 3D objects and turning our space into an interactive environment!</p><p><a href="https://github.com/Andyagus/My3DProject-medium">You can view the code for this project on my Github!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f5e0c41f9f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The current state of Augmented Reality and React (Native)]]></title>
            <link>https://andyflatiron.medium.com/the-current-state-of-augmented-reality-and-react-native-5307b8088525?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/5307b8088525</guid>
            <category><![CDATA[ar]]></category>
            <category><![CDATA[react-native]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 13:35:03 GMT</pubDate>
            <atom:updated>2020-08-18T13:35:03.110Z</atom:updated>
            <content:encoded><![CDATA[<p>My personal journey through Expo and Viro</p><p>I was extremely excited to try out React Native, lots of the features appealed to me. Ability to code javascript on iOS, Live previews on your device and on the iOS simulator. Cross-platform coding from the language we learned in school seemed like a no-brainer so I had to give it a shot. Ooo also, if I’m doing a mobile app, I might as well do it in augmented reality. Wishful thinking, I didn’t realize yet.</p><p>Things started off well, I started googling</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yOZshJSY3VOUeh-LyObz0w.png" /></figure><p>and found some promising results.</p><p>Very cool, this video showed me how to create an Augmented Reality app, connecting to <a href="https://poly.google.com/">Google Poly Api</a>, which allowed users to search any Augmented Reality object on the platform and see it augmented in their environment.</p><p>8pm, night before I present: This was going to be easy…class is going to enjoy watching this demo.</p><p>So, I start following along and I download Expo (which is sick btw, if your not trying to do anything in AR)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pDInFIpKm1dEQcSCya1KCA.jpeg" /></figure><p>Expo is a really neat software that offers both a command line environment and online interface to work with React Native. Similar to other React Native API’s. They provide a lot of built in components that you can plug right into your JSX file to make the coding proccess more effiecent. For example, in order to use AR, you can easily add the THREE-EXPO component, which allows you to access three.js from expo, without having to stretch to far.</p><h3>I code along</h3><p>and continue watching the video. Things were going well, although the expo platform updates so often, it took a bit of reorganizing to follow the flow of the video. And then we get up to the cool — part accessing the camera. I could not wait to see how this worked in action. So I set it all up.</p><p><em>Get this error — expo no longer supports augmented reality check out www. for more information</em></p><p><strong><em>Boom!</em></strong></p><p>So I check out their API docs and listed as the first option is ‘AR’, since its the first option im feeling pretty good about it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lX5V9ergV6LEEIq3BvAx1w.png" /></figure><p>9:00pm: I realized AR has been removed from the expo library, so I was no longer able to use it. Close down the video. And started getting very frustrated</p><p>Needed to find another solution…behold this message from Andrew Santos</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Wqf9kDAvs5mniEZfSvpUQ.png" /></figure><p>Master Andrew Santos mentioned that I previous student worked in a platform called Viro React. It looked pretty easy to use, so I checked out their documentation.</p><pre>/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p><em>homebrew install command</em></p><pre>brew install node</pre><p><em>node install command</em></p><pre>yum install watchman</pre><p><em>install watchman</em></p><pre>npm install -g react-native-cli</pre><p><em>install the react command line interface</em></p><pre>npm install -g react-viro-cli</pre><p>install the Viro Command Line Interface</p><pre>npm install -g react-viro-cli</pre><h3>And started working off the documentation</h3><pre>react-viro init ViroSample</pre><h3>Downloaded the Viro app</h3><p><a href="https://itunes.apple.com/us/app/viro-media/id1163100576?mt=8">‎Viro Media</a></p><p>Here’s the link to download the app, it allows you to test out your mobile experience as you are developing. Unike typical iPhone apps, AR, requires the use of the phones camera so you can’t use the xCode simulator. So downloading the app here is a crucial step. Everything was off to a great start</p><h3>10pm: Smooth Sailing</h3><p>Off the bat everything was working well, the Viro sample project, worked as promised and the next step in the documentation was to add components. This looked pretty easy, since its react it all worked by importing different materials</p><pre>./HelloWorldSceneAR.js</pre><pre>import {<br>  ...<br>    ViroBox,<br>  ViroMaterials,<br>} from &#39;react-viro&#39;;</pre><p>and then I created a box under the ViroText component</p><pre>&lt;ViroBox position={[0, -.5, -1]} scale={[.3, .3, .1]} materials={[&quot;grid&quot;]} /&gt;</pre><pre>ViroMaterials.createMaterials({   grid: {     diffuseTexture: require(&#39;./res/grid_bg.jpg&#39;),<br> }, <br>});</pre><p>and added materials to it.</p><h3>Adding 3D objects to the scene</h3><p>Continuing to in the documentation I started adding 3D objects you need to import components Viro3DObject, ViroAmbientLight and ViroSpotLight.</p><p>Add the following to your import statement</p><pre>import {<br>    ...<br>  Viro3DObject,<br>  ViroAmbientLight,<br>  ViroSpotLight,<br>} from &#39;react-viro&#39;;</pre><p>Once your done importing create a new Viro3DObject and import the provided files by viro into your project as the source. Specify the position, scale and type — vrx is a converted 3d object file type</p><pre>&lt;Viro3DObject source={require(&#39;./res/emoji_smile/emoji_smile.vrx&#39;)}            position={[-.5, .5, -1]} scale={[.2, .2, .2]} type=&quot;VRX&quot; /&gt;</pre><p>Position the object in space, give it a scale and specify the type — note their are a lot of different object types, and they are all handled differently in viro. For more information on 3D objects, <a href="https://docs.viromedia.com/docs/3d-objects">view this doc</a></p><h3>Create an AR Plane</h3><p>For it to be AR It needs to be positioned well in space, and Viro offers a great solution. In order to do so import ViroARPlaneSelector into the import statement of your react app. And next add the following code into your ViroARPlaneSelector</p><pre>&lt;ViroARPlaneSelector /&gt;</pre><p>In order to nest the objects in space into the ViroPlane you just wrap the object into the ViroARPlane Selector. And now your all set with a ‘working’ augmented reality project using react. Now that we have some objects in the scene we can spice it up.</p><h3>Image Recognition</h3><p>I finished the documentation and started working on image recognition and tying in</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dZJ_Ma1Ac_ua2xxf9nRRUw.jpeg" /></figure><p>Now the fun ended, both my devices stopped working and after doing some research this problem seems inevitable at least a difficult fix for the time being. So I went to sleep, woke up early this morning, to try to get it to work before the blog presentation this afternoon.</p><p>I realized the payoff wasn’t even worth it and I was stressing out over this blog post to much and this framework.</p><p>After an hour or so additional time spent trying to get the app to work this morning, I decided it was time to call it and instead write a short story on my short-lived experience with augmented reality and javascript.</p><p>So how’s the current state of augmented reality and react — not great.</p><p>Thanks</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5307b8088525" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing AR Experiences on React]]></title>
            <link>https://andyflatiron.medium.com/developing-ar-experiences-on-react-28247ab59a53?source=rss-2b4cf9c25141------2</link>
            <guid isPermaLink="false">https://medium.com/p/28247ab59a53</guid>
            <dc:creator><![CDATA[Andy Flatiron]]></dc:creator>
            <pubDate>Tue, 18 Aug 2020 02:22:33 GMT</pubDate>
            <atom:updated>2020-08-18T02:22:33.827Z</atom:updated>
            <content:encoded><![CDATA[<p>Leveraging React Native and Viro</p><p>To get started, make sure you have Homebrew, Node and Watchman installed. Thank you viro for your documentation and quick start guides which you can find here, I recommend you check those out after reading through this blogpost</p><pre>/usr/bin/ruby -e &quot;$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;</pre><p><em>homebrew install command</em></p><pre>brew install node</pre><p><em>node install command</em></p><pre>yum install watchman</pre><p><em>install watchman</em></p><pre>npm install -g react-native-cli</pre><p><em>install the react command line interface</em></p><pre>npm install -g react-viro-cli</pre><p>install the Viro Command Line Interface</p><pre>npm install -g react-viro-cli</pre><h3>Generate a new project</h3><p>Now that all of that is set up the first thing we want to do is create a new Viro project. Viro has already created in their repo a sample project which you can clone down by using the following command. You must always start your viro projects with react viro init + project name</p><pre>react-viro init ViroSample</pre><h3>Download the Viro app</h3><p><a href="https://itunes.apple.com/us/app/viro-media/id1163100576?mt=8">‎Viro Media</a></p><p>Here’s the link to download the app, it allows you to test out your mobile experience as you are developing. Unike typical iPhone apps, AR, requires the use of the phones camera so you can’t use the xCode simulator. So downloading the app here is a crucial step.</p><h3>Run NPM Start</h3><p>From the newly created project directory run npm start and the package server will be displayed to you with a specific IP address meant to be put into the app. In the below image you will see the output of my terminal response after typing in NPM Start</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DbOiYelnipikiw9IBkqKHg.png" /></figure><h3>Open the Viro App And Enter End Point</h3><p>Use the same endpoint that was outputting to you in the terminal and tap go. Once you hit go the AR experience will initialize and it will bring you to a section where you can choose to move forward with either</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*D2ipTMBka4EZe1bDQ-VoLw.png" /></figure><h3>Hello World!</h3><p>If you set everything up properly, open launching the server, your iOS’s camera should open up and you should see the text “Hello World” superimposed on your space.</p><p>Now to take it up a notch lets add a few more objects and environment tracking, so we can make a real augmented reality experience.</p><h3>Adding Components</h3><p>Since this is React, we know that components are an integral part of the development environment, and Viro AR is no exception. We are going to start by adding a box, to do so we need to start by import Viro Box and ViroMaterials in to react —</p><pre>./HelloWorldSceneAR.js</pre><pre>import {<br>  ...<br>    ViroBox,<br>  ViroMaterials,<br>} from &#39;react-viro&#39;;</pre><p>and next, we&#39;ll create a box under the ViroText component</p><pre>&lt;ViroBox position={[0, -.5, -1]} scale={[.3, .3, .1]} materials={[&quot;grid&quot;]} /&gt;</pre><p>We need to make sure to set the position and scale of the box, to fit within our environment and look well placed next to the text</p><h3>Adding material to the box</h3><p>Since we already defined viro materials in our components we can easily style our component by adding the following code after the styles decleration</p><pre>ViroMaterials.createMaterials({   grid: {     diffuseTexture: require(&#39;./res/grid_bg.jpg&#39;),<br> }, <br>});</pre><p>Once you save and reload the app you should see a pink and grey cube appear on the screen directly under the hello world!</p><p>If you want to restart your server and see your app run again, you can shake your phone and tap reload, which will reload your server.</p><h3>Let’s add some 3D objects to the scene</h3><p>In order to use 3D objects you need to import components Viro3DObject, ViroAmbientLight and ViroSpotLight.</p><p>Add the following to your import statement</p><pre>import {<br>    ...<br>  Viro3DObject,<br>  ViroAmbientLight,<br>  ViroSpotLight,<br>} from &#39;react-viro&#39;;</pre><p>Once your done importing create a new Viro3DObject</p><pre>&lt;Viro3DObject source={require(&#39;./res/emoji_smile/emoji_smile.vrx&#39;)}            position={[-.5, .5, -1]} scale={[.2, .2, .2]} type=&quot;VRX&quot; /&gt;</pre><p>Position the object in space, give it a scale and specify the type — note their are a lot of different object types, and they are all handled differently in viro. For more information on 3D objects, <a href="https://docs.viromedia.com/docs/3d-objects">view this doc</a></p><h3>Lastly, create an AR Plane</h3><p>For it to be AR It needs to be positioned well in space, and Viro offers a great solution. In order to do so import ViroARPlaneSelector into the import statement of your react app. And next add the following code into your ViroARPlaneSelector</p><pre>&lt;ViroARPlaneSelector /&gt;</pre><p>In order to nest the objects in space into the ViroPlane you just wrap the object into the ViroARPlane Selector. And now your all set with a ‘working’ augmented reality project using react.</p><p>Here’s a quick demo of your final outcome!</p><p>Hope you enjoyed</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28247ab59a53" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>