1 / 11

Drawing UFOs with Simple-Draw Teachpack

Learn how to use the Simple-Draw teachpack to draw UFOs on a canvas. Install the teachpack, use predefined functions, and start creating your own UFO designs.

Download Presentation

Drawing UFOs with Simple-Draw Teachpack

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSC 160Computer Programmingfor Non-MajorsSection 1.2: Drawing a UFO Prof. Adam M. Wittenstein adamwittenstein@adelphi.edu http://www.adelphi.edu/~wittensa/csc160/

  2. So far … • We can (write a program to): - compute the UFO’s location • But we cannot (write a program to): - create a canvas or - draw the UFO on it

  3. Why use teachpacks? • Since this is a non-majors course, we will leave out some of the details and nitty-gritty of programming. • For example, instead of writing a program to create a canvas and a picture, we will use the program someone else wrote. • The authors of the textbook wrote this program, and many others, for students to use in the teachpacks. • They provide tools you don’t know how to write yet, but you can use them • Analogy: you can drive a car without knowing how to build one

  4. Teachpacks • To use the programs, you need to install the file the author saved it on. That file is called a “teachpack”. (often called “libraries”) • This teachpack can be found on the web at: www.ccs.neu.edu/home/matthias/HtDP/Extended/simple-draw.ss • Install to the folder C:\ProgramFiles\PLT\Teachpacks • To install a teachpack to your DrScheme file: Language -> Add Teachpack -> find it • In the real world, the work of a computer programmer is used by other programmers. • In this course, the teachpacks will simulate the work of the “other computer programmer”.

  5. Our first teachpack: simple-draw.ss This file includes four programs: • (start width height) creates a canvas of width × height pixels; • (draw-solid-disk0 x y r c), which draws a colored disk at position (x,y), with radius r and color c; • (draw-solid-rect0 x y w h c), which draws a colored rectangle at position (x,y), of w × h pixels, and color c; • (draw-solid-line0 x0 y0 x1 y1 c), which draws a colored line of color c between the two positions (x0,y0) and (x1,y1).

  6. Using the programs • Notice that I have not given you the actual computer code for the program. • This means I have not shown you how this programs are defined, and I don’t plan to. • But we will still be able to use the programs, because the code is in the file that we will install. • Most of the variables will be replaced with numbers. We saw how to do this last time.

  7. Replacing variables with colors • To replace a variable with a number, we change (X t) to (X 20). That is, we replace the variable t with the number 20. • How would we replace a variable with a color? • We could assign numbers to each color, but this will get messy in a hurry. • Luckily, the teachpack also includes the names of some common colors like: 'white, 'yellow, 'red, 'blue, 'green, and 'black. • Suppose the program X used colors instead of numbers. Then (X t) would become (X ‘white).

  8. Exercise: Using the teachpack • Install the simple-draw.ss teachpack. • Type in an example for each of the four programs the teachpack gives. • See if it works the way you expect. If not, try and figure out why it doesn’t. - Either you expected the wrong thing - Or you did something wrong when typing it in.

  9. Now we are ready to draw UFOs • Step 1: Open the canvas. (start 100 200) Don’t worry about it printing out true. This is an error by the teachpack writer. • Step 2: Draw a solid circle. (draw-solid-disk0 50 50 10 'green) • Step 3: Draw a line through the middle. (draw-solid-rect0 30 50 40 3 'green)

  10. How do we draw many UFOs? • We can keep doing all 3 steps every time we want to draw a UFO. This will quickly get boring. • A better way is to write a program that will draw any UFO. • This program will use the simple-draw programs. • Defining this function is similar to defining the X or Y function for determining the UFO’s location.

  11. In summary… • Today we saw how to use predefined functions for drawing. • Next time, we will use this to write a program to draw UFOs. Next time…

More Related