<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-3583660468885673865</id><updated>2024-10-03T16:46:47.811-04:00</updated><title type='text'>Code Journal</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gjmiles.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3583660468885673865/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://gjmiles.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>GJMiles</name><uri>http://www.blogger.com/profile/10460788817115186917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>2</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-3583660468885673865.post-7693497838298896971</id><published>2013-05-17T01:29:00.003-04:00</published><updated>2013-05-17T11:50:14.436-04:00</updated><title type='text'>Super Duper Simple Animation Using HTML5 canvas element and JavaScript Tutorial</title><content type='html'>Ok so I have been using &lt;a href=&quot;http://codecademy.com/&quot; target=&quot;_blank&quot;&gt;codecademy&lt;/a&gt;, which is great to get people started on coding but I feel that codecademy needs to stress more going beyond codecademy &amp;nbsp;to advance coding skills.&lt;br /&gt;
&lt;br /&gt;
Anyways, I still think codecademy is pretty cool and this post is based on a codecademy lesson called &quot;Project: Draw with JavaScript&quot;. &lt;br /&gt;
&lt;br /&gt;
The lesson is pretty well described by the title and it teaches people how to use HTML5 and javascript to draw on the screen which is pretty sweet. &amp;nbsp;So I took the lesson one step further and decided to learn how to do some really simple animations using this&amp;nbsp;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/HTML/Canvas/Tutorial/Basic_animations?redirectlocale=en-US&amp;amp;redirectslug=Canvas_tutorial%2FBasic_animations&quot; target=&quot;_blank&quot;&gt;mozilla tutorial&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Main Code and Results&lt;/h3&gt;
Here is what I got:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;iframe allowfullscreen=&quot;allowfullscreen&quot; frameborder=&quot;0&quot; height=&quot;300&quot; src=&quot;http://jsfiddle.net/gjmiles/PL2F5/embedded/result/&quot; width=&quot;50%&quot;&gt;&lt;/iframe&gt;

&lt;br /&gt;
&lt;br /&gt;
I am going to go over the animation portions of the code, if you want to learn the other parts I suggest checking out codecademy because it gives a great rundown. &amp;nbsp;If you are using the right browser you should be able to see that the code is just rotating a square and text on a screen (HTML5 canvas tag is not supported by certain IE browsers).&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
HTML code&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Here is the html code is used by the function:&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;script class=&quot;brush:html&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
    &lt;body&gt;
        &lt;canvas id=&quot;canvas&quot; width=&quot;200&quot; height=&quot;200&quot;&gt;
            This text is displayed if your browser does not support HTML5 Canvas.
        &lt;/canvas&gt;
      &lt;/body&gt;
]]&gt;&lt;/script&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
init() function and JavaScript code&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
The first part of setting up a animation involves setting up your init() function:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;script class=&quot;brush:js&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
function init(){
    beware();
    setInterval(beware,120);
}
]]&gt;&lt;/script&gt;

In the init() function it will run whatever functions you put inside and it is also where you want to load any images that you will use in your animation. &amp;nbsp;It is also where you want to call the function which will be handling the actual animation, in this case &amp;nbsp;it is setInterval(animationFunction,time in milliseconds). &amp;nbsp;Also it is important to&amp;nbsp;remember&amp;nbsp;to declare the init() function elsewhere in your script!&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
JavaScript code for beware() function&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
Next up is the beware() function, which is used to run the animation.&lt;br /&gt;
&lt;script class=&quot;brush:js&quot; type=&quot;syntaxhighlighter&quot;&gt;&lt;![CDATA[
function beware(){
    
var my_canvas = document.getElementById(&#39;canvas&#39;);
var context = my_canvas.getContext(&quot;2d&quot;);
context.clearRect(0,0,200,200);

context.beginPath();
context.arc(100,100,100,0,2*Math.PI);
context.stroke();

context.save();
context.translate(100,100);

var time = new Date();
 
context.rotate( ((2*Math.PI)/60) * time.getSeconds() + ((2*Math.PI)/60000) * time.getMilliseconds() );

context.fillStyle = &quot;#DC143C&quot;;
context.fillRect(-50,-50,100,100);

context.fillStyle = &quot;#8B008B&quot;;
context.font = &quot;20px Garamond&quot;;
context.fillText(&quot;Beware&quot;,-40,-55);
context.fillText(&quot;The Square&quot;,-55,70);
context.restore();

}
]]&gt;&lt;/script&gt;

Many parts of the drawing parts of this function are covered in the codecademy JavaScript drawing lesson so I will not cover them here.&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
Line by line overview of animation function beware()&lt;/h3&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
The parts which I added to get the animation going are on lines 05, 11, 12, 14, 16 and 25. &amp;nbsp;This function will be ran through again and again every 120 milliseconds as specified in the setInterval function.&lt;br /&gt;
&lt;br /&gt;
When animating the first step is to clear the screen of everything that is not a static background. &amp;nbsp;On line 05 this is accomplished by calling the clearRect function which clears the size of the canvas specified in this example in the html code above in the JSfiddle.&lt;br /&gt;
&lt;br /&gt;
Next the save() function is called on line 11 which saves the last drawn state onto a stack. &amp;nbsp;So in this case it is saving a cleared screen with just the circle drawn onto the stack.&lt;br /&gt;
&lt;br /&gt;
Usually when using javascript drawing function on a 2D canvas the origin (0,0) is the upper left corner of your canvas. &amp;nbsp;On line 12 this is changed by using the translate(x,y) function and the center of the canvas is made the origin for this example.&lt;br /&gt;
&lt;br /&gt;
In this example the new animations are based on the computer time which is grabbed by making a Date() object. &amp;nbsp; Date() methods are used in line 16 in the rotate(angle) function to specify a new angle every 120 milliseconds.&lt;br /&gt;
&lt;br /&gt;
On line 25 the restore() function is called which pulls the last saved state off the stack and displays it.&lt;br /&gt;
&lt;br /&gt;
So none of this is done using ActionScript, which for more complicated interactive features might run faster, at least for the time being. &amp;nbsp;But for simple and quick animations it is a cool feature to include. &amp;nbsp;Another use might be to make some very simple games if&amp;nbsp;interactivity&amp;nbsp;is integrated.&lt;br /&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://gjmiles.blogspot.com/feeds/7693497838298896971/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/3583660468885673865/7693497838298896971' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3583660468885673865/posts/default/7693497838298896971'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3583660468885673865/posts/default/7693497838298896971'/><link rel='alternate' type='text/html' href='http://gjmiles.blogspot.com/2013/05/super-duper-simple-animation-using.html' title='Super Duper Simple Animation Using HTML5 canvas element and JavaScript Tutorial'/><author><name>GJMiles</name><uri>http://www.blogger.com/profile/10460788817115186917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-3583660468885673865.post-783748549980240802</id><published>2013-05-10T03:43:00.001-04:00</published><updated>2013-05-10T05:04:04.786-04:00</updated><title type='text'>First Post </title><content type='html'>Starting a minor code journal.  I started out coding through a school summer internship for computational biology where I was introduced to perl and worked on a linux cluster, basically using perl to parse data and R to analyze data. &amp;nbsp;I worked on a &amp;nbsp;project analyzing molecular dynamics simulations involving a lectin from a blue-green algae. &lt;br /&gt;
&lt;br /&gt;
The computational&amp;nbsp;intensity&amp;nbsp;of the project sparked my interests in computer science so I decided to switch to computer science.  For the past year or so I have taken classes in C++ and have learned the OOP paradigm.&lt;br /&gt;
&lt;br /&gt;
Projects (all in c++) I have worked on so far include:&lt;br /&gt;
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;a RPN-calculator with the Qt framework for a gui&lt;/li&gt;
&lt;li&gt;&amp;nbsp;poker graphically displayed using opengl&lt;/li&gt;
&lt;li&gt;&amp;nbsp;a multi-threaded chat server and client using the Qt framework and gui&amp;nbsp;&lt;/li&gt;
&lt;li&gt;&amp;nbsp;An algebraic expression calculator that graphs using the Qt framework&lt;/li&gt;
&lt;li&gt;&amp;nbsp;Various other minor projects such as a BigNum calculator (to get beyond &amp;nbsp; overflow problems) and a project involving &lt;a href=&quot;http://en.wikipedia.org/wiki/Ancient_Egyptian_multiplication&quot; style=&quot;color: red; text-decoration: none;&quot;&gt;Bitwise Multiplication&lt;/a&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ul&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
While I am supportive of open source and free software (I do all of my coding using Arch Linux), I do not post or give out code from classwork because I do not like the idea of people using my code to help them finish CS homework/tests. &amp;nbsp;The less competition in the job market the better.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
What I do plan posting about is my own private projects outside of class.&lt;br /&gt;
&lt;div&gt;
&lt;br /&gt;
Currently, for fun I am using Code &lt;a href=&quot;http://www.codecademy.com/&quot; style=&quot;color: red; text-decoration: none;&quot;&gt;Academy&lt;/a&gt;. &amp;nbsp;However, after a year or so of learning C++ I find it a little disappointing because it sort of confines users to a box. &amp;nbsp;I feel the same way about blogger so hopefully soon I can get a domain name registered and set up my own custom blog for didactic&amp;nbsp;purposes. &lt;br /&gt;
&lt;br /&gt;
Over the summer I also plan on getting&amp;nbsp;familiar&amp;nbsp;with opengl using this free online book &lt;a href=&quot;http://www.arcsynthesis.org/gltut/&quot; style=&quot;color: red; text-decoration: none;&quot;&gt;Learning Modern 3D Graphics Programming&lt;/a&gt;. I am planning on starting a project using opengl for the graphics and with Qt for windows management.&lt;br /&gt;
&lt;br /&gt;
My plans for the blog are basically to discuss my meager programming experiences and some code alongside my opinions on learning programming.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://gjmiles.blogspot.com/feeds/783748549980240802/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/3583660468885673865/783748549980240802' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/3583660468885673865/posts/default/783748549980240802'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/3583660468885673865/posts/default/783748549980240802'/><link rel='alternate' type='text/html' href='http://gjmiles.blogspot.com/2013/05/first-post.html' title='First Post '/><author><name>GJMiles</name><uri>http://www.blogger.com/profile/10460788817115186917</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>