Wednesday, June 20, 2018

The Physics Simulator

Introduction/The Idea:

For my AP Physics End of Year project, we were asked to create something that shows our knowledge of our favorite physics topics. You could either make two short projects or one long project. The options for both were pretty much the same, but the amount of effort you put into it will determine whether it was a short project or a long one. The most chosen options were a teaching video, an engineering project, or experimental research. Since my favorite topic was kinematics and specifically projectile motion, I decided to make something that would show this while playing to my strengths. One of the other options that only a few people chose was to create a program that shows your knowledge using code. If you already had experience programming, then it would be considered a short project, However, my teacher said that if I put in a lot of work, then he would consider it a long project. Therefore, I decided to create a program on projectile motion.

After some thinking, I decided to create a projectile motion simulation that can calculate the distance traveled. I decided to do this instead of a simpler project because I had already experimented with creating canvas animations earlier in the year during my free time. I had ended up making a simple animation that dropped a square wherever you clicked on the canvas. I decided to build this into a full-fledged projectile simulation.

A Crash Course on Web Design:

The programming languages I used for the application were HTML, CSS, and Javascript. A good analogy to how these programming languages fit together to make web applications would be a person. HTML would be the actual "body" of the person. CSS would be the clothes they wear. Javascript would be the "brains" of the person. What HTML does, if you didn't already know, is that it gives the framework for your program. You use HTML to create buttons, text boxes, containers, and links. CSS, on the other had, is what is used to style the pages you made in HTML. Normal HTML pages are very basic and unaesthetic. CSS helps to position elements, change the color, size and borders they have, resize elements for different browsers, and generally give the website "style". Javascript gives the web page functionality. It tells the web page what to do when a button is pressed, or a picture is clicked, or when the page loads. This is what I used to animate my simulation.  I'll only go over the HTML and CSS  code briefly, as most of the work I did was in Javascript.


How It Works (the code):

The HTML in my project basically set up all the inputs and outputs I needed for my program. The inputs are what will be used to set properties for each projectile that is fired. These include buttons, textboxes, and dropdown menus. The output, of course, is the canvas itself. The CSS moved the different elements around to make it easier to work with, along with giving it a color scheme and overall making it look nicer. The Javascript is what animates the projectiles in the program. What this section will cover is mainly focused on this.

Basically, how it works is that when the page loads, several variables and arrays are created for the more important data that needs to be saved. A variable is a way to store data without having to write it all out. An array is a way to store data without having to manually make multiple variables. It's best to store data this way due to it being easier to make and fix. Imagine having to describe all the features of a person just to call them to you. It's much easier to just give that person a name and use that instead. The name represents the person, just as the variable represents the data. Once this is done, it automatically runs the program once, just to show the user what the simulation does. I'll get into how that works later. Whenever you press the go button, it uses the DOM (a way to access HTML elements with Javascript) to get all the values you set in the Settings tab and put them into variables. This is what the createObjectOnClick() function does. A function is basically a way to run the same code over and over without having to type it out. Think of the person example I gave for variables. Instead of having to describe the same properties every time you want the person to come, giving it a name and using that is easier. Only this time, instead of giving a name to a bunch of data, you are giving a name to a bunch of code.

Lines 1-13 are where I declare my global variables and arrays. 
Lines 213-237 are where I declare the variables for each property the projectile will have.
At the bottom, lines 310-312 push the variable properties into each created instance (or copy) of the object. Then that gets put into an array that has all the properties of the projectiles.
Now here comes the interesting part: how it's animated. Once the createObjectOnClick() function finishes putting the properties of the object into variables, it actually gives it to the object. Remember those variables and arrays that were declared when the page loaded? Among those is an array called allObjectsCreated, and it stores the Objects that are created whenever you press the go button. Notice how I capitalized the word "objects". That's because in Javascript, there are something called Objects, which are basically arrays that can store code as well as regular data, They are helpful for storing properties of whatever you want, such as color and size, as well as functions to run. In this case, the object stores all the properties createObjectOnClick() made. It also stores an update() function, which basically tells the object what to do based on whether it touched the ground or not. If it is not touching the ground, it will keep accelerating the object downwards based on the gravity value. If it is, and bouncing is turned on in settings, it will flip the velocity to a positive in order to make it go upward. This part of the function is run every 20 milliseconds, and runs for all the projectiles in the simulation. However, since there is only one object, then in order to be able to save for multiple properties, the keyword new has to be used in createObjectOnClick(). This basically makes a new object at runtime that stores the properties. This new object is put into an array, which is how you access each projectile. In this way, you can create many objects and not have the code break.
Lines 47-71 handle what happens when the projectile hits the ground.

Now this next part explains what you might have noticed earlier: how the code is actually made to run every 20 milliseconds. In order to do this, you have to use the setInterval(arg1, arg2) method. This is a default method in Javascript and makes whatever the code you write in arg1 repeat for however many milliseconds you put in arg2. You can put a function in arg1, which is what I did so I don't have to run a giant block of code within the parenthesis. Also, to make the function creatObjectOnClick() actually run once, all you have to do is declare it with parenthesis outside of where it is called. So you create the function like this (ignore the brackets): [ function foo() {//code} ] and call it like this[ foo() ].

Anyways, that is how the most important bits of my program work. Everything else deals with smaller issues such as creating a pop-up when certain conditions are met and looping through the array that holds the properties of all the objects.












Final Product:

My final product is a projectile motion simulator that calculates the distance it travels while helping you learn different facts about projectile motion in general. It's features include:

- projectile motion visuals

- customizable:
    -gravity
    -initial velocity
    -friction
    -projectile type
    -cliff height
    -launch angle

-projectile tracing (can be turned off)

-bouncing (can be turned off)

-sliding (can be turned off)

-wall bouncing (can be turned off)

-learning popups (can be turned off)

It is a valuable tool to teach students about projectile motion and kinematics while still being entertaining and fun to use.

Monday, September 4, 2017

My New App: The Amharic Calculator

   ካልኩሌተር: The Amharic Calculator- screenshot



ይህ የሂሳብ ማስሊያ (ካልኩሌተር) በገጹም ሆነ በይዘቱ ኢትዮጵያዊነት የተላበሰ እና ለመሰረታዊ የሂሳብ ስሌት ስራ እንከን የለሽ አገልግሎት ይሰጣል።  በተጨማሪም ይህ የስልክ-ቁስ (አፕ)፦

- 100% ነጻ እና ማስታወቂያ የሌለው
- ልዩ ኢትዮጵያዊ እሴትን የሚያሳይ ጠቃሚ የሂሳብ ማስሊያ ካልኩሌተር ነው
- የአማርኛ/ግዕዝ ቁጥሮች እና ምልክቶች በሁሉም ቁልፎች ላይ አለው
- የተሳሳተ የስሌት ትዕዛዝን የሚጠቁም የአማርኛ መልዕክት ይጽፋል
- በአግድሞሽ ሲቀመጥ የቀድሞ ስሌቶችን ውጤት የሚስታውስ የስሌት ታሪክ አምድ ያሳያል
- ከስር የቀድሞ ስሌት ውጤት ምን እንደነበር ጽፎ ያሳያል

በሉ በሞቴ በሳንቃው ደረቴ! አሁን ስልክዎ ላይ ጭነው ሞክሩት፤ አስተያየትዎንም ይጻፉ፤ ለሌሎችም ያሳውቁ።
--------------------------------------------------------------------------------------------------------------------------
This Amharic Calculator is an app with the following unique features:

- It is 100% FREE with NO ads!
- It is an Ethiopianized basic math calculator!
- It has Amharic/Geez numbers on each button!
- Error messages are displayed in Amharic and English!
- Landscape mode shows the previous results as history!
- Recent history is displayed in portrait mode!

Download it for free today!

Link: play.google.com/store/apps/details?id=com.abukatech.amhariccalculator

Thursday, August 6, 2015

Gauss Explained

So I was reading this really great book called the Joy of X, and in the first chapter, it had an explanation of Gauss's (is that how you write it?) Formula of adding the numbers 1-100 without going 1+2+3+4... There are a bunch of techniques for this but the one I like best is the Triangle method. So, lets say you're back at elementary school and your teacher is having a bad day, so she gives you a challenge. "Can you add up all the numbers from 1 to 100?". Then, the teacher, confident that they couldn't solve it, leans back and relaxes, drinking a cup of dark coffee. But you're very smart, so you decide to play around with the problem before solving it. And, just for no reason, you make a triangle out of the problem: x xx xxx xxxx xxxxx xxxxxx xxxxxxx xxxxxxxx xxxxxxxxx xxxxxxxxxx And just for kicks, you decide to mirror it like so: oooooooooo xooooooooo xxoooooooo xxxooooooo xxxxoooooo xxxxxooooo xxxxxxoooo xxxxxxxooo xxxxxxxxoo xxxxxxxxxo xxxxxxxxxx So what do you do now? Well, let's say the total number of x's and o's are called "S". And remember the formula for the area of a triangle? It was bh/2. And these sure look like triangles, don't they? So you can apply the formula to them. So it would look like this: S=bh/2 Or, if you substitute b for n: S=nh/2 But, you realize, it isn't a perfect square. The x's and o's make a rectangle, so how would you account for that? The total thing is a rectangle because on the very top and bottom rows, it is filled with just x's and just o's. So it makes it into a rectangle. And so to account for that, You can do this: S=nh+1/2 Or, if you want to make it easier to read: S=n(h+1)/2 You can add the parenthesis because nh is equal to n(h) because both mean they are being multiplied. But h, the height is just the same thing as n, because both are made of x's and o's. So the formula can look like this: S=n(n+1)/2 Which is what the actual formula looks like! That teacher must have been very impressed.

Saturday, February 14, 2015

Why Is the Sky Blue?



By: Tsegazeab Beteselassie


Why Is the Sky Blue?
Source: gizmodo.com
    Why is the sky blue? I'm pretty sure that when you were a child,you asked your parents that (I certainly did). And maybe they muttered something about the refraction of light and prisms and the colors of the rainbow. And when you searched it on Google, you got the exact same thing. You probably didn't, but still. And just maybe, you are still wondering why the sky is blue and not a different color. So you went to my blog to find out the answer. And so, now you want to know why it's blue. So, instead of wasting your time, I'll tell you right away. The light bounces off the air molecules and produce a visible effect of a multitude of colors, but since the blue light's wavelength is shorter than the others, then it'll scatter by a complex formula that goes like:
Or something like it. Didn't understand that? Time to go into deeper explanation.