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.

Slides:



Advertisements
Similar presentations
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Advertisements

2006 by Jim X. Chen: 1.1. Review –Graphics commands specify straight lines or other geometric primitives that are scan-converted.
Building Java Programs Supplement 3G Graphics Copyright (c) Pearson All rights reserved.
Cosc 1P02 Week 2 Lecture slides
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
1 Graphical objects We will draw graphics in Java using 3 kinds of objects: DrawingPanel : A window on the screen. Not part of Java; provided by the authors.
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.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
1.1 History of Computers 1940s: The ENIAC was one of the world’s first computers. Large stand-alone machine Used large amounts of electricity Contained.
I/O in AP Java Enjoyable, Meaningful, Non- Distracting I/O in AP Java Ken Lambert, Washington and Lee University Martin Osborne, Western Washington University.
EDT Chapter 41 Coordinate Systems Cartesian, Relative and Polar Sacramento City College EDT 310.
Introduction to Programming Writing Java Beginning Java Programs.
TOPIC 3 INTRODUCTION TO PROGRAMMING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach by M. Guzdial and B.
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.
Lesson 2: First Java Programs. Objectives: –Discuss why Java is an important programming language. –Explain the Java virtual machine and byte code. –Choose.
Microsoft® Small Basic
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
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.
Agent P, I have been hearing some rumours about a Python Turtle.
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.
TURTLE GRAPHICS IP MR. MELLESMOEN. LOGO IN THE 1970’S THERE WAS A SIMPLE BUT POWERFUL PROGRAMMING LANGUAGE CALLED LOGO THAT WAS USED BY A FEW.
Logo For beginners By Dali Matthews 9S What is logo?
Java is an object oriented programming language In this model of programming all entities are objects that have methods and fields Methods perform tasks.
Java Introduction part 2 CSC1401. Overview In this session, we are going to examine some of the instructions from the previous class in more detail.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
Loops & Graphics IP 10 Mr. Mellesmoen Recall Earlier we wrote a program listing numbers from 1 – 24 i=1 start: TextWindow.WriteLine(i) i=i+1 If.
Introduction to Programming Writing Java Beginning Java Programs.
Introduction to Graphics. Graphical objects To draw pictures, we will use three classes of objects: –DrawingPanel : A window on the screen. –Graphics.
AP Computer Science A – Healdsburg High School 1 Unit 2 - Object-Oriented Programming - Example.
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.
Copyright 2008 by Pearson Education Building Java Programs Graphics reading: Supplement 3G videos: Ch. 3G #1-2.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
1 Sections Java Interfaces – The Client Perspective Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
CPCS 391 Computer Graphics Lab One. Computer Graphics Using Java What is Computer Graphics: Computer graphics are graphics created using computers and,
 The word static is used to declare either a ________ variable or method.  Why do we use statics?  What is Polymorphism? class In general, we use a.
Using the Python Turtle
Fundamentals of Programming I Introduction to Graphics
Graphics CIS 40 – Introduction to Programming in Python
LOGO BY Kaotip 9S.
More methods, more capabilities
Building Java Programs
Building Java Programs
Basic Graphics Chapter 5 3/19/15 Thursday Section Only
Building Java Programs
Fundamentals of Programming I Introduction to Graphics
A Tiny Look at the Graphics Window
Agent P, I have been hearing some rumours about a Python Turtle.
Microsoft® Small Basic
البرمجة مع لغة PYTHON TURTLE
Scalars v. Vectors.
Teaching Java using Turtles part 2
Bellwork (block 2) Textbook pg 415 (ALL)
CSE 142 Lecture Notes Graphics with DrawingPanel Chapter 3
class PrintOnetoTen { public static void main(String args[]) {
Introduction to Turtle Graphics
Aim: How do we add vectors graphically?
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
Working with Vectors.
Teaching Java using Turtles part 2
The beginning of media computation Followed by a demo
Coordinate Systems Cartesian, Relative and Polar
Presentation transcript:

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 process.  Imagine a turtle walking around a screen with a pen tied to it’s tail. Commands tell it to move and to put the pen up and down (i.e. put it’s tail up and down.)  This is a primitive form of graphics but gives us a good introduction to graphic concepts.

Example TurtleGraphics Program import TurtleGraphics.StandardPen; public class DrawSquare { public static void main(String [ ] args) { StandardPen pen = new StandardPen(); pen.up();pen.move(25);pen.turn(90);pen.move(25);pen.down(); pen.turn(90); pen.move(50); }}

Example Program Explanation import TurtleGraphics.StandardPen;  Imports the TurtleGraphics package which allows us to draw basic shapes.  StandardPen is the class we will be using.

Example Program Explanation pen.up( ); pen.move(25); pen.turn(90); pen.move(25); pen.down( );  These statements lift the pen, move it to the square’s top left corner, and lower to set it to draw.

Example Program Explanation pen.turn(90); pen.move(50);  These statements draw a square with side length of 50 pixels. Each turn forms the 90° turn at the corners.

Turtle Graphics Pen Messages Pen Message What it Does home() The pen jumps to the center of the graphics window without drawing and points north. setDirection(degrees) The pen points in the indicated directions. Due east corresponds to 0 degrees, north to 90, west to 180 and south to 270. turn(degrees) The pen adds the indicated degrees to its current direction. Positive degrees correspond to turning counterclockwise. The degrees can be integer or floating point. down() The pen lowers itself to the drawing surface up() The pen raises itself from the drawing surface move(distance) The pen moves the specified distance in the current direction. The distance can be an integer or floating- point number and is measured in pixels.

Misc. Statements on Turtle Graphics  When the StandardPen is instantiated, it is always:  In the center of the graphics window  In the down position  Pointing North.

Additional TurtleGraphics Features Pen Message What it Does setColor(Color. color) Sets the pen’s color to the specified color. import java.awt.Color; setWidth(width as int.) Sets the pen’s width to the specified width. Must be an integer. move(double x,double y) Moves the pen to the specified location relative to home(0, 0)

TurtleGraphics Color Constants  The Color class has a number of different colors available.  import java.awt.Color; redred yellowyellow blueblue orangeorange pinkpink cyancyan magentamagenta blackblack whitewhite graygray light graylight gray dark graydark gray

Setting color and width of pen Example //imports needed packages import TurtleGraphics.StandardPen; import java.awt.Color; public class DrawSquareColor //Start of class { public static void main(String [] args) //Start of Main method { StandardPen pen = new StandardPen(); //Instantiates a pen object pen.setColor(Color.red);pen.setWidth(3); pen.turn(90); pen.move(50); pen.setColor(Color.magenta);pen.setWidth(6);pen.move(50);}}