Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein

Similar presentations


Presentation on theme: "CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein"— Presentation transcript:

1 CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein adamwittenstein@adelphi.eduhttp://www.adelphi.edu/~wittensa/csc160/

2 A Word on Computers ● Computers were originally used as number crunchers (to perform complex, large-scale calculations). ● We now use them for many other purposes as well. ● Computers cannot do all the wonderful things that we expect without instructions telling them what to do.

3 What is programming? ● Programming is how we give instructions to the computer. ● First, we represent various things in the world (numbers, words, pictures, etc.) to the computer. ● Then, we can write instructions in Scheme (or any other computer language) to tell the computer what we want it to do.

4 Programming the UFO ● You need to represent the UFO and the shots to the computer. ● Then you can program the computer to change: – their location (using numbers) and – draw them on the screen (as an image). ● In this chapter, we will see the details on how to do this in Scheme.

5 Section 1.1: Flying a UFO

6 Graphing in Scheme ● In math class, the x-coordinate becomes higher when you move to the right. ● This is true in Scheme. ● In math class, the y-coordinate becomes higher when you move up. ● This is FALSE in Scheme. ● The y-coordinate actually increases moving DOWN.

7 Pixels on the Computer Screen ● Increasing the y-value as you go down is common in computer science. ● To prevent computers from dealing with negatives, the top left corner of the screen is X=0, Y=0. ● Then as you move down or to the right, the numbers get bigger. ● For example, X = 5 is 5 pixels to the right of the screen’s left edge. Also, Y = 30 is 30 pixels down from the top of the screen.

8 Representing the UFO ● Suppose you are creating a game that shoots UFOs. ● You will play the game on a window within your computer screen. This is called the canvas. ● The location of the UFO (and the shots) can be expressed using two numbers: X, for left-to-right location in the window and Y, for up-and-down location in the window.

9 A little bit of number stuff… ● Soon we will get to moving UFOs, but first a little math review. ● Suppose the UFO starts out at X = 20. ● It moves 10 pixels to the right every second. t =01234…7 X =2030405060…?

10 Creating a formula (for X) ● We want the computer to know where the UFO is at any time, even t = 342. ● The process of adding 10 and extending the table is very tedious. ● For this purpose, it is better to figure out an algebraic formula that describes what X is for a given value of t. ● Here is the algebraic formula that relates X to t: X = 10 · t + 20

11 Checking the formula is correct ● In the first exercise, I will ask you to come up with such a formula on your own, generalizing from a table like the one above. In that case, it is good practice to test whether it works properly. ● To test the formula, see if some of the specific examples you know work. For example, the chart says that when t = 0 then X = 20. According to the formula, X = 10 · t + 20 X = 10 · 0 + 20 x = 0 + 20 = 20

12 In summary… ● Today we saw the “math” needed for the UFO game. ● We will translate this into writing our first Scheme program. Next time…


Download ppt "CSC 160 Computer Programming for Non-Majors Draft Chapter: The UFO Example Prof. Adam M. Wittenstein"

Similar presentations


Ads by Google