1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!

Slides:



Advertisements
Similar presentations
Java Script Session1 INTRODUCTION.
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.
Cosc 1P02 Week 2 Lecture slides
Computer Science 1000 LOGO I. LOGO a computer programming language, typically used for education an old language (1967) the basics are simple: move a.
Aim: Use the given examples to record examples and our own ideas in our journal 1.Write technical examples in journal and/or participate in full.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
JavaScript Lesson 1 TBE 540. Prerequisites  Before beginning this lesson, the learner must be able to… Create a basic web page using a text editor and/or.
HTML Lesson 1 TBE 540 Farah Fisher. Prerequisites Before beginning this lesson, the student must be able to… Access web pages and navigate the web Access.
Introduction to TouchDevelop
Java Programs u 1 project file –with an extension of.mcp –contains information that CodeWarrior needs to run the program u >= 1 source files –have an extension.
B.A. (Mahayana Studies) Introduction to Computer Science November March Logo (Part 1) An introduction to Logo: drawing, moving,
Turtle Graphics  Turtle graphics provide a simple way to draw pictures in a window.  The name suggests the way in which we can think about the drawing.
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
CS 101: Arrays Abhiram Ranade. Computers manipulate many objects Given the position, masses, and velocities of all stars, where will they be after the.
Lecture 2: Static Methods, if statements, homework uploader.
THE BIG PICTURE. How does JavaScript interact with the browser?
Enhancing Your Web Site. More Basic HTML Tags Today you will learn these tags: & add-on (alt, height, width & align) and “href” add-on Add a text link.
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.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Programming Training kiddo Main Points: - Python Statements - Problems with selections.
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) 
Main Points: - Python Turtle - Fractals
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.
Turtle Graphics  Turtle graphics provide a simple way to draw pictures in a window.  The name suggests the way in which we can think about the drawing.
Introduction to TouchDevelop
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.
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
1 Chapter 18 Programming Basics When it comes to being precise about an algorithm, a programming language is better than English.
1 Building Your Own Turtle Functions For making really cool pictures!
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
PLT Final Project---COLOGO Lixing Dong, Zhou Ma, Chao Song, Siyuan Lu, Dongyang Jiang.
Create a Halloween Computer Game in Scratch Stephanie Smullen and Dawn Ellis Barb Ericson October 2008.
Computer Programming Modeling a Passive Solar Home.
Website design and structure. A Website is a collection of webpages that are linked together. Webpages contain text, graphics, sound and video clips.
1 Building Your Own Turtle Functions For making really cool pictures!
JavaScript Defined DOM (Document Object Model) General Syntax Body vs. Head Variables Math & Logic Selection Functions & Events Loops Animation Getting.
1 2/22/05CS120 The Information Era Chapter 4 Basic Web Page Construction TOPICS: Images and placing pages on the server.
Let’s Learn 3. Modules Saenthong School, January – February 2016
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
CSC1401 Drawing in Java - 1. Goals Understand at a conceptual and practical level How to use the Turtle class to draw on a picture How to use the java.awt.Graphics.
Javascript Basic Concepts Presentation By: Er. Sunny Chanday Lecturer CSE/IT RBIENT.
JavaScript Invented 1995 Steve, Tony & Sharon. A Scripting Language (A scripting language is a lightweight programming language that supports the writing.
CompSci 4 Java 4 Apr 14, 2009 Prof. Susan Rodger.
Graphics CIS 40 – Introduction to Programming in Python
For vs. While loop count=0 while count< 5: for count in range(5):
Introduction to Python
LOGO BY Kaotip 9S.
Main Points: - Python Turtle - Fractals
Loops BIS1523 – Lecture 10.
JavaScript is a programming language designed for Web pages.
A Tiny Look at the Graphics Window
Microsoft® Small Basic
Teaching Java using Turtles part 2
The Web Wizard’s Guide To JavaScript
Main Points: - Python Turtle - Fractals
Introduction to Turtle Graphics
For this assignment, copy and past the XHTML to a notepad file with the .html extension. Then add the code I ask for to complete the problems.
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
JavaScript Basics What is JavaScript?
Logo Programming.
Javascript Chapter 19 and 20 5/3/2019.
Web Programming and Design
Web Programming and Design
Presentation transcript:

1 Turtle Graphics and Math Functions And how you can use them to draw cool pictures!

2 5 Cool Programming Topics… 1.Variables and Arithmetic (last class) 2.Branches for variety (last class) 3.Using Functions (today) 4.Building your own Functions (Next class) 5.Loops to repeat (in two classes)

3 Review: 1) Variables and Arithmetic var n, x, y; n = 4; y = 2; x = n + y; y = n * 2; document.write(“x=” + x + “, y=” + y); This + concatenates the string “x=“ with the value in x, resulting in a larger string “x=6” Declare variables for use in program

4 Review: Your Turn, what is printed? var n=2, x, y=4; x = n + y * n; y = y + x * n; x = x + y; document.write(“x=” + x + “, y=” + y); ANSWER: x=34, y=24 x=2 + 4*2 = 10 y=4+10*2=24 x=10+24=34

5 Review: 2) Branches (Conditionals) var x, y=2, n=4; if ( y > n ) x = y - n; else x = n - y; document.write(“x=” + x + “, y=” + y); ANSWER: x=2, y=2 FALSE! (2 is not > 4) x=4-2=2

6 Review: Your turn…what is printed? var x=5, y=6, n=7; if ( x == 5) y = n; else n = x; if ( y < n) y = y + n; else x = n; document.write(“x=” + x + “, y=” + y); TRUE! y=7 FALSE! x=7 ANS: x=7, y=7

7 From the JavaScript Reference link

8 TODAY: Built in JavaScript Functions Sometimes your math needs will go beyond standard arithmetic Square roots, raising to the power, etc JS provides built in Math functions We also can use Turtle functions (if we include a file called a ‘library’) Not perfect… only works on your local machine, can’t make web enabled Still a lot of fun

9 From JavaScript Reference link

10 Your turn…what is printed? var n, x, y=4; x = Math.sqrt( y ); y = Math.sqrt( (x+2)*16 ); document.write(“x=” + x + “, y=” + y); y = Math.min( x, y ); document.write(“x=” + x + “, y=” + y); x=2 y=sqrt(64)=8 x=2, y=8 y=2 ANSWER: x=2,y=2

11 Some terminology… var n, x, y=4; x = Math.sqrt( y ); y = Math.sqrt( (x+2)*16 ); document.write(“x=” + x + “, y=” + y); y = Math.min( x, y ); document.write(“x=” + x + “, y=” + y); arguments Function calls Function calls are when you use a function Arguments are the data (variable or number) the function needs to do its work

12 Turtle Graphics Functions We have a nifty turtle graphics library of functions available for drawing Not standard JS…in a separate file File turtle.js has to be downloaded to the same folder as the assignment html file we are working on Any file using Turtle Graphics needs to include turtle.js

13 A simple turtle example forward(20); left(90); forward(20); right(135); backward(40); arguments Function calls x

14 For your art project, Only use these pre-made functions: forward -- move turtle forward some number of pixels backward -- move turtle backward left – turn left some number of degrees right – turn right moveTo -- move to an x,y coordinate turnTo – turn to a particular degree heading home – send turtle back to center of screen, facing up drawString – draw text at current position color – change the color of the line width – change the thickness of the line penUp – lift up the pen so no line will be drawn penDown – lower the pen so a line will be drawn rand – generate random integers between two values

15 Some Further Turtle Examples width(50); color("blue"); forward(50); width(50); color("blue"); forward(50); width(20); color("yellow"); backward(50);

16 home( ) takes you to screen center width(10); color("green"); forward(100); right(135); forward(60); home();

17 You can move without drawing… using penUp and penDown turnTo(0); // horizontal pointing right color("#C312AF"); width(50); forward(50); penUp(); forward(100); penDown(); forward(50);

18 Absolute vs Relative Positioning Relative Position: forward, backward, left, right keeps track of where you are and makes adjustments from your current position Absolute motion: moveTo, turnTo Lets you specify exactly where or what angle Using Cartesian geometry… a little refresher may help

19 moveTo(x,y) puts you here: moveTo(-200, 0) moveTo(200, 100) moveTo(100, -100)moveTo(-400, -200)

20 turnTo(angle) points you like so turnTo(120) turnTo(45) turnTo(315) or -45 turnTo(210) turnTo(30)

21 You can mix absolute and relative moveTo(350, -180); forward(300); turnTo(200); forward(500); moveTo(-350, 180); (350, -180) (-350, 180);

22 A cool Turtle function…rand( ) var x, y; x = rand(-200, 200); y = rand(0, 50); moveTo(x, y); random value -200 to 200 random value 0 to 50 go to that random point, will be different each time you refresh

23 You can use rand with if-else to select random colors var n; n = rand(1, 4); if (n = = 1) color(“red”); else if (n = = 2) color(“yellow”); else if (n = = 3) color(("#C312AF”); else color(“lime”); last branch is like “none of the above” You can add as many branches as you like Notice the cascading if, else if structure

24 To print your picture… Can’t print from web browser (doesn’t show) Do a screen capture…Alt-PrtScr Open Paint Edit > Paste Page Setup Orientation: Landscape Fit to: 1 by 1 pages OK Now File > Print will work