Checkerboard Examples Top Down Design. The Problem On a checkerboard where locations are numbered similar to java coordinates, draw a rectangle using.

Slides:



Advertisements
Similar presentations
Cutting Created by Inna Shapiro ©2008 Problem 1 The figure on the right is composed of three equal squares. Can you cut it into four equal parts?
Advertisements

RenderMan - Writing RenderMan Shaders (2)-. Transforming Tiles Transforming texture coordinates has an "inverse" effect on the appearance of the pattern.
Drawing In One-Point Perspective
Android UserInterfaces Nasrullah Niazi. overView All user interface elements in an Android app are built using View and ViewGroup objects. A View is an.
Graphics Shapes. Setup for using graphics You have to import the graphics library You can use either “import graphics” or “from graphics import *” or.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Laboratory Study II October, Java Programming Assignment  Write a program to calculate and output the distance traveled by a car on a tank of.
Graphics You draw on a Graphics object The Graphics object cannot directly be created by your code, instead one is generated when the method paintComponent.
Working with images and scenes CS 5010 Program Design Paradigms “Bootcamp” Lesson 2.5 TexPoint fonts used in EMF. Read the TexPoint manual before you delete.
Introduction to shapes
Python Programming, 2/e1 CS177: Programming in Multimedia Objects Recitation Topic: Graphics Library.
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
Drawing Objects with Illustrator 1.Start a new image in RGB mode. 2.Size 1024 X Unit = pixels 4.Go to View > Show Grid to turn on the grid. 5.Go.
Drinks Bottle Using CREO DEVELOPMENT
Display of Objects on Screen. COUNTERS b A horizontal counter represents the horizontal position of the monitor’s electron beam. b A vertical counter.
ObjectDraw and Objects Early Chris Nevison Barbara Wells.
Section 1.2: Drawing a UFO (conclusion). Last time… ● Using figure 1, we can now find a UFO’s location (using the X and Y functions). ● And, we can now.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
1 CS428 Web Engineering Lecture 10 Images, Tables, Forms, Border-Radius (CSS – V)
Multiplying Polynomials
3Rex Task Task 1 Task 2 Task 3 Task 4 Task 5 Task 6 Task 7 Task 8
Final Exam Chess Game.
COMPSCI 101 Principles of Programming Lecture 27 - Using the Canvas widget to draw rows and columns of shapes.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
CS 450: Computer Graphics PIXEL AdDRESSING AND OBJECT GEOMETRY
Element. The element Used to dynamically draw graphics using javascript. Capable of drawing paths, circles, rectangles, text, and images.
CS1315: Introduction to Media Computation Referencing pixels directly by index number.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Java course. Assignment #2, due: Feb. 27, (20) (a) Tell the difference between the abstract class and the interface. (b) Tell the difference between.
18 yds 3 yds 18ft 6ft 7ft. Surface Area Part 1 Work Explain 1. Units Changed click HERE to seeHERE 2. Simplified parts: 2 rect. 9ft by 24ft 2 rect. 6ft.
Divide into meridian sections – Gore development
Volume of prisms and cylinders
Some Graphics CS303E: Elements of Computers and Programming.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
Calculating the area of a leaning triangle. Calculating Area.
Dear Power point User, This power point will be best viewed as a slideshow. At the top of the page click on slideshow, then click from the beginning.
1 A Simple Applet. 2 Applets and applications An applet is a Java program that runs on a web page Applets can be run within any modern browser To run.
Make a Model A box company makes boxes to hold popcorn. Each box is made by cutting the square corners out of a rectangular sheet of cardboard. The rectangle.
Constructing Square Roots of Positive Integers on the number line
IOT POLY ENGINEERING 2-19 November 29, 2010 Your drawing space is 10” wide by 7 ¼” high. Calculate the horizontal starting point and the vertical starting.
Midterm: Question 1 (35%) (30 minutes) Write an assembly program to draw a rectangle. – (5%) Show a message to ask for information of the rectangle – (5%)
+ This step by step tutorial demonstrates drawing a keyboard illustration using rectangles, grids, move and transform effects.
Programming for Art: Arrays – 2D ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 16 Fall 2010.
Creating Scenarios In Greenfoot. Greenfoot Scenarios are made up of: Greenfoot Scenarios are made up of: A World class. A World class. Actor classes.
PyGame - Unit 1 PyGame Unit – – Introduction to PyGame.
Basic Graphics 03/03/16 & 03/07/16 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
Squared and Cubed Conversion Factors
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Over the recent years, computer vision has started to play a significant role in the Human Computer Interaction (HCI). With efficient object tracking.
CS552: Computer Graphics Lecture 16: Polygon Filling.
Graphical Output Basic Images.
Basic Principles Photogrammetry V: Image Convolution & Moving Window:
Adapted from slides by Marty Stepp and Stuart Reges
Intro & Point-to-Box, Circle-to-Circle, Point-to-Circle
Chapter 3 Drawing In the World.
2.2 Multiply Polynomials Multiply a monomial and a polynomial
3.5 Graphs in Three Dimensions
CSc 110, Spring 2017 Lecture 6: Parameters (cont.) and Graphics
CS 106A, Lecture 12 More Graphics
2.2 Multiply Polynomials Multiply a monomial and a polynomial
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Coding Concepts (Sub- Programs)
Orthogonal Base Cartesian Coordinate System Works in general:
The coordinate system Susan Ibach | Technical Evangelist
ECE 448: Spring 2016 Lab 5 Julia Set Fractal.
Working with images and scenes
Op Art Directions.
Presentation transcript:

Checkerboard Examples Top Down Design

The Problem On a checkerboard where locations are numbered similar to java coordinates, draw a rectangle using checker pieces. You will be given the top left coordinate of the checkerboard, the size of individual squares, the location and dimensions of the rectangle to be drawn Create disks with radius one third of the square widths

Examples

The Main Algorithm Given : (cbx, cby) : top left corner of checkerboard width : the width of one square rx, ry, rwidth, rheight : rectangle paremeters 1- Draw the checkerboard on screen 2- Put the pieces in a rectangular form (So here the big decision is to separate these two tasks. Instead of drawing 64 more complex pieces, we will draw 64 + rwidth * rheight simpler objects (hopefully))

Observation Here we have two different types of coordinates : coordinates in pixel locations, and coordinates in checkerboard positions. In order to be able to swiftly go back and forth between these two different systems, let’s introduce conversion functions. What type of functions do we need?

Conversions We need a function that, given a checkerboard coordinate, returns the pixel coordinate of the top left corner of that square. Let’s call the function cb2pixels, cb being short for checkerboard. What inputs are needed, and what will cb2pixels output?

cb2Pixels function function [ px, py ] = cb2pixels( rx, ry, x, y, width) %CB2PIXELS Converts a checkerboard position to pixel positions % Given a checkerboard position (rx,ry), and board parameters, % returns x and y coordinates in pixels. px = x + width * (rx-1); py = y + width * (ry-1);

Pixels2cb? Do we need to convert from pixel positions to board locations? No need at this point. We could have needed that if the user could click on the board, and we want to know which location was clicked.

1-Draw the checkerboard For i= 1 to 8 do for j=1 to 8 do if (i+j) is even draw a colored square at (i,j) else draw a white square (i,j)

Draw a White square? Since the background is already white, just draw a boundary rectangle Given x, y, cbx, cby, and width [px py] = cb2pixels(x, y, cbx, cby, width) drawHorizontalLine(px, px + width, py, g) drawHorizontalLine(px, px + width, py + width, g) drawVerticalLine(py, py + width, px, g) drawVerticalLine(py, py + width, px+width, g)

Draw a Colored Rectangle? Homework question

Draw a chessboard Rectangle? We already know how to do this using pixels Given rx, ry, rwidth, rheight, width for i=rx to rx + rwidth – 1 do for j=ry to ry + rheight – 1 do draw a disk to location (i, j)

Draw a Piece? Given cbx, cby, width, x, y [px py] = cb2pixels(x, y, cbx, cby, width) cx = px + width/2 cy = py + width/2 cradius = width/3 Draw a disk centered at (cx, cy) with radius cradius

Decomposition of our problem Draw a checkerboard Rectangle Draw the checkerboard Draw white square Draw Horizontal Line Draw Vertical Line Draw colored square Draw the rectangle using pieces Draw disk

drawCheckerBoardRectangle.m function drawCheckerBoardRectangle(cbx, cby, width, rx, ry, rwidth, rheight, g) %DRAWCHECKERBOARDRECTANGLE Draws a rectangular pattern on checkerboard % cbx, cby being the top left corner of the checkerboard, this function % first draws it with squares of size width, and then draws a rectangle % using pieces. rx,ry is the top left corner of the rectangle, rwidth and % rheight are the dimensions of the rectangle drawCheckerBoard(cbx, cby, width, g); drawRectangularPieces(cbx, cby, width, rx, ry, rwidth, rheight, g);

drawCheckerBoard.m function drawCheckerBoard(cbx, cby, width, g) for i= 1:8 for j=1:8 if (mod(i+j, 2) == 0) drawColoredSquare(i,j, cbx, cby, width, g) else drawWhiteSquare(i,j, cbx, cby, width, g) end

drawWhiteSquare.m function drawWhiteSquare(x, y, cbx, cby, width, g) [px py] = cb2pixels(x, y, cbx, cby, width); drawHorizontalLine(px, px + width, py, g) drawHorizontalLine(px, px + width, py + width, g) drawVerticalLine(py, py + width, px, g) drawVerticalLine(py, py + width, px+width, g)

drawColoredSquare.m function drawColoredSquare( x, y, cbx, cby, width, g ) [px py] = cb2pixels(x, y, cbx, cby, width); drawGreyRectangle(px, py, width, width, g)

drawGreyRectangle.m function drawGreyRectangle(x,y, width, height, g) startsWithBlack = true; for cY=y:y + height isNextBlack = startsWithBlack; for cX = x:x + width if (isNextBlack) putPixel(cX, cY, g); end isNextBlack = ~isNextBlack; end startsWithBlack = ~startsWithBlack; end

drawRectangularPieces.m function drawRectangularPieces(cbx, cby, width, rx, ry, rwidth, rheight, g) for i = rx : (rx + rwidth - 1) for j = ry : (ry + rheight - 1 ) drawBlackPiece(i, j, cbx, cby, width, g); end

drawBlackPiece.m function drawBlackPiece(x, y, cbx, cby, width, g) [px py] = cb2pixels(x, y, cbx, cby, width); cx = px + width/2; cy = py + width/2; cradius = width/3; drawDisk(cx, cy, cradius, g)