1 Building Your Own Turtle Functions For making really cool pictures!

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

SuperStar Basics Brian Bruderer. Sequence Editors Traditional sequence editors use a large grid to control when channels are turned on and off. This approach.
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
Week 9: Methods 1.  We have written lots of code so far  It has all been inside of the main() method  What about a big program?  The main() method.
Logo Lesson 3 TBE 540 Fall 2004 Farah Fisher. Prerequisites for Lesson 3 Before beginning this lesson, the student must be able to… Use simple Logo commands.
Introduction to Shape Programming When we make geometric shapes with computers, we have to give specific numbers to tell the computer exactly what to do.
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
What is Scratch? Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Loops and Switches. 1. What kind of blocks are these? 2. Name two kinds of controls that can be specified to determine how long a loop repeats. 3. Give.
XP Tutorial 7 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Working with Graphics Tutorial 7.
Programming 101 The Common Palette Content provided by Connor Statham (6 th Grade Student) Formatting by Shannon Sieber.
AP Computer Science Principles Data Abstraction and Procedural Abstraction Curriculum Module.
LOGO SOFTWARE BY: SAVE 9S. INTRODUCTION Logo is a software that can be found at : Shared area> High School > ICT > take home software > LOGO32. This is.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
Fall Week 3 CSCI-141 Scott C. Johnson.  Say we want to draw the following figure ◦ How would we go about doing this?
Microsoft® Small Basic
1 Loops and Branches Ch 21 and Ch18 And how you can use them to draw cool pictures!
1 CSC 221: Computer Programming I Fall 2011 Fun with turtle graphics  turtle module  relative motion (setup, reset, left, right, forward, backward) 
Georgia Institute of Technology Barb Ericson Georgia Institute of Technology May 2006 Teaching Java using Turtles part 2.
Art 321 Lecture 7 Dr. J. Parker. Programming In order to ‘make things happen’ on a computer, you really have to program it. Programming is not hard and.
Class 2 Introduction to turtle graphics
Turtle see, turtle do Lesson 1 – Welcome to LOGO.
1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!
Copyright © Curt Hill Turtles The beginning of media computation.
MSW Logo By Awin 9s.
An introduction to Logo Mike Warriner Engineering Director, Google Note: This course is not an endorsement of Logo by Google. All views in this document.
Introduction to Scratch Scratch as Logo Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Refining Original Illustrations Lesson 9.
2015 CSE/EGR Summer Camps 1 Computer Science Concepts 1. What is an algorithm? 2. Binary information coding 3. Programming concepts via Scratch Designed.
Make a blank window This is a starter activity and should take 5 minutes [ slide 1 ] 1.Log in to your computer 2.Open IDLE 3.In script mode create a file.
1 CSC 221: Computer Programming I Spring 2008 Objects and classes: a broad view  software objects, classes, object-oriented design  BlueJ IDE, compilation.
1 FUNCTIONS - I Chapter 5 Functions help us write more complex programs.
Algorithms Writing instructions in the order they should execute.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
1 Project designed and created by M. Shajith Kumar.
1 Building Your Own Turtle Functions For making really cool pictures!
Getting started with the turtle Find the latest version of this document at
Programming 101 The Common Palette Content provided by Connor Statham (9 th Grade Student) Formatting by Shannon Sieber.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Let’s Learn 3. Modules Saenthong School, January – February 2016
First of all – lets look at the window’s you are going to use. At the top you have a toolbar, with all your various tools you can use when customising.
Transparency 9 Click the mouse button or press the Space Bar to display the answers.
How to draw a Geometric Tessellation by Ms. Day Lesson 1: 4 sided polygons (grid) Lesson 2: Basic tessellations Lesson 3: Drawing in Word.
Turtle Graphics Lesson 2 1. There are 3 homeworks to complete during the six lessons of this unit. Your teacher will let you know when a homework has.
Functions. functions: a collection of lines of code with a name that one can call. Functions can have inputs and outputs.
IMDB Template File Save as: IMDB_period_Lastname Partner #1 name Partner #2 name.
Microsoft Publisher 2010 Lesson 4 Graphics in Publications.
Introducing the turtle
Hackety Hack! Written by Krystal Salerno Presented by _______________.
Module 1: Investigation 1 Moving, Turning and Stamping
Create a Halloween Computer Game in Scratch
Computer Programming.
Scratch for Interactivity
Intro CS – Loops & Creating Shapes
Starter Activity Instructions: Complete the starter sheet Planner
A Tiny Look at the Graphics Window
Learning to program with Logo
Frozen Graphics Lesson 3.
Lesson 4 Graphics in Publications
Graph Paper Programming
Microsoft® Small Basic
Intro to Programming With Snap PII.
Creating Functions with Parameters
Teaching Java using Turtles part 2
Chap. 3 Functions Start Python IDLE (Shell) and open a new file.
Using Logo and Logic This presentation uses a version of Logo called StarLogo available through MIT. It can be downloaded for free and installed on your.
A Tiny Look at the Graphics Window
Loops and Switches How Do You Make Loops and Switches? lesson > TeachEngineering.org Center for Computational Neurobiology, University of Missouri.
Presentation transcript:

1 Building Your Own Turtle Functions For making really cool pictures!

2 5 Cool Things… 1.Variables and Arithmetic 2.Branches for variety 3.Using Functions 4.Building your own Functions (Today) 5.Loops to repeat (Next class)

3 Review: 1) Variables and Arithmetic var n = 4; var y = 2; var x = n + y; y = n * 2; document.write(“x=” + x + “, y=” + y);

4 2) Using Functions Math Functions: x = Math.sqrt(81); y = Math.sqrt(x); document.write(“x=” + x + “, y=” + y); Turtle Functions: forward(20); left(90); forward(20); right(135); backward(40); Identify the Function calls and the arguments

5 Which command(s) uses “relative” positioning, and which “absolute” forward -- move turtle forward some number of pixels left – turn left some number of degrees moveTo -- move to an x,y coordinate turnTo – turn to a particular degree heading home – send turtle back to center of screen, facing up

6 Today—3) Building your own functions Lets you “abstract” a collection of moves For example, these lines make a square: forward(20); right(90);

7 If you want to draw a lot of squares, put this Function Definition at the top of your script… function square( ) { forward(40); right(90); } This is a Function Definition

8 Now you can ‘call’ your square function square(); left(30); square(); left(180); square(); moveTo(-300, -100); left(30); square(); left(180); square();

9 Functions help manage complexity You can do interesting patterns without a lot of repetition of code They save time and effort Functions can use other functions

10 What if you want different sizes of squares? function square( n ) { forward(n); right(90); } n is called a parameter It’s a variable that receives the size of the square (given as the argument in the function call)

11 Now when you call the square function, just say how big you want it to be square(100); square(50); square(25);

12 You can generate random sized squares… var size, angle; size=rand(50,100); square(size); angle=rand(0,180); turnTo(angle); size=rand(50,100); square(size); rand(low, high) gives random number between low and high

13 Every time you run the code from last slide, it gives a different result It’s interesting to observe the variations and similarities

14 Program Structure Function Definitions (in ) Main program block (in )

15 Functions Give “Vertical Structure” How to draw this complicated mosaic of 120 triangles?

16 “Bottom Up” Problem Solving Solve this sequence of ever more complex problems using functions at each level. triangle pattern line mosaic

17 Solutions function triangle(n) { forward(n); right(120); } function pattern(n) { turnTo(30); triangle(n); right(90); turnTo(90); }

18 That’s all! function line(n) { pattern(n); jumpFwd(n*1.7); pattern(n); jumpFwd(n*1.7); pattern(n); jumpFwd(n*1.7); pattern(n); jumpFwd(n*1.7); pattern(n); } function mosaic(n) { jumpTo(-200,-100); line(n); jumpTo( *1.7, -100); line(n); jumpTo( *2*1.7, -100); line(n); jumpTo( *3*1.7, -100); line(n); jumpTo( *4*1.7, -100); line(n); jumpTo( *5*1.7, -100); line(n); }

19 Not Quite! We need an initial function call to mosaic to kick it off: mosaic(30); Notice we give a size of 30…fills in for ‘n’ in all the other functions. So…using functions we can draw 120 triangles (or 360 forward commands) with about 30 lines of JavaScript—powerful!

20 Capture your images in a “screen shot” Press Alt and PrtScr at same time Open Paint Edit/Paste You can chop out image using select tool Dotted line box Then paste into Microsoft Word Or save as a.jpg file (project 2)

21 That’s it! Have fun in lab SUMMARY— Functions let you create your own building blocks to use in more complex programming problems Functions abstract pieces of code—self documenting Functions can call other functions Functions are re-usable—save time and money in software development Next week…branches and loops