Monthly Archives: July 2020

Input/Output: Animations: Ballistic Motion I

Animations using java
duke

Screen Shot 2015-02-23 at 12.19.21 AM

Classwork:
Projectile motion with drag. Use the supplied program and make the necessary changes to show during the animation the following:
Ballistic Motion Sim

Projectile motion with drag. Write a program YI_BallisticMotion1.java that plots the trajectory of a ball that is shot with velocity v at an angle theta. Account for gravitational and drag forces. Assume that the drag force is proportional to the square of the velocity. Using Newton’s equations of motions and the Euler-Cromer method, update the position, velocity, and acceleration according to the following equations:

Use the given program to enhance it to show the image bellow:
1. The values should change as the ball travels through the air.
2. The values should move with the ball.
3. The blue text and dotted curve is not included in the GUI.

project motion math

[spoiler title=’BallisticMotion.java’]

/******************************************************************************
* Compilation: javac BallisticMotion.java
* Execution: java BallisticMotion v theta
* Dependencies: StdDraw.java
*
* Simluate the motion of a ball fired with velocity v at theta degrees
* with coefficient of drag C. Uses Euler-Cramer method to numerically
* solve differential equation.
*
* % java BallisticMotion 180.0 60.0
*
* % java BallisticMotion 20.0 45.0
* Copyright © 2000–2011, Robert Sedgewick and Kevin Wayne.
* Last updated: Mon Aug 3 12:15:11 EDT 2015.
******************************************************************************/

public class BallisticMotion {

public static void main(String[] args) {
double G = 9.8; // gravitational constant m/s^2
double C = 0.002; // drag force coefficient

double v = Double.parseDouble(args[0]); // velocity
double theta = Math.toRadians(Double.parseDouble(args[1])); // angle in radians

double x = 0.0, y = 0.0; // position
double vx = v * Math.cos(theta); // velocity in x direction
double vy = v * Math.sin(theta); // velocity in y direction

double ax = 0.0, ay = 0.0; // acceleration
double t = 0.0; // time
double dt = 0.01; // time quantum

double maxR = v*v / G; // maximum distance without drag force
StdDraw.setXscale(0, maxR);
StdDraw.setYscale(0, maxR); // set the same as for X-scale

// loop until ball hits ground
while (y >= 0.0) {
v = Math.sqrt(vx*vx + vy*vy);
ax = -C * v * vx;
ay = -G – C * v * vy;
vx += ax * dt;
vy += ay * dt;
x += vx * dt;
y += vy * dt;StdDraw.filledCircle(x, y, 0.25);
StdDraw.show();
StdDraw.pause(5);
StdDraw.clear();

}

StdDraw.show();
}

}

[/spoiler]

Homework:
Work on the ballistic motion assignment.

Input/Output: Animations: Array: Intro to Conways’ Game of Life

Conways’ Game of Life
Gospers_glider_gun

Answer the following questions in edmodo.com
1. What is the shape of the cells?
2. What are the two possible states of a cell?
3. How many neighboring cells each cell interact with?
4. Explain the relative location of these neighboring cells.
5. What are the rules at each step in time?
6. What does the initial pattern constitute?
7. What is it referred by a “tick”?
8. What are the criteria that must be met for the proper emulation to be successful?
9. What are the different types of pattern that occur in the Game of Life?
10. On a piece of graph paper draw the 3 following patterns and show the life of the cell at each of 5 ticks.
Beehive
Screen Shot 2014-12-15 at 11.12.40 PM

Beacon
Screen Shot 2014-12-15 at 11.13.08 PM

Glider
Screen Shot 2014-12-15 at 11.13.32 PM

Write the first draft of your algorithm using only pseudocode.
One of many Fun sites


Animation: RandomBlock_YI.java

Implement an animation, RandomBlock_YI.java. The CheckerBoard.java can easily be changed to randomly select a random number of squares on the grid and become a solid color (“alive”) and then randomly it will turn back to white (“dead”) again. ‌ Re-Use-Code: these are good resources for this assignment: ‌

BouncingBall.java

CheckerBoard.java

MyGraphPaper.java

If you have successfully completed the random block program, you should be able to get started with the game of life assignment.
Start small. Here is the glider: