<?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 Gabedotgutierrez on Medium]]></title>
        <description><![CDATA[Stories by Gabedotgutierrez on Medium]]></description>
        <link>https://medium.com/@gabedotgutierrez?source=rss-cf08d488d5c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gqL_xnCgxGH9yegA.jpg</url>
            <title>Stories by Gabedotgutierrez on Medium</title>
            <link>https://medium.com/@gabedotgutierrez?source=rss-cf08d488d5c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:53:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@gabedotgutierrez/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[The Pattern-Matchers Guide To the Universe (Or at least redux)]]></title>
            <link>https://medium.com/@gabedotgutierrez/the-pattern-matchers-guide-to-the-universe-or-at-least-redux-e64b380f716c?source=rss-cf08d488d5c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/e64b380f716c</guid>
            <category><![CDATA[pattern-matching]]></category>
            <category><![CDATA[for-dummies]]></category>
            <category><![CDATA[redux]]></category>
            <dc:creator><![CDATA[Gabedotgutierrez]]></dc:creator>
            <pubDate>Wed, 12 Feb 2020 22:17:05 GMT</pubDate>
            <atom:updated>2020-02-12T22:17:05.148Z</atom:updated>
            <content:encoded><![CDATA[<p>(This might be used later on as an example of the saying “The blind leading the blind”)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*glH-dtdIeiiwdgNRWzAJZA.png" /><figcaption>(Isn’t this thing on top of Dr. Manhattan’s forehead?)</figcaption></figure><p>Greetings dear readers! The following should be used as a supplement to, not in lieu of, an actual intro to redux. What this is more of a diary of how I got my first redux program running, and the concepts (and friends) I’ve found along the way. Also, I’m programming with redux with react. It is fabled in the docs of yore that once could use redux without react… but those concepts have been lost to a humble bootcamp coder such as myself.</p><p>SO YOU WANT TO LEARN REDUX?</p><p>The first thing you should think about if you want to learn redux is do I need to use redux? After creating my first redux app and becoming slightly balder, I can’t say that every app needs it. Redux is a way of front-loading all the frustration of state management. If you app doesn’t need a ton of state/props, or won’t have many components, it might not be worth it. Though at the same time… trying to count how many files and code lines you have to make to make a button that on click says hello world that renders on an index page might be super entertaining (My bet is around 50 lines, please email me and let me know!).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/1*HPQ9sIfnCI4DApVj_f3gmA.jpeg" /><figcaption>If you diagram for components and state look like this, then A: holy crap this program looks awesome. B: yeah you probably need redux.</figcaption></figure><p>So either way, if you think you need redux or if you just wanting to learn, lets get started…</p><pre>npm install --save redux</pre><p>(hey I know I would’ve forgotten to install it if I didn’t say it out loud)</p><p>Ok. Let’s just start with some key concepts in redux. Instead of using state and passing it up and down from our components, we will be using a STORE, which will contain our STATE and ACTIONS. Then we are going to make REDUCERS. REDUCERS are functions that take in the last state and the action, then give out the new state. One of the main parts of Redux is that people should not be able to make functions that can make more than one result. So because of this reducers are used as an intermediary between store and actions.</p><p>So how would I start making a redux app? Let’s start with your index layer.</p><pre>import React from &#39;react&#39;</pre><pre>import { render } from &#39;react-dom&#39;</pre><pre>import { Provider } from &#39;react-redux&#39;</pre><pre>import { createStore } from &#39;redux&#39;</pre><pre>import reducer from &#39;./reducers&#39;</pre><pre>import App from &#39;./components/App&#39;</pre><pre>const store = createStore(Reducer)</pre><pre>render(</pre><pre><br>&lt;Provider store={store}&gt;</pre><pre>&lt;App /&gt;</pre><pre>&lt;/Provider&gt;,</pre><pre>document.getElementById(&#39;root&#39;)</pre><pre>)</pre><p>So whats happening here? Since this is the top layer of application, it makes the most sense to have everything to start using redux here. After installing the redux library you have access to the create store command, and the &lt;provider&gt; tags. Wrap those tags around &lt;APP/&gt; so that you can have access to the redux library throughout the entire application. After doing this, you declare your store with the line const store = createStore(Reducer) And the reducer there will be the name of the reducer file that you will be making. In the future and in real life there might be multiple reducers that can be combined… but I haven’t gotten there yet. I will only be showing how to make a program with a single reducer.</p><p>Now for reducers: in the same folder, I created a file called reducer.js. (you can see it being imported in the top of the index file above). In this file I created the initial state and started to make the actions that I want to be using in the rest of my program. To declare the state in your store that you will be pulling from in various parts, do this.</p><pre>let defaultState = {</pre><pre>//our centralized state goes here</pre><pre>key : &quot;defaultvalue&quot;,</pre><pre>}</pre><p>This is declared in the same way you’d do any other app state in your program before redux. Reducer actions will be made in this way:</p><pre>let reducer = (prevState=defaultState, action) =&gt; {</pre><pre>switch(action.type){</pre><pre>      case &#39;STATECHANGE&#39;:</pre><pre>             return {...prevState,</pre><pre>                     key: &quot;new value&quot;</pre><pre>                   }<br>       default:</pre><pre>         return prevState //do what previously happens, just a good         catchall.</pre><pre>    }</pre><pre>}</pre><p>So here we start to describe our actions. When you do this, make it into a full switch case. What we are doing in each time a reducer is called, is making a new state which is what the old state was (…prevState) and the change to the new state. When naming your actions, make sure they are in ALLCAPS, because we are in THE CRUISE CONTROL FOR COOL (also it’s naming convention and helps us out greatly.</p><p>Above is a reducer for a state change without any value being brought into the reducer (think of a onClick without a value as an example). but what if you need a value being passed up? Like in a form or text box for example? You declare the thing being lifted into this reducer as PAYLOAD.</p><pre>case &#39;CHANGEWVALUE&#39;:</pre><pre>return {...prevState,</pre><pre>key: action.payload.value</pre><pre>}</pre><p>This will use a value being put into program back into the reducer.</p><p>An optional thing that I would recommend to do is make action creators. they’ll work as another intermediary between our dispatch and our components. here’s an example of our actioncreators for the two dispatch actions we’ve made before.</p><pre>const CHANGEWVALUE = &quot;CHANGEWVALUE&quot;</pre><pre>const STATECHANGE = &quot;STATECHANGE&quot;</pre><pre>const stateChangeCreator = () =&gt; ({type: STATECHANGE})</pre><pre>const changeWValueCreator = (value) =&gt; ({type: CHANGEWVALUE, payload{value})</pre><pre><br>export{</pre><pre>stateChangeCreator,<br>changeWValueCreator</pre><pre>}</pre><p>You can see how this plugs back into the reducer and how the payload will later on be loaded onto the component.</p><p>Finally, this is my template for any new component I make. Which will have a bunch of stuff that might not be necessary but I’ll walk you through it so you can see what you need or don’t for yourself. (I’m also including the stored actions and reducers I put in above in there).</p><pre>import React from &#39;react&#39;</pre><pre>import { connect } from &#39;react-redux&#39;;</pre><pre>import {stateChangeCreator, changeWValueCreator } from &#39;../actionCreators&#39;</pre><pre>class template extends React.Component{</pre><pre>state = {</pre><pre>}</pre><pre>render(){</pre><pre>   return(</pre><pre>     &lt;div&gt;</pre><pre>         &quot;Hello world!&quot;</pre><pre>     &lt;/div&gt;</pre><pre>         )</pre><pre>      }</pre><pre>}</pre><pre>const MSP = (state) =&gt; {</pre><pre>   console.log(`MSP`,state)</pre><pre>        return {</pre><pre>           key: state.key</pre><pre>           }</pre><pre>}</pre><pre>const MDP = (dispatch) =&gt; {</pre><pre>      return {</pre><pre>                stateChange: () =&gt; dispatch(stateChangeCreator()),</pre><pre>                changeWValue: (value) =&gt;         dispatch(changeWValueCreator(value))</pre><pre>             }</pre><pre>}</pre><pre>export default connect(MSP, MDP)(template);</pre><p>The first couple of lines should be pretty familiar, with the exception that you MUST import all your actions from the action creator (since they’re from a different file). Also I have local state declared here. Will all your components need local state? No. Should you put everything in the store? Also no. However, it’s good to know that if you need to use local state you can in any of your components in the same way you did before redux. Think of things that you wouldn’t need to persist into the store, such as some handle changes, and just leave em here on the page.</p><p>On the bottom, after the render, is the fruits of our labor. It’s where we can pull things in and out of our store. MSP and MDP stand for Map State to Props and Map Dispatch to Props respectively. In these things you can declare whatever you need to use on your component and call them by using this.props.x (where x is the thing you want to use). For example, this.props.key would give me the value for key which I declared in the initial state. and this.props.stateChange will change that state. this.props.changeWValue takes an argument of an object to change the state as a payload. These are pretty much all the things you’re going to be doing with redux over and over again.</p><p>I hope that this tutorial helps out just a little bit to see the EXTREME basics of redux and how to use it in your apps. I wish you all good luck</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e64b380f716c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reading multiple coding languages, gaming in the 90s, the holy grail of firepower, everything is…]]></title>
            <link>https://medium.com/@gabedotgutierrez/reading-multiple-coding-languages-gaming-in-the-90s-the-holy-grail-of-firepower-everything-is-8323f60c4429?source=rss-cf08d488d5c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/8323f60c4429</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[loopring]]></category>
            <category><![CDATA[code]]></category>
            <category><![CDATA[id-software]]></category>
            <category><![CDATA[bfg]]></category>
            <dc:creator><![CDATA[Gabedotgutierrez]]></dc:creator>
            <pubDate>Thu, 23 Jan 2020 15:39:40 GMT</pubDate>
            <atom:updated>2020-01-23T15:39:40.728Z</atom:updated>
            <content:encoded><![CDATA[<h3>Reading multiple coding languages, gaming in the 90s, the holy grail of firepower, everything is math… AND YOU!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*v1zdhG3NqKK_THDApMDD5Q.jpeg" /><figcaption>And so, my public speaking here comes to a close</figcaption></figure><p>As our time in Flatiron school, receiving lectures on code come to a close, it is super interesting to see how the world around you changes. There is a fair amount of it seems more…. readable. As a self-proclaimed video game addict, I went back to investigate all the code that I found so baffling and magical when I was a kid/teenager. Enter… DOOM, and it’s original super-weapon, the BFG (Big Friendly Gun) 9000.</p><pre>//<br>// A_BFGSpray<br>// Spawn a BFG explosion on every monster in view<br>//<br>void A_BFGSpray (mobj_t* mo) <br>{<br>    int			i;<br>    int			j;<br>    int			damage;<br>    angle_t		an;<br>	<br>    // offset angles from its attack angle<br>    for (i=0 ; i&lt;40 ; i++)<br>    {<br>	an = mo-&gt;angle - ANG90/2 + ANG90/40*i;<br><br>	// mo-&gt;target is the originator (player)<br>	//  of the missile<br>	P_AimLineAttack (mo-&gt;target, an, 16*64*FRACUNIT);<br><br>	if (!linetarget)<br>	    continue;<br><br>	P_SpawnMobj (linetarget-&gt;x,<br>		     linetarget-&gt;y,<br>		     linetarget-&gt;z + (linetarget-&gt;height&gt;&gt;2),<br>		     MT_EXTRABFG);<br>	<br>	damage = 0;<br>	for (j=0;j&lt;15;j++)<br>	    damage += (P_Random()&amp;7) + 1;<br><br>	P_DamageMobj (linetarget, mo-&gt;target,mo-&gt;target, damage);<br>    }<br>}</pre><p>Above is the code for the magical powers of the BFG 9000, the original power weapon. To translate it to todays terms, the BFG was the first ultimate, a lightning bolt duct taped to a blue shell, an 3 bar super combo, and getting 25 kills in COD all rolled into one.</p><p>Some of the greatest things about the age we live in today is that we have the entire history of code to read at our fingertips. Doom source code was released at the end of the 90s. You can even find it today as a github repository. <a href="https://github.com/id-Software/DOOM">https://github.com/id-Software/DOOM</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*oVDG353gUetU24wX0KVbBw.gif" /><figcaption>listen to your elders, etc etc</figcaption></figure><p>So why doom? Aside from the point that it’s my blog post and I can do what I want. Doom, released in 1993, lands a gaming milestone and one that we can all read. It was one of the first truly 3d games (even if it’s a bit more complicated in that even though there is a z axis.. it’s extremely limited in the way that you can’t layer one z axis over another… blog post in a blog post anyone?). Also, doom is coded in C for computers, so it’s tons more readable than code made for specific consoles (most of which will never open source their games). Lastly, doom is deceptively simple. the repo on github is slightly under 500kb (it’s missing maps and music and various other assets). When it was released, the free version of doom was released on 2 3.5&quot; floppy disks… totaling around maybe 3MB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*xAeKNjpBWtzHGzzLe6lJVA.jpeg" /><figcaption>thanks, john.</figcaption></figure><p>So why the BFG? Aside from its devastating power in the videogame, the limitations of the time has always made it sort of mysterious in how it works. From what you’d expect when you see it, you’d expect it work logically, as a giant green ball that explodes and does damage to the world around it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*6oygEoccDz4GOub0WPtEiA.gif" /><figcaption>sorry this is the best gif I can find.</figcaption></figure><p>But it often didn’t work as you’d expect due to the code we saw above. Due to what I’d assume is hardware limitations (computers at the time were infinitely less powerful than your smart phone 5 years ago), the damage radius does not come from the green ball seen above, but from invisible rays coming out of the player once the green ball hits.</p><p>So let’s go back to the code. The direct hit damage is calculated below. It’s a simple one line computation that seems to use a random number generator and adding 1 to it.</p><pre>damage = ((P_Random()%8)+1)*tmthing-&gt;info-&gt;damage;</pre><p>But the very interesting one, and the one that we can make inferences on due to our ability to code, is the one I previously posted. This one computes the surrounding damage from the weapon.</p><pre>//<br>// A_BFGSpray<br>// Spawn a BFG explosion on every monster in view<br>//<br>void A_BFGSpray (mobj_t* mo) <br>{<br>    int			i;<br>    int			j;<br>    int			damage;<br>    angle_t		an;<br>	<br>    // offset angles from its attack angle<br>    for (i=0 ; i&lt;40 ; i++)<br>    {<br>	an = mo-&gt;angle - ANG90/2 + ANG90/40*i;<br><br>	// mo-&gt;target is the originator (player)<br>	//  of the missile<br>	P_AimLineAttack (mo-&gt;target, an, 16*64*FRACUNIT);<br><br>	if (!linetarget)<br>	    continue;<br><br>	P_SpawnMobj (linetarget-&gt;x,<br>		     linetarget-&gt;y,<br>		     linetarget-&gt;z + (linetarget-&gt;height&gt;&gt;2),<br>		     MT_EXTRABFG);<br>	<br>	damage = 0;<br>	for (j=0;j&lt;15;j++)<br>	    damage += (P_Random()&amp;7) + 1;<br><br>	P_DamageMobj (linetarget, mo-&gt;target,mo-&gt;target, damage);<br>    }<br>}</pre><p>It’s crazy to see how much of this code is similar to what we see today. The comments are done in the same way //. void A_BFGSpray (mobj_t* mo) looks like a declaration. And with a simple google search, I can find out that void is declaring a function without a return! The next 4 lines, 3 of them are int declarations for variables, are similar to how we declare tables in rails. The first line after that is a for loop! A FOR LOOP! EXACTLY CODED IN THE WAY WE DO IN JS! Counting from 1–40 and on each iteration giving us parts of 90/40. This is because the damage is fanning out from the player at a 90 degree angle (around the field of view of the player) and fanning 40 rays during that time.</p><p>And that if statement! Again! Written closely to what we know in JS. The conditional if exists, and again checking over with my good friend Mr. Google, the bang operator still works as a the logical negation of a value. Granted, I don’t know anything around the P_spawnMobj part of the code… below that is another for loop! After a declaration of damage to be 0. and we can see how the damage ticks up for each iteration of the loop! The damage is being added to on every iteration of the loop, 15 times (16 including the first loop), with a random number generator making each tick as somewhere from 1–8 damage. Even though I do not know C, haven’t programmed video games, and didn’t know any sort of math at the time of this being made… we can kind of read this! And that in itself is sort of amazing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/336/1*lUjyzxCv8KDoXbYKs2xHBQ.gif" /><figcaption>A nice image from the FAQ I pulled this info from.</figcaption></figure><p>So, going forward from here, and knowing that the world of coding will always change. Know that even though languages change, a lot of the problems they intend to solve are similar. Here we can see a 25 + year old piece of code, doing what we attempt to do today. It declares variables, uses loops and even groups chunks of code by indents and brackets. Understand that, though it will be hard, we now have an entry point into the world of code, and we will be able to mutate our knowledge to other forms. From the beginning that my dad tells me of (the boomer who lords over this boomer, lol) that involves giant punch card machines in basements of his college, to the smart phone in your hand, and finally to the sentient AI that I’m sure will one day rule the world, all are created with similar objects and commands. And I, for one, think that’s pretty cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/200/1*BioO66syvzuHMBgK3H_Aaw.png" /><figcaption>(yes, this is the only OTHER safe for work img from the doom comic I could pull.)</figcaption></figure><p>Addendum:</p><p>I think also another fun semi-related thing is how my ability to understand html and the console made me reading the info for this blog post alot easier. BEHOLD HTML ONLY WEBSITES FROM BEFORE 2000!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g3zQPOpP5M6WuMt6Pisd8Q.png" /></figure><p>MY EYESSSS!!!! MY FELIX GRAYS, THEY DO NOTHING.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cYgpsRPh-9WTDJSEZxWeUA.png" /></figure><p>Phew!</p><p>Further reading:</p><p><a href="http://www.gamers.org/docs/FAQ/bfgfaq/">http://www.gamers.org/docs/FAQ/bfgfaq/</a> — The website I pulled the code from (also you should delete the background layer for your eyes sake too).</p><p><a href="https://www.youtube.com/watch?v=_0KBAZkPFmI">https://www.youtube.com/watch?v=_0KBAZkPFmI</a> A video made that shows the really odd behavior that sparked me looking up the code.</p><p><a href="https://github.com/id-Software">https://github.com/id-Software</a> id-softwares github, hosting open source repositories of doom, quake and quake 3. (interestingly enough, quake’s code for 3d movement is still used today in many modern games.)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8323f60c4429" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Canvas, the laments of a boomer, not using divs, and you!]]></title>
            <link>https://medium.com/@gabedotgutierrez/canvas-the-laments-of-a-boomer-not-using-divs-and-you-819cba416242?source=rss-cf08d488d5c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/819cba416242</guid>
            <category><![CDATA[html5]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[canvas]]></category>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[animation]]></category>
            <dc:creator><![CDATA[Gabedotgutierrez]]></dc:creator>
            <pubDate>Thu, 09 Jan 2020 07:59:20 GMT</pubDate>
            <atom:updated>2020-01-09T08:10:04.512Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/264/1*qV5-g7g7GENP5TskVy28CQ.jpeg" /><figcaption>Or: There and back again</figcaption></figure><p>Hey buddies! Are you tired of drawing things in divs? Is your imagination constrained by filling in html elements and do you dream of making a circle without posting an image? Worry not dear friends! There is a way! <em>HTML CANVAS</em>! FRIEND OF APPLE, VANQUISHER OF FLASH!</p><h3>In the beginning, there was the html line:</h3><p>Today I want to make a website that says a message. “Hey! I want to be happy” I say. “Lets hello world ourselves to say that we’re having a great day!”… Then the limits of HTML seem to hit you straight on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*IL3ZscrQU7kl9JcDLi0qog.png" /><figcaption>oh god.</figcaption></figure><p>And to code all of that…..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*UWuxTEWGIdKWQEvs04vbGA.png" /><figcaption>I used a generator for this btw…</figcaption></figure><h3>There must be a better way…</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/1*Q5efQ32C7LFEEyCQmvDYAw.jpeg" /></figure><p>So how, instead, do we draw on webpages without just creating a grid of elements? HOW THE HELL DO WE MAKE A CIRCLE? Enter… Canvas. From MDN:</p><blockquote>“<a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas"><strong>&lt;canvas&gt;</strong></a> is an <a href="https://developer.mozilla.org/en-US/docs/Web/HTML">HTML</a> element which can be used to draw graphics via scripting (usually <a href="https://developer.mozilla.org/en-US/docs/Glossary/JavaScript">JavaScript</a>). This can, for instance, be used to draw graphs, combine photos, or create simple (and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/A_basic_ray-caster">not so simple</a>) animations. The images on this page show examples of <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas"><strong>&lt;canvas&gt;</strong></a> implementations which will be created in this tutorial.”</blockquote><p>So today we’re going to discuss canvas elements, what they are, and do some basic shapes and manipulations. We will make a few basic shapes, go about animating them and even go into some theory on how to manipulate/interact/animate them now that they are objects!</p><h3>A prequel story:</h3><p>Before we get to canvas, I want to start off with an aside to the previous technology that html5 replaced: Flash. Flash is/was a 3rd party browser program created to handle graphics inside html. Even though this isn’t the focus of my blogpost, I want to give a shoutout to Flash. Flash animation and websites like newgrounds was peak teenage Gabe. Programming in Flash was extremely graphically inclined. Though I’ve never worked with it personally, Flash game programming was known to be delegated equally in graphics and code. So cheers to you Flash, you bloated, not very secure program that gave me years of not safe for work fun. Rest in peace, too bad Steve Jobs killed you by making you not phone compatible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*_JIpAWVElXiXhqgW" /><figcaption>this would be a pretty good blog post too.</figcaption></figure><h3>Let’s start a canvas!</h3><p>So making a canvas is easy! In html, just use the canvas tags. ex: &lt;canvas id=”myCanvas” width=”480&quot; height=”320&quot;&gt;&lt;/canvas&gt;. Doing this there’s a few things we can note. First of all, the two parameters, width and height. When making your canvas and making coordinates, know that all your coordinates will be ascending left to right and up to down. As in, 0/0 will be the top left corner of your canvas, and in this case 480/320 will be the bottom right of the canvas. This is kind of opposite of most graphs we see that start from the bottom left corner and go to the top right. The second thing we should notice is that canvas is a native html element! As such you can run css on it! Some of the most important css you can run on it is that you can fill it in with a color to make it more visible (in my example code I fill it in with light grey). Also you can change it’s z-index to lay multiple layers of canvas on top of each other! My project used this but I’m not doing this for the blogpost.</p><h3>Making shapes!</h3><p>So finally we have our canvas with the id of myCanvas. Let’s draw some shapes! To do so first you need to get the context of the canvas. I honestly don’t have a reason why other than it’s necessary, and that they haven’t fully coded 3d canvas yet as far as I know. To do so run these two lines of code.</p><pre>let canvas = document.getElementById(&quot;myCanvas&quot;); <br>let ctx = canvas.getContext(&quot;2d&quot;)</pre><p>After this we’re going to use the ctx variable alot. Drawing shapes in js runs a pretty basic pattern. 1 begin a path. 2. Actually pick out what shape we are drawing and it’s coordinates and parameters. 3. Fill in said shape, or draw a line around said shape 4. Close the path.</p><p>Let’s start this out by making the most perfect of shapes: a circle. Here is my code for a circle, and let’s investigate it.</p><pre>ctx.beginPath();<br>ctx.arc(150, 160, 150, 0, Math.PI*2, false);<br>ctx.fillStyle = &quot;yellow&quot;;<br>ctx.fill();<br>ctx.closePath();</pre><p>First we begin our path. Then I make an arc. The first two parameters of this arc are the x y coordinates of the center. the second 2 are the beginning and end of the arc path in radians. I have the math skills of a 6 year old who’s been hit in the head, so here’s an image to reference to see what that means. The last option being false is the direction the arc is being drawn. False is clockwise, true is counterclockwise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/302/0*4KOomDLCScyrBo9U.gif" /><figcaption>radians, so to make a full circle it’ 0 to math pi 2.</figcaption></figure><p>Here’s the result of the code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/806/1*oJOeq2mfSux2bZEZ5HTQ4Q.png" /></figure><p>Now lets make some rectangles!</p><p>Rectangles are a bit easier, first two parameters is the top left corner of the start of the box. The second two are the width and height of the item.</p><pre>ctx.beginPath();<br>ctx.rect(70, 40, 50, 125);<br>ctx.fillStyle = &quot;black&quot;;<br>ctx.fill();<br>ctx.closePath();</pre><p>result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*QiLu6mDMLowabMlhBFjAdw.png" /></figure><h3>Now lets put it all together!</h3><p>So lets layer a few of these shapes onto a canvas together! Here’s my code!</p><pre>ctx.beginPath();<br>ctx.arc(150, 160, 150, 0, Math.PI*2, false);<br>ctx.fillStyle = &quot;yellow&quot;;<br>ctx.fill();<br>ctx.closePath();</pre><pre>ctx.beginPath();<br>ctx.rect(70, 40, 50, 125);<br>ctx.fillStyle = &quot;black&quot;;<br>ctx.fill();<br>ctx.closePath();</pre><pre>ctx.beginPath();<br>ctx.rect(170, 40, 50, 125);<br>ctx.fill();<br>ctx.closePath();<br> <br>ctx.beginPath();<br>ctx.arc(140, 200, 50, 0, Math.PI*1, false);<br>ctx.fillStyle = &quot;red&quot;;<br>ctx.fill();<br>ctx.closePath();</pre><p>Can you guess what it’s gonna make?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/962/1*JurULHqzQExmOKqAQI0tyA.png" /><figcaption>joy.</figcaption></figure><h3>Beyond the shapes</h3><p>So now that we have established shapes, that are created through math, one can make a ton of fun transformations using them. I both don’t have the ability to make all of them nor do I have the time to explain them. but lets start with a simple animation. To start, lets wrap all our face drawing into a function. I named mine drawSmile.</p><p>Animation in canvas is actually the action of drawing the same thing over and over again on the canvas, clearing the canvas after every frame. to clear your canvas, run ctx.clearRect(0, 0, canvas.width, canvas.height);. In this case, the first two parameters are the beginning of the clearing portion. The second two, lucky for us, are just parameters we have for the full size of the canvas given to us by html.</p><p>Knowing this, I made an x variable of 0, and added it to all the x coordinates of my draw. I made a simple loop.</p><pre>function moveSmile(){<br>  ctx.clearRect(0, 0, canvas.width, canvas.height);<br>  drawSmile()<br>    x += 1<br>}</pre><p>First, I clear the canvas. Then I draw my smile. Then I move over the x coordinate by 1. I then attach this to a set interval.</p><pre>setInterval(moveSmile, 50);</pre><p>EVERYONE LETS SEE THE RESULTS!</p><p><a href="https://jsfiddle.net/MarioBland/8z23spmL/19/embedded">https://jsfiddle.net/MarioBland/8z23spmL/19/embedded</a></p><p>Thank you! and there’s a ton more you can learn about canvas! Here’s some further reading.</p><p>Further reading:</p><p>Reply All episode about flash, interview with Tom Fulp, founder of newgrounds at ~20min <a href="https://gimletmedia.com/shows/reply-all/j4hlx6">https://gimletmedia.com/shows/reply-all/j4hlx6</a></p><p>MDN’s tutorial of making a fully working breakout game in html5</p><p><a href="https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript">https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript</a></p><p>Slime volleyball. One of the first html5 games that I knew of:</p><p><a href="http://marler8997.github.io/SlimeJavascript/SlimeVolleyballLegacy.html">http://marler8997.github.io/SlimeJavascript/SlimeVolleyballLegacy.html</a></p><p>Code here</p><p><a href="https://github.com/marler8997/SlimeJavascript/blob/master/SlimeVolleyball.html">https://github.com/marler8997/SlimeJavascript/blob/master/SlimeVolleyball.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=819cba416242" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[APIS, GOOGLE LIBRARY, A MILLION MONKEYS, TEST DRIVEN DESIGN…AND YOU!]]></title>
            <link>https://medium.com/@gabedotgutierrez/apis-google-library-a-million-monkeys-test-driven-design-and-you-c28b1dd04416?source=rss-cf08d488d5c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/c28b1dd04416</guid>
            <category><![CDATA[flatiron-school]]></category>
            <category><![CDATA[experiment]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Gabedotgutierrez]]></dc:creator>
            <pubDate>Thu, 21 Nov 2019 15:59:28 GMT</pubDate>
            <atom:updated>2019-11-21T15:59:28.850Z</atom:updated>
            <content:encoded><![CDATA[<ul><li><em>an adventure of learning through useless code</em>.</li></ul><p>Over the last week we were introduced into APIs through the Google Library. Sadly (or not sadly) I never got to use it. But after my (spectacular, marvelous, show-stopping) mod 1 project I came to a realization!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*14MOW7CowZzfh3ZSvgKs7Q.gif" /><figcaption>(goodbye sunday)</figcaption></figure><p>And now that I have the power of using APIS. It’s time to misuse it. A man once said “With great power comes great responsibility”. It’s time to find out what happens when you have great power and pretty much 0 responsibility. Enter… the infinite monkey theorem.</p><p>WITH INFINITE MONKEYS, COMES INFINITE POWER.</p><p>The<em> infinite monkey theorem </em>is a thought experiment created in the early 1900s to explain the idea of extremely improbable as compared to impossible. Moreover (and in my case, most importantly) if thought about literally, IT WOULD BE HILARIOUS. It goes somewhat as such — If there were an infinite amount of monkeys typing for an infinite amount of time, there is a chance *though infinitesimally small* that the monkeys would produce Shakespeare. If we think that there are 26 letters in the alphabet and 28 key presses with the spacebar and enter key, at some point there is a chance that BY RANDOM a monkey could type out Shakespeare. This is *NOT* however, completely impossible, unlike me breathing in outer space, or my dear Mets winning the World Series.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*1Rl0CWsMlNBxE3O43WLFpw.gif" /><figcaption>(but also, the idea of monkeys typing is hilarious.)</figcaption></figure><p>So how do we, with the power of BIG DATA make something similar to this? First I’m gonna find a text. And what better text than one narrated by a monkey. One that describes our almost sisyphean task.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2rOAr8QZDRiIv3XlAj78GA.jpeg" /><figcaption>(I know, he’s a scientist. Also if you got this far and are complaining, well that’s your fault)</figcaption></figure><p><em>(from Henry V, spoken by King Henry)</em></p><p><em>Once more unto the breach, dear friends, once more;</em></p><p><em>Or close the wall up with our English dead.</em></p><p><em>In peace there’s nothing so becomes a man</em></p><p><em>As modest stillness and humility:</em></p><p><em>But when the blast of war blows in our ears,</em></p><p><em>Then imitate the action of the tiger;</em></p><p><em>Stiffen the sinews, summon up the blood,</em></p><p><em>Disguise fair nature with hard-favour’d rage;</em></p><p><em>Then lend the eye a terrible aspect;</em></p><p><em>Let pry through the portage of the head</em></p><p><em>Like the brass cannon; let the brow o’erwhelm it</em></p><p><em>As fearfully as doth a galled rock</em></p><p><em>O’erhang and jutty his confounded base,</em></p><p><em>Swill’d with the wild and wasteful ocean.</em></p><p><em>Now set the teeth and stretch the nostril wide,</em></p><p><em>Hold hard the breath and bend up every spirit</em></p><p><em>To his full height. On, on, you noblest English.</em></p><p><em>Whose blood is fet from fathers of war-proof!</em></p><p><em>Fathers that, like so many Alexanders,</em></p><p><em>Have in these parts from morn till even fought</em></p><p><em>And sheathed their swords for lack of argument:</em></p><p><em>Dishonour not your mothers; now attest</em></p><p><em>That those whom you call’d fathers did beget you.</em></p><p><em>Be copy now to men of grosser blood,</em></p><p><em>And teach them how to war. And you, good yeoman,</em></p><p><em>Whose limbs were made in England, show us here</em></p><p><em>The mettle of your pasture; let us swear</em></p><p><em>That you are worth your breeding; which I doubt not;</em></p><p><em>For there is none of you so mean and base,</em></p><p><em>That hath not noble lustre in your eyes.</em></p><p><em>I see you stand like greyhounds in the slips,</em></p><p><em>Straining upon the start. The game’s afoot:</em></p><p><em>Follow your spirit, and upon this charge</em></p><p><em>Cry ‘God for Harry, England, and Saint George!’</em></p><p>So now that we have our goal, and have our monkeys. Let’s map out some goals for our program.</p><p>First, we need to get the text. To be kind to my fellow primates, I’m going to take it easy on them. First of all, we will be culling ONLY the first 4 lines, because any more than that in a test will make me turn into an angry ape. ALSO we will only be worried about characters and spaces, no punctuation, no capitalization. This gives our monkeys a 1/28 chance of getting the right character at every keystroke, which… might not be as bad? (It’s still very close to impossible.).</p><p>Then for our monkeys, they have to spit out random keys (26 letters in the alphabet + space + newline), that would fit the same amount of characters in the first 4 lines of Shakespeare. This is, well, a collection of deliverables and methods I’ve just mapped here.</p><p>Call -</p><ul><li>Calls google api</li><li>Retrieves king henrys speech</li></ul><p>Sharksphere -</p><ul><li>From that speech cut the first 4 lines.</li><li>From that culled speech, convert all words into lowercase, remove punctuation.</li><li>Returns in a format that can be compared to our monkeys.</li></ul><p>Monkeys -</p><ul><li>Randomly chooses from 26 letters, spaces, and newlines (/n).</li><li>Returns the same amount of characters that are in the original text.</li><li>Saves this text to be tested</li></ul><p>Test -</p><ul><li>Will compare the Sharksphere output with the Monkey output.</li><li>*also note, this will almost always fail in the end.</li></ul><p>STEP ONE — CALL</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/636/1*OTEtQBhOrugFhJVE7LYf_w.jpeg" /></figure><p>Later on Sunday evening….</p><p>Well guys, I’m going to call (pun intended) it, I can’t seem to find a way to get the full text of Henry the fifth online. I can find the text by using this call. Using <a href="https://www.googleapis.com/books/v1/volumes?q=henryV">this</a> lets you into the text that I want to look for, but getting the full text of that speech is not available in the api as I see it. It is available at your local library!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jtHaXZuE6cIksbgU-fv6IA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*WGhMTv-dzGgLR6IWqSj3fQ.gif" /></figure><p>(As far as I got before I needed an e-reader)</p><p>STEP TWO- SHARKSPHERE</p><p>For step two, I had to format my quote into something comparable and actionable. I had to convert it into a format that I can send over to my monkeys. THERE’S RULES TO THIS GAME PEOPLE. So I decided to use an array as my format. This gives me some distinct advantages, with an array I can:</p><ul><li>Lowercase all letters</li><li>Remove all special characters</li><li>Get the length of the array, so our monkeys know when to stop.</li><li>Compare to an array of monkeys.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*D22olt8c_79wXb_wNDeK9A.png" /></figure><p>This returns us a collection of letters in an array that make up the speech, removing all special characters and lowercasing all of them.</p><p>Now we have to move to the monkeys.</p><p>STEP THREE -HEY HEY WE’RE THE MONKEYYYSSS</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q4BmGS-qHobrJJxRRcCDYA.jpeg" /></figure><p>To make a monkey typing randomly on a keyboard we have two random methods in ruby, RAND and SAMPLE. Rand gives you a random number, which can be given an argument of a range. Sample takes the argument of an array, which is super useful for our situation. Here I created an array of all lowercase letters, a space, and /n, which is a newline character. After that I do this random action as many times as the Shakesphere quote is long.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*IvH8j-OgV5w1c9dJB3_pUg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*hK_niwoN1V2yVFaj09whMA.png" /></figure><p>AND FINALLYYYYYY THE TEST ITSELF</p><p>Ok! Now we have our Shakesphere quote, formatted for our test, and our monkeys, ready and willing to knock this ball out of the park. LETS SEE HOW THIS GOES!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*3hc68tZLN4GvJi78cMWI4A.png" /></figure><p>DRUMROLL PLEASEEEE….</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*pE_bheTEGSe0P_mezrk3hQ.png" /></figure><p>EPILOUGE</p><p>In conclusion…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*3UCT-IKpon7RkX-sEJF4jw.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c28b1dd04416" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>