EEN118 LAB TWO. 1. A Five-Pointed Star.

Similar documents
EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t ½ g t 2

EEN118 LAB FOUR. h = v t - ½ g t 2

EEN118 LAB THREE. Section A - Conversions A1. Remembering how to start. A2. Exotic Canada

Polygons and Angles: Student Guide

Animations involving numbers

Angles, Polygons, Circles

How to draw and create shapes

My Favourite Problem No.5 Solution

Using Microsoft Word. Tables

In this project, you ll learn how to use a turtle to draw awesome shapes and patterns.

Grade 6 Math Circles Fall 2010 Tessellations I

Interactive Tourist Map

CISC 1600, Lab 3.1: Processing

Excel Basics: Working with Spreadsheets

Shapes. Reflection Symmetry. Exercise: Draw the lines of symmetry of the following shapes. Remember! J. Portelli

Create an Adorable Hedgehog with Basic Tools in Inkscape Aaron Nieze on Sep 23rd 2013 with 5 Comments

Geometry AP Book 8, Part 2: Unit 7

CISC 1600, Lab 2.1: Processing

n! = 1 * 2 * 3 * 4 * * (n-1) * n

Instructions for Crossword Assignment CS130

On the Web sun.com/aboutsun/comm_invest STAROFFICE 8 DRAW

Stroke Styles. Once defined, they can be saved and reused at a later time.

The options for both the Rectangular and Elliptical Marquee Tools are nearly identical.

Spring CS Homework 3 p. 1. CS Homework 3

Grade 6 Math Circles February 19th/20th

How to...create a Video VBOX Gauge in Inkscape. So you want to create your own gauge? How about a transparent background for those text elements?

There we are; that's got the 3D screen and mouse sorted out.

Grade 6 Math Circles. Shapeshifting

Shape and Line Tools. tip: Some drawing techniques are so much easier if you use a pressuresensitive

Using Microsoft Word. Working With Objects

[ the academy_of_code] Senior Beginners

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 24 Solid Modelling

RENDERING TECHNIQUES

Using Flash Animation Basics

Ideas beyond Number. Teacher s guide to Activity worksheets

2013 Four-by-Four Competition Thursday, January 31st, Round Four-by-Four Competition Thursday, January 31st, 2013.

1 Getting started with Processing

How to create shapes. Drawing basic shapes. Adobe Photoshop Elements 8 guide

Class Meeting 05 (Lecture 04) Objectives for this class meeting. Conduct vote on basic style of game for class project

Understanding the Screen

SNOWFLAKES PHOTO BORDER - PHOTOSHOP CS6 / CC

Creating Vector Shapes Week 2 Assignment 1. Illustrator Defaults

Art, Nature, and Patterns Introduction

Surface Area and Volume

Camtasia Studio 7 User Guide

Header. Article. Footer

10 Connector Designer

Introduction to Excel

Learn to make desktop LE

Prime Time (Factors and Multiples)

Chapter 7. Polygons, Circles, Stars and Stuff

Adobe Photoshop How to Use the Marquee Selection Tools

TESSELLATIONS #1. All the shapes are regular (equal length sides). The side length of each shape is the same as any other shape.

Name: Class: Date: ID: A

Creating Digital Illustrations for Your Research Workshop III Basic Illustration Demo

Adobe Flash CS3 Reference Flash CS3 Application Window

UNIT 7 Mensuration Activities

Paint Tutorial (Project #14a)

Grade 6 Math Circles February 19th/20th. Tessellations

HO-1: INTRODUCTION TO FIREWORKS

Name: Tutor s

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Intermediate Algebra. Gregg Waterman Oregon Institute of Technology

Tutorial 3: Constructive Editing (2D-CAD)

The Fundamentals. Document Basics

10-1. Enrichment. You Can Count On It!

lundi 7 janvier 2002 Blender: tutorial: Building a Castle Page: 1

Lesson 18: Slicing on an Angle

5. Canvas overview. Cricut Design Space User Manual. Design Panel

Late Penalty: Late assignments will not be accepted.

Using Microsoft Excel

2. If a window pops up that asks if you want to customize your color settings, click No.

How to use the ruler, grid, guides, and the Align panel

The original image. Let s get started! The final result.

CS 201 Advanced Object-Oriented Programming Lab 10 - Recursion Due: April 21/22, 11:30 PM

CpSc 101, Fall 2015 Lab7: Image File Creation

Expressions and Casting

Transcriber(s): Aboelnaga, Eman Verifier(s): Yedman, Madeline Date Transcribed: Fall 2010 Page: 1 of 9

Adobe Photoshop CS2 Reference Guide For Windows

Ai Adobe. Illustrator. Creative Cloud Beginner

T O B C A T C A S E E U R O S E N S E D E T E C T I N G O B J E C T S I N A E R I A L I M A G E R Y

Add Photo Mounts To A Photo With Photoshop Part 1

AN INTRODUCTION TO SCRATCH (2) PROGRAMMING

Geometric Constructions

Part 1 - Your First algorithm

Customisation and production of Badges. Getting started with I-Color System Basic Light

Maths Levels Criteria

Draw beautiful and intricate patterns with Python Turtle, while learning how to code with Python.

Introduction To Inkscape Creating Custom Graphics For Websites, Displays & Lessons

2D Space. Name. 1 Trace the vertical lines in red. Trace the horizontal lines in blue. Trace the oblique lines in green.

SETTINGS AND WORKSPACE

Overview: The Map Window

Surface Area and Volume

ICS 61 Game Systems and Design Introduction to Scratch

Let s Make a Front Panel using FrontCAD

Computer Science 474 Spring 2010 Viewing Transformation

Today s Hall of Fame and Shame is a comparison of two generations of Google Advanced Search. This is the old interface.

Welcome to Desktop Publishing with InDesign!

Transcription:

EEN118 LAB TWO The purpose of this lab is to get practice with defining and using your own functions. The essence of good structured programming is to split large problems into smaller and smaller sub-problems. Small subproblems should have small solutions which can be programmed quickly and reliably. Functions that solve each of the small sub-problems are used together to solve the original big problem. Divide and conquer. If you just go immediately to the last step and wonder how to do it, this may seem like an impossibly long and detailed assignment. If you work through the numbered steps properly, you will soon see that it isn t. After each step, look over what you have done carefully, and make sure you completely understand it, and that it does not seem particularly complicated any more. When starting the next step, think carefully how you can use what you have already done to make it easy. 1. A Five-Pointed Star. In a previous lab exercise, you wrote a program that draws a pentagram, which is almost a five-pointed star, but has a pentagon inscribed inside it. Adapt that program so that it draws a clean five-pointed star with no extra lines, just like you would expect to see on an American flag. There are many ways to solve a problem in programming. This one has two equally sensible solutions. You could write a function void draw_star(const int length), where length is the length of each of the ten lines that make up the star. The programmer would be responsible for moving the pen to the right position before calling this function. The other would be to write void draw_star(const int x, const int y, const int length), which required the programmer to work out the numeric x-y coordinates of the top spike of the star before calling the function. Think ahead. Think about how you are going to be using this function, and make what you judge to be the appropriate decision. You should be able to work out what the correct angles are, but in case you can t, they are given above the first diagram on the next page.

2. A Function. Convert the part of your program that actually draws the star, after all the set-up, into a function. Make this function good and flexible (it will need to have at least one parameter), so that it can draw a star of any size and at any position. Verify that you have got it right by using your function to draw a variety of stars in the same window. Make sure they all come out with the right orientation. The angles inside the points of the star are 36, the wider shoulder angles are 108. 3. Colouring It In. Drawing the outline of a star is all very well, but they would look much better if filled with some solid colour, or perhaps if they were white shapes on a coloured background. Filling a whole rectangular area with a single colour is easy, and there is a library function that does it in a single operation. Just give it the x and y co-ordinates of the top left corner of the area, then the width, then the height, and it s done. Naturally, it uses whatever the current pen colour is, e.g.: set_pen_color(color::blue); fill_rectangle(10, 10, 200, 50); will fill the whole area from x=10 to x=210 and y=10 to y=60 in blue. To fill a more complex shape, your program must define each of its corners one by one. There are three simple steps: a. Use the start_shape() function, just to tell the system that a new shape is about to be defined. b. Move the pen to each of the corners in turn. When the pen is positioned at a corner, use the note_position() function to tell the system to record this position as a point on the outline of the shape. You don t need to draw, just move the pen to the right places. c. Finally, set the pen to the right colour, and call the fill_shape() function.

Here is a simple example that draws a slightly irregular solid red triangle: start_shape(); move_to(100, 100); move_to(150, 150); move_to(50, 120); set_pen_color(color::red); fill_shape(); It is a peculiarity of windows that whenever it fills a shape, it also draws the outline using the current pen settings. If you haven t selected a very thin pen, the shape will have a slightly blurry or rounded appearance. Make your star function draw solid sharp stars. 4. An Intermediate Flag. Test your function in a program that draws the flag of Washington D.C. It will just take a minute or two of experimentation to get the proportions looking exactly right. Don t be afraid of trial-and-error. This is how it should look: 5. Rows of Stars. Write a new function that makes use of your existing star-drawing function to draw a horizontal row of six evenly spaced solid white stars. If you have got the right idea, this will be very easy. You have already completely solved the problem of drawing one solid white star. There is no need to modify that function in any way. All you have to do for this new function is to call the existing function a few times.

Give the new function a sensible name, something like row_of_six_stars, and make sure that it is good and flexible: it should be able to draw its row of stars anywhere you want. Once your row of six stars looks right, take a few seconds to make another function which this time draws a row of just five stars. At this stage, you should have two new functions, one that draws a row of six stars, and one that draws a row of five stars. 6. Blocks of Stars. Now it will take almost no effort to write another function that calls both your row_of_six_stars and row_of_five_stars functions to make a block of eleven stars: Take the time to get the stars properly spaced, so that the two rows slightly overlap as shown, because you know what is coming next. Get this stage right, and the next will not be very hard at all. Make this into a new function too, drawing eleven stars just like that.

You are now at the point where your solutions to smaller sub-problems can be made into a relatively simple solution to a much larger and more complex problem. Write a program that draws a good rendering of the American flag. Try to get it looking just right. After all this effort, you might as well do it properly. Officially the ratio of width to height of the flag should be 19 to 10. As you can tell by counting stripes, the height of the blue box is seven thirteenths of the height of the whole flag. The length of the blue box is two fifths of the length of the whole flag. 8. Extra Credit: Make it Special. What size should it be? We know the correct proportions, but flags are allowed to be any overall size you want. Make your program flexible: define one constant called height, which defines the height of the whole flag in pixels, and calculate all other dimensions from that. It should be that all you have to do is change the value of height, and all the rest of the flag will automatically adjust to continue looking just right at the new size.