Wednesday, November 30, 2016

Space Ship Scene Reflection



  1. The purpose of the code is to create a scene in space. It works by calling multiple functions that create objects such as spaceships and planets. The most important features are randomized planets with craters, a ufo, a black hole, and a spaceship with animated fire.

  1. The most difficult part for me was the fire for the spaceship. It had to be animated, and look like fire. I achieved the fiery look by making the fire made out of 2 curves, one to the left and one to the right. I then turned the turtle 180 degrees and repeated it, so it got to the original start position of the flame. I then took a stored variable of the distance away from the center of the ship, and had it return to the center. To animate the flames, I had the draw flames loop for infinity, which made new flames constantly, making it animated.

  1. An abstraction I used was to split up the main function of drawing the spaceship into smaller sub functions. I had a simple main function that was split up into smaller more complex functions. The main function called functions to draw the body of the ship, the top, the rocket, and the flames. The main function also had a parameter to rotate the ship. Functions with parameters are a type of abstraction.


  1. We used collaboration to split up the tasks into manageable chunks. We each had sections of code we chose to make. Collaboration was also used for feedback. Before putting everything in the main code, we shared our result and our team mates gave their feedback on it so it could be improved.

CODE:
function drawShip(angle) {
  hide();
  turnTo(angle);
  drawBody();
  drawTop();
  drawRocket();
  drawFlames();
}
function drawBody() {
  penDown();
  penColor("#FA6323");
  penWidth(20);
  turnLeft(90);
  moveForward(15);
  for (var i = 0; i < 3; i++) {
    turnRight(90);
    moveForward(30);
  }
  turnRight(90);
  moveForward(15);
  turnRight(90);
  moveForward(15);
  dot(21);
  penColor("black");
  dot(15);
  penColor("#FACF23");
  dot(13);
}
function drawTop() {
  penUp();
  penColor("#7A7A7A");
  moveForward(40);
  dot(15);
  moveBackward(10);
  turnRight(90);
  moveForward(15);
  turnLeft(90);
  penDown();
  turnLeft(30);
  for (var i = 0; i < 2; i++) {
    moveForward(30);
    turnLeft(120);
  }
  moveForward(30);
  penUp();
  moveBackward(15);
  turnLeft(90);
  moveBackward(22);
}
function drawRocket() {
  penUp();
  moveBackward(40);
  penColor("#4A4A4A");
  penDown();
  penWidth(15);
  turnLeft(90);
  moveForward(5);
  turnLeft(30);
  moveForward(15);
  turnLeft(150);
  moveForward(30);
  turnLeft(150);
  moveForward(15);
  turnRight(60);
  penUp();
  turnLeft(90);
  moveForward(3);
  turnLeft(90);
}
function drawFlames() {
moveForward(15);
speed(100);
var originalDist;
var arcDist;
for (var i = 0; i < 1; i) {
  turnRight(90);
  penRGB(255, randomNumber(104, 175), 17, 1);
  penWidth(randomNumber(2, 6));
  penDown();
  originalDist = randomNumber(-20, -2);
  arcDist = randomNumber(15,40);
  moveForward(originalDist);
  turnLeft(90);
  arcRight(30, arcDist);
  arcLeft(30, arcDist);
  turnRight(180);
  arcLeft(30, arcDist);
  arcRight(30, arcDist);
  turnRight(180);
  arcLeft(30, arcDist);
  arcRight(30, arcDist);
  turnRight(180);
  arcRight(30, arcDist);
  arcLeft(30, arcDist);
  turnRight(90);
  moveForward(originalDist);
  turnRight(90);
}
}
drawShip(0);

Wednesday, November 23, 2016

Smiley Face

https://studio.code.org/projects/applab/U_jdUmHE-fs-h2KCsjBu8w

https://studio.code.org/projects/applab/gZij3sn3oweRYoALNHxD9A

Monday, November 21, 2016

Functions with parameters

Prompt: 1.  Develop a rule for deciding when to create a function with a parameter rather than a normal function. Below your rule write a couple sentences justifying your rule.
Whenever you have a function that needs an input, use parameters. For example, if you had a function that took 2 numbers and added them, then multiplied them together, you would want a parameter for the input.

Prompt 2. When do you need a function with a parameter?
Whenever you need a outside input to the function.

Iteration

Define and provide examples of iteration:
Iteration: loops, repeating something.

examples: loops in code. for loops, while loops, and do while.

Friday, November 18, 2016

Smiley code reflection


Copy and paste your code to create your smiley face.  

penColor("lightgreen");
dot(500);
penUp();
penColor("purple");
penWidth(5);
move(0, -175);
penDown();
move(0, 50);
penUp();
move(0, 50);
turnRight(45);
penColor("red");
penDown();
arcRight(180, 25);
moveForward(50);
penUp();
moveTo(160, 165);
turnTo(-45);
penDown();
arcLeft(180, 25);
moveForward(50);
penColor("purple");
penUp();
moveTo(140, 300);
penDown();
turnTo(-90);
arcLeft(180, 25);
penUp();
moveForward(40);
penDown();
moveForward(10);
arcLeft(180, 12.5);
arcRight(180, 12.5);
moveForward(10);



What challenges did you face in this lab?
The biggest challenge was finding where to put all of the dots/curves

How did you solve these challenges?  
I figured out the center of the coordinate grid by guess and check, then offset the dots a equal distance from the center.

Did you collaborate with others in class?
no

Did you get or provide help to other "programmers" in class?  With what?  What documentation did you use for this lab today?  
I used the documentation from code.org

Provide examples of other libraries you are familiar with in other programming languages.

I’m familiar with a lot of the libraries in Java, such as the input, and the math librarys.

Wednesday, November 16, 2016

Unit 3 stage 5 reflection

function drawStep(){
 moveForward();
 turnLeft();
 moveForward();
 right();
}

function right(){
 turnLeft();
 turnLeft();
 turnLeft();
}
function drawSide() {
 drawStep();
 drawStep();
 drawStep();
 moveForward();
 right();
}
function drawDiamond() {
 drawSide();
 drawSide();
 drawSide();
 drawSide();
}
drawDiamond();

1. Prompt: “List the benefits of being able to define and call functions in a program. Who specifically gets to enjoy those benefits?”
Everyone enjoys the benefits of functions. It makes programmer’s lives easier, and also makes the code easier to read and understand. It organizes code, saves you from writing repeating code, and makes the code easier to read.

2. Prompt: “How is the use of a function an example of abstraction?”
Functions are an example of abstraction because it can make parts of your code reduced to essential commands. It reduces large chunks of code into nicely named functions, which give only the essential data. Within the function, only the relevant data is passed into it, making it simplified.

3. Prompt:  Explain more than one reason why programming languages have functions.

Functions are useful tools to split up code and make it look logical, while also being able to reuse sections of code. For example, if I had a section of code that calculated (number A x number B - 52)/5, or something that took out a section of a string, instead of rewriting that code, I could just use a function, and call that function inputting the numbers. They also organize code. Instead of having a large chunk of code that does a complicated math function, you could send it to a function, which might be named takeDerivative(). That way you know it takes the derivative of the function, without seeing the large chunk of code.

Monday, November 14, 2016

Ch 3 Stage 4 reflections

Define efficiency in programming.
When we are trying to be "efficient" in our programming what are some (valuable) resources we might be concerned with?  Why does it matter?

I think efficiency in programming is using the minimum amount of code to run a program with the minimum amount of resources needed. The resources we might be concerned with is storage space, amount of ram used, and how much computing power your program requires. It matters because if your computer uses too many of one of these resources, it will slow down the program and any other program being used on the user's computer. This will end up with frustration from the user, and drive them away from your program.


Thought Prompt: What is the “most efficient” way to program the solution for the 3x3 grid?
I know for sure that my solution was not the most efficient, but I think that the most efficient would be a program that minimizes right turns. Right turns take up 3 commands, and cutting down on those would be the easiest way to cut down on code.


  • What surprised you about programming with such a small set of basic commands?
I was surprised there  was no right turn.

  • Were you able to be creative with such a limited set of tools?

I was not very creative, but looking back, if I started out the second program with a right turn, and made the box the opposite direction, it would create 3 left turns  and a right, instead of 4 right turns, which is 12 left turns.

  • What was most frustrating about this activity? If you could add one additional simple command, what would it be, and why?
It was frustrating not having a right turn. I would add a right turn command, because it would cut down on a lot of left turn commands needed.

  • Draw (on paper) the simplest image you can that we would be unable to create with our “building block” commands, and explain why it would be impossible to create.
One simple image would be a triangle. The program is unable to create angled lines.



  • Draw a second image we would be unable to create with the given simple commands, but for a different limiting reason than you cited in the first drawing
One other image would be a circle. The program is unable to draw curved lines.