Fundamentals of Programming I Introduction to Graphics

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

COMPSCI 105 S Principles of Computer Science
Chapter 6.1 Visual Design. 2 Visual Design The management and presentation of visual information Two dimensional & three dimensional communication The.
Fundamentals of Python: From First Programs Through Data Structures
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphicsIntroduction Dr. Eng. Farag Elnagahy
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
Programming in Python Turtle Graphics Dr. Kristine Nagel Genie Yang Raquel Lawrence Dr. Kristine Nagel Genie Yang Raquel Lawrence Georgia Gwinnett College.
Bitmapped Images 27 th November 2014 With Mrs
Bitmapped Images. Bitmap Images Today’s Objectives Identify characteristics of bitmap images Resolution, bit depth, color mode, pixels Determine the most.
Log on and Download from website:
Co mputer Graphics Researched via: Student Name: Nathalie Gresseau Date:12/O7/1O.
Introduction to Scratch!
Objective Understand concepts used to create digital graphics. Course Weight : 15% Part Three : Concepts of Digital Graphics.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
Nov 061 Size Control How is a component’s size determined during layout and during resize operations? Three factors determine component sizes: The component’s.
Graphics and Animation Multimedia Projects Part 2.
Computer Science 111 Fundamentals of Programming I Introduction to Graphics.
Slide 1 Graphics Slide 2 Graphics A graphics package is a general purpose package used to draw pictures (graphics). Once produced, these can be saved.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
1 CSC 221: Computer Programming I Fall 2011 Fun with turtle graphics  turtle module  relative motion (setup, reset, left, right, forward, backward) 
A SIMPLE COMPUTER LANGUAGE LOGO. LOGO Introduction Logo is the simplest programming language. It.
1 COMS 161 Introduction to Computing Title: Digital Images Date: November 12, 2004 Lecture Number: 32.
INT 840E Computer graphics Introduction & Graphic’s Architecture.
Computer Science 111 Fundamentals of Programming I Introduction to Digital Image Processing.
PART TWO Electronic Color & RGB values 1. Electronic Color Computer Monitors: Use light in 3 colors to create images on the screen Monitors use RED, GREEN,
Let’s Learn 3. Modules Saenthong School, January – February 2016
© ExplorNet’s Centers for Quality Teaching and Learning 1 Objective % Understand concepts used to create digital graphics.
Adobe Photoshop CS4 – Illustrated Unit A: Getting Started with Photoshop CS4.
Today… The for loop. Introducing the Turtle! Loops and Drawing. Winter 2016CISC101 - Prof. McLeod1.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Lesson 13 – Color and Typography. 2 Objectives Understand basic color theory. Understand the color wheel. Understand how color is presented on a computer.
Graphics Basic Concepts 1.  A graphic is an image or visual representation of an object.  A visual representation such as a photo, illustration or diagram.
DISPLAY DEVICES CIS 10, Group #1 April 01, 2006 C. X. A. L. K. H. A. V. ((( L. C.
Unit 2.6 Data Representation Lesson 3 ‒ Images
BITMAPPED IMAGES & VECTOR DRAWN GRAPHICS
Objective % Explain design concepts used to create digital graphics.
Computer Graphics: An Introduction
Python Turtle Graphics
Images Data Representation.
Data Representation Images.
Image Processing Objectives To understand pixel based image processing
Pixels, Colors and Shapes
Computer Graphics Lecture 3 Computer Graphics Hardware
Binary Notation and Intro to Computer Graphics
LOGO BY Kaotip 9S.
Binary Representation in Audio and Images
Vector vs. Bitmap.
Tools and techniques.
Flash Interface, Commands and Functions
How to Convert Pictures into Numbers
Fundamentals of Programming I Introduction to Digital Image Processing
Fundamentals of Programming I Introduction to Graphics
Chapter I Digital Imaging Fundamentals
Chapter 6.1 Visual Design.
Adobe Visual Design 2.00 Identifying design elements when preparing images (10%) 7.00 Identifying design elements when preparing illustrations (1%)
COMS 161 Introduction to Computing
A Tiny Look at the Graphics Window
Chapter 6.1 Visual Design.
CSc 110, Spring 2018 Lecture 9: Parameters, Graphics and Random
Let's Learn Python and Pygame
Introduction to Media Computation
Fundamentals of Programming I Introduction to Digital Image Processing
Color and Shading Lecture 9 Mon, Sep 26, 2005.
COMS 161 Introduction to Computing
Introduction to Turtle Graphics
Digital Image Processing
A Tiny Look at the Graphics Window
Non-numeric Data Representation
Fundamentals of Python: First Programs Second Edition
Objective % Explain design concepts used to create digital graphics.
Presentation transcript:

Fundamentals of Programming I Introduction to Graphics Computer Science 111 Fundamentals of Programming I Introduction to Graphics

Text vs Graphics Early interactive computer systems used a character-based display and a keyboard (1960s) The first graphics displays allowed the drawing of simple wire-frame shapes with a pen device (Ivan Sutherland, early 1960s) The first bit-mapped display and mouse for a graphical user interface were developed in the late 1960s (Douglas Englebart at Xerox PARC)

Bitmapped Display Think of the monitor screen as a rectangular grid that is divided up into tiny square pieces Each square piece is called a picture element or pixel Each pixel can be painted black or white (monochrome) Several shades of gray (grayscale) Several (perhaps millions of) colors The values of the colors are represented as bits in a structure called a bitmap

Representing Colors: Monochrome Black and white: 0 = black, 1 = white, so just a single bit 8, 16, 128, or 256 shades of gray: 3, 4, 7, or 8 bits (why?) In general, N bits allows 2N distinct color values

Representing Colors: RGB The RGB system composes each color from red, green, and blue components Each component is an integer in the range 0..255 0 means the total absence of a color component 255 means the highest saturation of a color component 256 * 256 * 256 = 16,777,216 distinct color values

Representing Colors: RGB Think of each color value as a tuple of integers of the form (<r>, <g>, <b>) RGB Value Color (0, 0, 0) Black (255, 0, 0) Red (0, 255, 0) Green (0, 0, 255) Blue (127, 127, 127) Medium Gray (255, 255, 255) White

Turtle Graphics In the late 1960’s, Seymour Papert and his associates at M.I.T. invented LOGO, a programming language intended to teach programming to children Turtle graphics was initially a part of LOGO that allowed programmers to draw pictures easily on a computer

Turtle Graphics The turtle is an object that has a position in a drawing window This object can be told to turn a number of degrees, move a given distance, move to a new position, and change its color and line width If the turtle’s pen is down, it draws a line; otherwise, it just moves without drawing

The turtle Module A standard Python module Includes a Turtle type with methods for getting turtle objects to do things

The Turtle Drawing Window The turtle appears as an icon Initial position: (0, 0) Initial direction: East (0°) Color: black Line width: 1 pixel Pen: down (ready to draw) 90° x-axis (0,0) (0,0) 180° 0° y-axis 270°

Instantiating a Turtle >>> from turtle import Turtle >>> sleepy = Turtle() Pops up a drawing window whose drawing area has a default height and width of 500 pixels A configuration file can change these initial dimensions

Some Turtle Methods home() # Return to (0, 0) and 0° (east) down() # Enable drawing up() # Disable drawing forward(distance) # Go distance in current direction goto(x, y) # Go to (x, y) left(degrees) # Add degrees to current direction setheading(degrees) # Make degrees the new direction width(width) # Set width of pen in pixels pencolor(r, g, b) # Red, green, blue compound

Move a Given Distance >>> from turtle import Turtle >>> sleepy = Turtle() >>> sleepy.forward(50) Move 50 pixels in the current direction, which is 0° (east)

Move to a Given Position >>> from turtle import Turtle >>> sleepy = Turtle() >>> sleepy.goto(0, 50) Move to location (0, 50)

Print the State of the Turtle >>> from turtle import Turtle >>> sleepy = Turtle() >>> sleepy.goto(0, 50) >>> print(sleepy.position(), sleepy.pencolor(), \ sleepy.heading(), sleepy.isdown()) (0.00,50.00) black 0.0 True The state of an object includes the values of its attributes at any given time

Set the Direction 270° is due south >>> sleepy.setheading(270) 270° is due south The turtle’s icon changes direction

Change the Pen’s Color RGB value for the brightest red >>> sleepy.setheading(270) >>> sleepy.pencolor(255, 0, 0) RGB value for the brightest red Alternatively, could use “red” Changes the icon’s outline color

Move Due South Returns to the origin, drawing a red line >>> sleepy.setheading(270) >>> sleepy.pencolor(255, 0, 0) >>> sleepy.forward(50) Returns to the origin, drawing a red line

Pick Up the Turtle’s Pen >>> sleepy.setheading(270) >>> sleepy.pencolor(255, 0, 0) >>> sleepy.forward(50) >>> sleepy.up() Won’t draw when moved now

Move Without Drawing Won’t draw when moved now >>> sleepy.setheading(270) >>> sleepy.pencolor(255, 0, 0) >>> sleepy.forward(50) >>> sleepy.up() Won’t draw when moved now

Turn a Given Number of Degrees >>> sleepy.up() >>> sleepy.forward(10) >>> sleepy.right(45) Subtract 45 ° from 0 °, turning clockwise

Reset to Draw Again Double the pen width Hide the turtle’s icon >>> sleepy.up() >>> sleepy.forward(10) >>> sleepy.right(45) >>> sleepy.width(2) >>> sleepy.hideturtle() >>> sleepy.down() >>> sleepy.forward(25) Double the pen width Hide the turtle’s icon Place the pen down Move forward

Go Home, Sleepy, Go Home Move to the origin and face east >>> sleepy.up() >>> sleepy.forward(10) >>> sleepy.right(45) >>> sleepy.width(2) >>> sleepy.hideturtle() >>> sleepy.down() >>> sleepy.forward(25) >>> sleepy.home() >>> sleepy.showturtle() Move to the origin and face east

Define Some Functions def drawSquare(t, x, y, length): """Use t to draw a square with corner point (x, y) and length.""" t.up() t.goto(x, y) t.setheading(270) t.down() for count in range(4): t.forward(length) t.left(90)

Define Some Functions def drawSquare(t, x, y, length): """Use t to draw a square with corner point (x, y) and length.""" t.up() t.goto(x, y) t.setheading(270) t.down() for count in range(4): t.forward(length) t.left(90) from turtle import Turtle sleepy = Turtle() sleepy.hideturtle() drawSquare(sleepy, 0, 50, 100)

Define Some Functions def drawPolygon(t, vertices): """Use t to draw a polygon from a list of vertices. The list has the form [(x1, y1), …, (xn, yn)].""" t.up() (x, y) = vertices[0] t.goto(x, y) t.down() for (x, y) in vertices: Note that (x, y) = <a tuple> allows the values in a tuple to be assigned to distinct variables

Define Some Functions def drawPolygon(t, vertices): """Use t to draw a polygon from a list of vertices. The list has the form [(x1, y1), …, (xn, yn)].""" t.up() (x, y) = vertices[0] t.goto(x, y) t.down() for (x, y) in vertices: from turtle import Turtle sleepy = Turtle() sleepy.hideturtle() drawPolygon(spleepy, [(0,0), (0, 60), (60, 0)])

Define Some Functions def drawTriangle(t, x1, y1, x2, y2, x3, y3): """Draws a triangle with the given vertices.""" drawPolygon(t, [(x1, y1), (x2, y2), (x3, y3)]) def drawSquare(t, x, y, length): """Draws a square with corner point (x, y) and length.""" drawPolygon(t, [(x, y), (x + length, y), (x + length, y - length), (x, y - length)])

Define Some Functions def drawFlower(t, x, y, width): """Draws a flower at (x, y).""" t.up() t.goto(x, y) t.down() for petals in range(36): for side in range(4): t.forward(width) t.left(90) t.left(10)

Define Some Functions def drawFlower(t, x, y, width): """Draws a flower at (x, y).""" t.up() t.move(x, y) t.down() for petals in range(36): for side in range(4): t.move(width) t.turn(90) t.turn(10) from turtle import Turtle sleepy = Turtle() sleepy.hideturtle() drawFlower(sleepy, 0, 0, 60)

Turtles as artists and mathematicians For Wednesday Turtles as artists and mathematicians