Code to the Future Almost every aspect of your life is affected by computer science in some way. The video games you play, the shows you watch, and even the music you listen to use computer science. How easy is this? Each chapter section teaches coding concepts. After learning a concept, you immediately apply it. Hands-On Example activities walk you through coding examples so you learn by doing. Try It! activities follow the Hands-On Example so you can apply the coding on your own. Why code? Throughout this text, features highlight how coding can impact your life. You make connections across other areas of study. Math and Coding features allow g you to apply your math skills to coding. Science and Coding features show g you how coding can be applied to a science project. What about a challenge? When you learn to solve problems, you learn you can take on challenges. Working alone or with a team, coding opens up the future. Coding Conundrum features present the challenge of finding the error in code to improve your ability to solve problems. Cooperative Coding features allow g you to blend your skills with those of others for improved teamwork. Hands-On Example 6.1B Hands-On Example 6.1B Repeat Block c A loop can be used us to repeat a specific m mo tion. n this In activity, you will move a sprite up and down five times. This s. motion could be us used to sh how the rising and setting of the Sun or Moon, for example. 1 Launch Scratch,, and delete the default s sp rite. 2 Applying what yo you have learned, add the he blue sky k y backdrop and the Sun sprite from the library. 3 Move the Sun prite sp to the right-hand sid de of the stage e just above the treetops (150, –40). 4 With the Sun prite sp selected, drag the w when een Flag Gre clicked block into the Scripts area. 5 Click the rol Contro category, and drag the r repeat 10 0 block to the bottom of the code stack. Change the v lue to alu 5. 6 Click the Motion n category, and drag the g glide 1 ecs to se x: value y: e valuee block and drop it into the repeat 5 5 loop. Change the x: valu ue to 150 and the y: value to 125. 7 Drag a second glide g block into the loop, a an d change n the x: value to 150 and the y: value to –40, as shown. when clicked repeat 5 glide secs to x: 1 150 y: 125 glide secs to x: 1 150 y: 40 Goodheart-Willcox Publisher 8 Click the Green n Flag button to test the p proj ect. Notice N how the Sun sprite moves exactly vertically. is This i because s the Y coordinate a chang nges, but the X coordinatehes does not. Also note how many times t the sprite moves u up and do down . This number matc the value set for the repeat op. loo 9 Modify the ber numb of seconds for each glide ock blo to control the speed at which the Sun sets and rises. 0 Add comments to the script to explain w wha t the code does. -S veth prj cas t Save the pr ojec ct HOE06 01B HOE06-0 1B i yo w ki g f f lder in yo ur wor f king f older. Try It! Choose any bacckdrop and sprite for this project.. Create a repeat loop to turn th he sprite 10 degrees to the righ ght exactly 36 times. After each tur urn, move the sprite 25 steps. H How would you describe the mot otion of the sprite? The starting point o of the sprite may need to b be adjusted to keep the sprite n the on stage. A pen down block n be can added to the loop to help show sh the motion. How can the size e of the area in which the rite spr moves be controlled? Save e the project as TI06-01B in your w wor king folder. Green Flag Copyright Goodheart-Willcox Co., Inc. Math and Coding Scratch can draw graphs of linear equations. Given the coefficients of a linear equation, Scratch can calculate the points. If the pen is placed down, Scratch can draw lines the points on the stage. Look at an equation: 3X + 4Y = 100. To plot this line, solve for Y:connecting Y = –3/4X + 100/4 or Y = –.75X + 25 Scratch has a backdrop in the library Linear Equations (X:0, Y:0) X Y (X:240, Y:0) –100 –200 100 200 100 100 (X:0, Y:180) (X:–240, Y:0) Wh t b t h ll ? W as a backdr op in the library that matches the coordinates and axes of the stage. Start a new Scratch project, and insert the xy-grid backdrop. the backdrop. See how the X andExamine Y a are aligned on the stage. Notice the origin is in the center of the stage. Also insert the pencil sprite from the library, and delete the cat sprite Save the pr MathC ( X:0 X:0 X:0 , , Y:0 Y:0 Y:0 ) ( X: –100 –200 100 100 ( X: 240 X:–240 X:–240 2 2 2 , , Y:0 Y:0 Y:0 ) sprite. . Save the pro MathC d Science and Codingxis Scuba is equipment used for breathing underwater. Its name comes from self-contained underwater breathing apparatus. Divers can use scuba to travel under water using normal air as a breathing gas. Normal air is a mixture of about 21 percent oxygen and 78 percent nitrogen. Strange things happen as a diver goes deeper than 50 meters. Due to the water pressure below 50 meters, the gases in air become toxic to humans. The diver can become disoriented, lose track of time, and forget safety procedures. This effect is called nitrogen narcosis or inert gas narcosis. Coming back to the surface from great depths also presents health concerns. If a diver comes up too quickly he/she may develop decompression sickness. This is a debilitating or life-threatening condition in which the gases dissolved in the diver’s body, such as oxygen and nitrogen, form bubbles. These bubbles may block blood supply to tissues, cause damage to joints, or affect the nervous system T Respiration and Depth o joints, ct the nervous system T p j Cu usto m blocks lo are often in conjunctio events. Consider the code shown here. This p progr am a m an imates user er clicks th the diver, the us use of two o custom blo This is program sho clicked d. However, the h e pressu ss ure as 0. Can you n y Coding Conundrum Event Errors when clicked forever move stepss 1 Depth if on edge, bounce when this sprite clicked f r secs define Depthare set to Depth / y position Driver2 of set to Depth Depthwill round set to Pressure Depth *are + definene Pressure is sprite y yo al th e of used n u sed i n con ion with w ith events . Con sider the code shown here. e the e sprite of a diver moving m ing up and down on the stage. Whenever the h sp spr ite will report the he wa water pressure at the current depth. Notice the ock ks and two events.. ou ould produce the an ans we wer to a multiplication problem when the sprite is e conundrum is th hat w when the program is run, the diver always reports the ou find the proble blem w with the code? ked ste ps e, bou un nce nc ce p rite cli c ic ck k ke ed define Depth set to Depth 180 / 3.6 y posit ion Driver2 of set to Depth Depth round define Pressure prite clicked Pressure Cooperative Coding Tutorials a very popular method for learning new material. This is especially true for software. A quick search of the Internet return hundreds of results for just about any software. Many software programs include tutorials within the program. Scratch contains many tutorials. Many more available online. With a partner, work through one of the tutorials in Scratch. Select a tutorial for what you believe is a basic skill in Scratch. After completing the tutorial, Writing an Interactive Tutorial michaeljung/Shutterstock.com ed p bo e e h the pri te of a di f ovin ng up a nd do wn on the stage Whe never the h oc o o ng the tutorial, nd
Previous Page Next Page