Activity Guide Loops and Random Numbers

Similar documents
Differentiation Applications 1: Related Rates

making triangle (ie same reference angle) ). This is a standard form that will allow us all to have the X= y=

, which yields. where z1. and z2

This section is primarily focused on tools to aid us in finding roots/zeros/ -intercepts of polynomials. Essentially, our focus turns to solving.

CS 477/677 Analysis of Algorithms Fall 2007 Dr. George Bebis Course Project Due Date: 11/29/2007

Student Exploration: Cell Energy Cycle

Weathering. Title: Chemical and Mechanical Weathering. Grade Level: Subject/Content: Earth and Space Science

Five Whys How To Do It Better

Physics 2010 Motion with Constant Acceleration Experiment 1

AP Statistics Notes Unit Two: The Normal Distributions

Physics 2B Chapter 23 Notes - Faraday s Law & Inductors Spring 2018

SPH3U1 Lesson 06 Kinematics

Flipping Physics Lecture Notes: Simple Harmonic Motion Introduction via a Horizontal Mass-Spring System

You need to be able to define the following terms and answer basic questions about them:

READING STATECHART DIAGRAMS

Medium Scale Integrated (MSI) devices [Sections 2.9 and 2.10]

Three charges, all with a charge of 10 C are situated as shown (each grid line is separated by 1 meter).

Lab 1 The Scientific Method

Turing Machines. Human-aware Robotics. 2017/10/17 & 19 Chapter 3.2 & 3.3 in Sipser Ø Announcement:

Lesson Plan. Recode: They will do a graphic organizer to sequence the steps of scientific method.

Hypothesis Tests for One Population Mean

Regents Chemistry Period Unit 3: Atomic Structure. Unit 3 Vocabulary..Due: Test Day

Work, Energy, and Power

Introduction to Spacetime Geometry

Interference is when two (or more) sets of waves meet and combine to produce a new pattern.

Experiment #3. Graphing with Excel

I. Analytical Potential and Field of a Uniform Rod. V E d. The definition of electric potential difference is

Forensic Science. Group: Background information

AP Physics Kinematic Wrap Up

ECE 545 Project Deliverables

CESAR Science Case The differential rotation of the Sun and its Chromosphere. Introduction. Material that is necessary during the laboratory

Flipping Physics Lecture Notes: Simple Harmonic Motion Introduction via a Horizontal Mass-Spring System

CHM112 Lab Graphing with Excel Grading Rubric

COMP 551 Applied Machine Learning Lecture 11: Support Vector Machines

SUMMER REV: Half-Life DUE DATE: JULY 2 nd

Trigonometric Ratios Unit 5 Tentative TEST date

Section 5.8 Notes Page Exponential Growth and Decay Models; Newton s Law

Lesson Plan: Dash and Dot

TRAINING GUIDE. Overview of Lucity Spatial

EEO 401 Digital Signal Processing Prof. Mark Fowler

Instructional Plan. Representational/Drawing Level

Astro 102 Lab #2. 1) Learning the user interface and setting up your home location

Sections 15.1 to 15.12, 16.1 and 16.2 of the textbook (Robbins-Miller) cover the materials required for this topic.

Chapter 1 Notes Using Geography Skills

TP1 - Introduction to ArcGIS

We can see from the graph above that the intersection is, i.e., [ ).

Getting Involved O. Responsibilities of a Member. People Are Depending On You. Participation Is Important. Think It Through

20 Faraday s Law and Maxwell s Extension to Ampere s Law

CHAPTER 24: INFERENCE IN REGRESSION. Chapter 24: Make inferences about the population from which the sample data came.

37 Maxwell s Equations

Pipetting 101 Developed by BSU CityLab

How do scientists measure trees? What is DBH?

AP Literature and Composition. Summer Reading Packet. Instructions and Guidelines

Physics 212. Lecture 12. Today's Concept: Magnetic Force on moving charges. Physics 212 Lecture 12, Slide 1

Guide to Using the Rubric to Score the Klf4 PREBUILD Model for Science Olympiad National Competitions

AP Statistics Practice Test Unit Three Exploring Relationships Between Variables. Name Period Date

NUMBERS, MATHEMATICS AND EQUATIONS

[COLLEGE ALGEBRA EXAM I REVIEW TOPICS] ( u s e t h i s t o m a k e s u r e y o u a r e r e a d y )

Thermodynamics Partial Outline of Topics

Kinetic Model Completeness

Lab 11 LRC Circuits, Damped Forced Harmonic Motion

ALE 21. Gibbs Free Energy. At what temperature does the spontaneity of a reaction change?

CEE3430 Engineering Hydrology HEC HMS Bare Essentials Tutorial and Example

Relationships Between Frequency, Capacitance, Inductance and Reactance.

Example 1. A robot has a mass of 60 kg. How much does that robot weigh sitting on the earth at sea level? Given: m. Find: Relationships: W

Name: Period: Date: ATOMIC STRUCTURE NOTES ADVANCED CHEMISTRY

Functions. EXPLORE \g the Inverse of ao Exponential Function

ENG2410 Digital Design Sequential Circuits: Part A

MODULE FOUR. This module addresses functions. SC Academic Elementary Algebra Standards:

QUIZ Fundamentals of Daylighting 1h30

Fall 2013 Physics 172 Recitation 3 Momentum and Springs

Standard Title: Frequency Response and Frequency Bias Setting. Andrew Dressel Holly Hawkins Maureen Long Scott Miller

Plan o o. I(t) Divide problem into sub-problems Modify schematic and coordinate system (if needed) Write general equations

Chem 163 Section: Team Number: ALE 24. Voltaic Cells and Standard Cell Potentials. (Reference: 21.2 and 21.3 Silberberg 5 th edition)

Lecture 7: Damped and Driven Oscillations

Revision: August 19, E Main Suite D Pullman, WA (509) Voice and Fax

Assessment Primer: Writing Instructional Objectives

AIP Logic Chapter 4 Notes

Figure 1a. A planar mechanism.

ENSC Discrete Time Systems. Project Outline. Semester

Exponential Functions, Growth and Decay

CS1150 Principles of Computer Science Loops

Lecture 6: Phase Space and Damped Oscillations

Lab #3: Pendulum Period and Proportionalities

PHOTOSYNTHESIS THE PRACTICALS 16 APRIL 2014

Review Problems 3. Four FIR Filter Types

If (IV) is (increased, decreased, changed), then (DV) will (increase, decrease, change) because (reason based on prior research).

Project CONVERGE 1/13/15. How to Read CONVERGE CODAR Imagery Data Primer

Web-based GIS Systems for Radionuclides Monitoring. Dr. Todd Pierce Locus Technologies

Lifting a Lion: Using Proportions

CONSTRUCTING STATECHART DIAGRAMS

WRITING THE REPORT. Organizing the report. Title Page. Table of Contents

MODULE 1. e x + c. [You can t separate a demominator, but you can divide a single denominator into each numerator term] a + b a(a + b)+1 = a + b

GRADE 5 QUARTER 4 SUGGESTED PACING

x 1 Outline IAML: Logistic Regression Decision Boundaries Example Data

Preparation work for A2 Mathematics [2018]

A - LEVEL MATHEMATICS 2018/2019

A B C. 2. Some genes are not regulated by gene switches. These genes are expressed constantly. What kinds of genes would be expressed constantly?

The Law of Total Probability, Bayes Rule, and Random Variables (Oh My!)

What is Statistical Learning?

Transcription:

Unit 3 Lessn 7 Name(s) Perid Date Activity Guide Lps and Randm Numbers CS Cntent Lps are a relatively straightfrward idea in prgramming - yu want a certain chunk f cde t run repeatedly - but it takes a little practice t get gd at cntrlling lps and recgnizing hw and where in yur prgrams t use them. The fr lp in JavaScript (and many ther prgramming languages) is designed t be used fr bth simple and sphisticated prgramming tasks, thus it has a lt f syntax t it that will be explained in the future. In this lessn, the blck-based frm f the fr lp expsed t students is effectively a simple repeat lp - it nly lets them change a number that dictates hw many times the lp repeats. Randm numbers are als used mre (much mre) in this lessn as an effective way t experiment with lps. Creating sme randmly-generated utput with each iteratin f the lp is gd visual feedback that the lp is running the way yu expect. It als helps yu explre the ranges f pssible utputs, which tells yu mre abut what yur prgram can and cannt d. Challenge 1: Getting Started with Lps A lp is a blck f cde that is repeated r "lped thrugh" in a prgram. Yu will be creating a lp using the fr lp blck. We'll start by experimenting with a prgram similar t what yu saw in the vide. Drag ut a fr lp blck. Inside the lp: Add a call t mvefrward. Add a call turnleft. (HINT: try turning by 137 degrees t start. Yu can change after that.) Run the prgram t see the lp in actin. Experiment: Change the number f times the lp runs. Increase the run speed t see hw fast lps can execute. Hw many times can the lp run befre yu can n lnger tell the difference in the image?

Mve n nce yu feel like yu have a decent grasp f using a fr lp: setting the number f times t repeat, running the prgram, and setting the run speed. Challenge 2: Practice Using Lps Part 2 Let's lk at the secnd example frm the vide. Use a fr lp t call a functin that yu wrte. We've prvided the cde fr the drawsquare functin fr yu. Drag ut a fr lp. Inside the lp add a call t drawsquare, and a call t turnright. Run the prgram t see what's happening. Change the number f lp iteratins t draw a lt f squares. Try t create the figure shwn belw (r smething similar). HINT: the image belw has 72 squares in it. Challenge 3: Lping with Randm Values If yu add sme randmness t turtle behavir inside a lp, the prgram will run a little differently every time which can make fr sme cl effects. Yu're abut t see a prgram in which the turtle mves t a randm lcatin each iteratin f the lp, and draws a randmly-sized dt that als has a randm clr. We've als made the dt semi-transparent by setting the alpha value t 0.5 (50% transparency). 2

Figure ut hw many iteratins yu need t cnsistently fill the screen entirely with dts s nne f the backgrund is shwing. It will be a little different every time s yu'll need t experiment. Cmpare what yu fund with a neighbr t see hw clse yur results are. Then mve n. Challenge 4: Using Multiple Lps Sme repeated tasks can't easily be slved with a single lp. Instead, yu'll need t use ne lp after anther, each ne slving a part f the prblem. Nw that yu've filled the screen with clred dts, let's cver it up by adding a lp that fills the screen with semi-transparent white dts. Drag a secnd lp int yur prgram. Add cmmands t draw dts in randm lcatins that are white with pacity set t 0.5. Increase the iteratins s that the clred dts are ttally erased. Hw many des it take? Challenge 5: Tp-Dwn Design Lk at this cmplex versin f the "Under the Sea" scene yu drew in the previus lessn. Yu nw have all the skills yu need t recreate this digital scene. We will use Tp-Dwn Design t help manage the cmplexity f drawing this image. The starter cde yu will be prvided already has brken the prblem int multiple levels. Overview f Prgram Structure Yu are abut t see that we've prvided yu with a gd amunt f starting cde. Here's a brief tur: High-Level Functin Calls: These read almst like a stry f hw yu will draw the image. There's ne functin fr every majr cmpnent f the scene. High-Level Functin Definitins: These are currently empty. Yu will be adding cde t these functins. Each will cntain a lp that will draw many cpies f each cmpnent. Lw-Level Functins: These draw single elements f the scene. Mst have been written fr yu already, but we've left a few fr yu t cmplete as well. 3

D This Review the structure f the cde in this level. Run the cde t familiarize yurself with what it currently draws. When yu are ready t d s, mve n! Challenge 6: Add Bubbles The first high-level functin yu will write is drawallbubbles. Yu may have nticed that the bubbles in the image lk very similar t the dts example we've already drawn in this lessn. Nw we'll use that skill t add t ur image. Read the drawbubble functin t knw hw it wrks and what parameters it accepts. Mdify the cde f drawallbubbles : Add a lp inside the functin Place the cmmands already inside the functin in yur lp. This way yur cde will mve the turtle randmly and call drawbubble many times. Set the number f iteratins in yur lp s that the screen is filled with bubbles. Try starting with 200 and then adjust t whatever number yu like. Challenge 7: Add Fish The next high-level functin yu will write is drawallfish. A versin f drawfish with parameters has been prvided fr yu t use. 4

Read the drawfish functin t knw hw it wrks and what parameters it accepts. Add a lp t drawallfish. Place the cmmands already inside the functin in yur lp. This way yur cde will mve the turtle randmly arund the tp 360 pixels f the image and draw 15 fish f randm size between 5 and 20 using drawfish. Once yu have yur lp wrking try calling drawfish with randm values fr its red, green, and blue parameters t get differently clred fish. Challenge 8: Add Sea Stars We're nw ready t add sea stars t ur image by writing drawallseastars. Recall that we've already written lps t draw much mre cmplex stars. Read the drawseastar functin t knw hw it wrks and what parameters it accepts. Update drawseastar t use a fr lp rather than repetitive cmmands. Add a lp t drawallseastars. Place the cmmands already inside the functin in yur lp. This way yur cde will mve the turtle randmly arund the bttm pixels (y values between 360 and 450) f the image. Draw 5 sea stars f randm size between 10 and 30 using drawseastar. Challenge 9: Cntrling Lps with Parameters This time yu will mdify ne f the lwer-level functins - drawseagrass. Ntice that the current versin f drawseagrass actually uses a lp. We want t mdify this functin s that we cntrl the number f times it lps with a parameter. Lk at the drawseagrass functin t see hw it currently wrks. 5

Add a parameter that will be used t indicate hw many waves the seagrass makes. Mdify the fr lp s that it uses that parameter as the number f times t repeat. Finally, mdify drawallseagrass t call this new tw-param versin f drawseagrass supplying a reasnable randm value fr the secnd parameter as well. Challenge 10: Add Sea Grass Our new versin f drawseagrass nw draws a single piece f seagrass with a randm height. Nw let's use a lp in drawallseagrass t fill the sea flr with it. Add a fr lp t drawallseagrass that draws abut 50 pieces f sea grass using yur updated drawseagrass functin. 6

Challenge 11: Add Sunbeams Finally, we'll add sme visual flurish by writing drawallsunbeams. Nte: yu'll have t use the turnt cmmand t make the turtle face the same directin prir t drawing each sun beam. Read the drawsunbeam functin t knw hw it wrks and what parameters it accepts. Add a lp t drawallsunbeams t draw abut 100 sunbeams. Inside yur lp: Place the cmmands already inside the functin in yur lp. This way yur cde will mve the turtle t a randm x lcatin at the tp f the image (y is 0), turnt a randm angle between 165 and 175 degrees, and call drawsunbeam. Hierarchy f functins drawbackgrund drawallseagrass drawallseastars drawallfish drawallbubbles drawallsunbeams drawseagrass drawseastar drawfish drawbubble drawsunbeam 7

Reflectin: Multiple Chice: A prgrammer wants t write a prgram in which the turtle draws 8 squares in a rw while mving frward. The final result shuld lk like the turtle drawing shwn. But smething is wrng! The incrrect cde is shwn t the right. The prgrammer has attempted t write a functin t draw a single square. Then he wrte anther functin that attempts t call that functin 8 times. Mentally trace thrugh the cde and determine which line f cde shuld be remved t make the prgram d what it's suppsed t. A: 1 B: 5 C:6 D:7 E: 14 Free Respnse: When breaking a prblem dwn, yu ften encunter elements that yu want t use repeatedly in yur cde. Smetimes it's apprpriate t write a new functin; at ther times it's apprpriate t write a lp. There is n hard-and-fast rule as t which is better, but what d yu think? What kinds f circumstances wuld lead yu t writing a functin versus using a lp? 8