Wednesday, May 25, 2016

Adding Tutorial

Today, I added the tutorial to the app. I included 3 sections: general info, controls, and menu buttons explained. I used the ScrollPane class (in Scene2d UI) that Jiho figured out to make it a scrolling window. This is updated on the website version that can be found here:

http://www.pages.drexel.edu/~njw59/

Below are some screenshots showing the content of the tutorial window.












Monday, May 23, 2016

Week 8 Update

Overview
We are at a point now where the app is just about done. We made a lot of progress over the last couple weeks and just this morning (Monday of Week 9) sent the app to a physics teacher for beta testing with his students.

Progress
One major change I made was updating the launch simulation to be more realistic. I incorporated the Runga Kutta method instead of Euler’s Method to provide more accuracy with less processing. The code used can be found here:


I also finished adding functionality to the menu buttons. They now all do what they’re supposed to do on click. Jiho also got the icons set up and I implemented those in as well. In addition, I added tooltips that pop up when someone mouses over a button and I added messages that show up to alert the user with the selected body and warnings such as when a body isn’t selected.

New Menu Icons

Messge overlay showing selected body (Body_1) and alert

Tooltip explaining function of scale button

Here’s the code for the menu:



And here’s the code for the message overlay:


Ebed made an assortment of 10 skins to put on the bodies. He made them different colors but all similar so that they would look consistent. Below is a texture atlas with 9 of them. I then put them into the app and set it up so that they would be randomly put on a body every time one was created.

Texture atlas of 9 body skins
The last major change I made was making it so that the app can be used online. I contacted the computer science department here at Drexel and they helped set me up with a free website. I then used Android Studio and libGDX to export the app in html form (see FAQ for a how-to). The app can be found and used here:


I then sent the app to my high school physics teacher who said he would test it out with his students over the next few days. Ebed created a survey that the students will fill out so that we can decide what changes need to be made. Here’s the survey:


Future Plans
In the next week, we need to plan out our presentation and finish our report. We will compile and analyse the results of the survey to do the results section of our report. We’re hoping we get nominated for the poster fair that will take place at the end of next week. Only one group from our section will make it.

Sunday, May 22, 2016

Upcasting and Downcasting


           Upcasting and downcasting allows you to change the reference variable type for an object. The type of the reference variable determines what methods you can call, but it’s the type of the object that the variable refers to which determines the methods that will be called. Unlike downcasting, upcasting is guaranteed by polymorphism.

            Similar to casting numbers, when down casting you need to specify what you’re casting to in parentheses before the variable. The variable your downcasting to must refer to the object type that your downcasting to. When your upcasting or downcasting you can't change the object only the reference variable.

Casting Numbers


In java you can cast from type to type as long as there in the same class. For example you can cast a floating number to a double, but not an integer to a string. Some types can only hold a certain amount of memory. So when converting between types you must be careful that the type you’re casting to can hold that value. If you do convert a number that doesn’t fit in that type, it may cut off the extra spaces. For example if you cast a floating number to an integer it will cut of the decimals. (It won’t round the number. Math.round does that for you.) When casting a number you must set a variable equal to the variable you want to cast. In parenthesis before the casted variable you must put the type you want to convert to.

Below shows code where I did many different casts. At the bottom I tried to cast a value of 128 to a byte. The problem is that a byte only holds up to 127, so what you get as an output is byte’s minimum, -127.

public class App {

      public static void main(String[] args){
            byte byteValue = 20;
            short shortValue = 55;
            int intValue = 808;
            long longValue = 3332322;
            float floatValue = 8834.8f;
            double doubleValue = 32.4;      
            
            System.out.println(Byte.MAX_VALUE);
            intValue = (int)longValue;
            System.out.println(intValue);
            doubleValue = intValue;
            System.out.println(doubleValue);       
            intValue = (int)floatValue;
            System.out.println(intValue);

            //ByteMax is 127;
            // the following won't work as we expect it to .
            //128 is to big for a byte.
            byteValue = (byte)128;
            System.out.println(byteValue);
          
      }
}

Wednesday, May 18, 2016

Encapsulation


Today I watched a tutorial on encapsulation. This is an extension of the public private and protected tutorial. Explaining why we declare instance variables, and methods private within a class. You want to declare a method private when you are only going to use it within the class. In general try not to make instance variables public unless they are constants. One reason we due this is to reduce cross linkages, you don’t want one class getting entangled in another class. Another thing the tutorial talked about is API documents. This is just the documents of built in classes for java. For example String is a built in class, meaning you don’t have to make a String class to create a String object in java. The API document gives you information on everything about the class, interfaces, instance variables, methods, constructers, etc. You will notice that in the built in classes there aren’t many instance variables that are public, except constants. The point of encapsulation is to define things private as much as you can unless, you need to use them outside that class.

Tuesday, May 17, 2016

Planets and App Logo

Today I spent time working on different skins for planets. Since you can't just copy images from online, because of legal reasons, I used Photoshop to make my own planets. One problem with our orbit simulator is that it runs slow. So we are looking for ways to increase the operation speed. One idea we thought of, was getting rid of friction. What we wanted to do was make planets that are symmetric so the rotation due to friction wouldn't matter. So however I spin a planet it will look exactly the same.

When making the app logo, I wanted to make sure the color scheme looked appealing. This will be the first thing the user sees, so it must look good. I experimented with different colors to try and get the most visual appealing one. In the process I asked friends which colors they liked the best, knowing that I am not the target audience. Below is the logo I made in Photoshop.


Monday, May 16, 2016

Polymorphism


Polymorphism essential means that if you have a child class of a parent class you can use the child class anywhere you would use the parent class.  For example you can declare variable with type of parent class to objects of child class. Then when you call a method to that variable it will call the method in the child class. When you run the method the type of the variable doesn’t matter. What matters is the type object containing the variables that’s going to run. So if you make a variable with a parent class type, but it refers to a child class object. It’s going to run the code in the child class.

Below shows many examples of polymorphism. In the main method I made a tree object and a plant object. Tree is a child class of plant. So we can declare a variable type plant to a tree object. We can now call a method that is in both the plant and tree class. When the method is called it will run the code in the tree class. If you try and call a method not in the plant class using a tree object it won’t work. This is shown in the comment below where shedLeaves is a method only in the tree class.



public class App {
     
      public static void main(String[] args) {

            Plant plant1 = new Plant();
            Tree tree = new Tree();         
            Plant plant2 = tree;
         
            plant2.grow();          
            tree.shedLeaves();
        
            //plant2.shedLeaves();
          
            doGrow(tree);
  
      }
    
      public static void doGrow(Plant plant){
            plant.grow();
      }

}