Software project Gnome Graphics Olga Sorkine Andrei Scharf Office: Schreiber 002, 03-6405360 Web:

Slides:



Advertisements
Similar presentations
1 Exceptions: An OO Way for Handling Errors Rajkumar Buyya Grid Computing and Distributed Systems (GRIDS) Laboratory Dept. of Computer Science and Software.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 12 Introduction to ASP.NET.
Chapter 11 Introduction to Programming in C
Introduction to C Programming
Credit hours: 4 Contact hours: 50 (30 Theory, 20 Lab) Prerequisite: TB143 Introduction to Personal Computers.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Chapter 7: Arrays In this chapter, you will learn about
2007 Pearson Education, Inc. All rights reserved C Structures, Unions, Bit Manipulations and Enumerations.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
1 Structures. 2 Structure Basics A structure is a collection of data values, called data members, that form a single unit. Unlike arrays, the data members.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 230 Structures Functions and Arrays Dale Roberts, Lecturer Computer.
Copyright 2006 by Pearson Education 1 Building Java Programs Supplement 3G: Graphics.
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
C Language.
Decisions If statements in C.
Lectures 10 & 11.
Lesson One: The Beginning
1 More on Applets Overview l Changing Colors l Changing Fonts & Styles l Applet Life-Cycle l Input using Dialog Window l Input using HTML parameters l.
CS2984: Introduction to Media Computation Drawing directly on images.
Software project Gnome Graphics Olga Sorkine Andrei Scharf Office: Schreiber 002, Web:
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January.
CSE Lecture 6 – Complex Numbers & Images
©College of Computer and Information Science, Northeastern UniversityApril 22, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 4.
CSE202: Lecture 2The Ohio State University1 Variables and C++ Data Types.
CSE 803 Using images in C++ Computing with images Applications & Methods 2D arrays in C++ Programming project 4.
1 Lecture 2  Input-Process-Output  The Hello-world program  A Feet-to-inches program  Variables, expressions, assignments & initialization  printf()
CS430 © 2006 Ray S. Babcock CS430 – Image Processing Image Representation.
Image representation methods. Bitmap graphic method of a black-and-white image.
Last time 3 main components to a computer system Types of computers Talked about software – task oriented What are some kinds of data that a computer works.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
CSC – Java Programming II Lecture 9 January 30, 2002.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
By Sidhant Garg.  C was developed between by Dennis Ritchie at Bell Laboratories for use with the Unix Operating System.  Unlike previously.
C Programming language
C Tokens Identifiers Keywords Constants Operators Special symbols.
PROCESSING & JAVA An Introduction to Computing. Objectives Be able to state and apply phases of development Be able to state and describe the goals of.
Computer Science 112 Fundamentals of Programming II Graphics Programming.
Abstraction IS 101Y/CMSC 101 Computational Thinking and Design Tuesday, September 9, 2014 Carolyn Seaman Susan Martin University of Maryland, Baltimore.
Summary of what we learned yesterday Basics of C++ Format of a program Syntax of literals, keywords, symbols, variables Simple data types and arithmetic.
Introduction to PHP A user navigates in her browser to a page that ends with a.php extension The request is sent to a web server, which directs the request.
Information Processes and Technology Multimedia: Graphics.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process Dale/Weems.
CSE1222: Lecture 2The Ohio State University1. mathExample2.cpp // math example #include using namespace std; int main() { cout
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
1 CSE1301 Computer Programming: Revision. 2 Topics Type of questions What do you need to know? About the exam Exam technique Staff consultation Revision.
Graphics and Images Graphics and images are both non-textual information, that can be displayed and printed. These images may appear on screen as well.
Object-Oriented Programming •Object-Oriented Programming (OOP) allows you to create your program based upon modeling objects.  Your program’s properties.
1 Chapter 2 C++ Syntax and Semantics, and the Program Development Process.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
CS140: Intro to CS An Overview of Programming in C by Erin Chambers.
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
CS 325 Introduction to Computer Graphics 04 / 12 / 2010 Instructor: Michael Eckmann.
How Computers Work Part 3 18 February Data Types  Computer doesn’t know what the bits represents or what format is being used  Computer assumes.
©College of Computer and Information Science, Northeastern UniversityFebruary 21, CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
CS 1704 Introduction to Data Structures and Software Engineering.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 1 Scott Marino.
C is a high level language (HLL)
CS1010: Programming Methodology
1 CS 177 Week 7 Recitation Slides Modifying Sounds using Loops + Discussion of some Exam Questions.
1 Sections 5.1 – 5.2 Digital Image Processing Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Windows Programming Lecture 03. Pointers and Arrays.
Multidimensional Arrays
Representation of image data
Introduction to Programming
Variables in C Topics Naming Variables Declaring Variables
C Language B. DHIVYA 17PCA140 II MCA.
PPM file format CSE 681.
EECE.2160 ECE Application Programming
Presentation transcript:

Software project Gnome Graphics Olga Sorkine Andrei Scharf Office: Schreiber 002, Web:

Course outline Two classes at the beginning of the semester Work in groups of TWO. Address questions to me in person, in the forum or by (better the forum, so everybody can benefit from it). Handout next week: –Initial design –Sample UNIX program

Outline cont. The project definition is on the web-page Get updated at the web page Every Week Programming language: C or C++ Operating system: linux in classroom January-2004, the final project.

Grading Written material: more details are in the project definition Runtime: –Run tests and give a pass/fail to each test

Project overview Interpreter for graphical program language: GNOME Program controls the behavior of a small creature – the gnome – that walks and draws on a white canvas.

Overview cont. Canvas: –n-by-m pixels –white in the beginning of execution Gnome: –Width of gnome’s paintbrush is 1 pixel –Anytime: the gnome has certain position on the canvas and a heading direction

Project goal Write parser that reads GNOME language: –GNOME programming language Implement GNOME programming language in C/C++ to execute various GNOME programs: –GNOME graphics

GNOME programming language Built-in commands (Forward, Back…) Built-in variables ($PositionX, …) User defined routines (ROUTINE Square) User-defined variables ($len=10) Operators (+, -, …) Supported functions (sin, cos, …) Supported commands (if, else…)

ROUTINE main { CanvasSize(100, 100) $len = 10 DrawSegment($len) TurnRight(90) DrawSegment($len) TurnRight(90) DrawSegment($len) TurnRight(90) DrawSegment($len) } ROUTINE DrawSegment($Length) { Forward($Length) } Sample program

Variables and Expressions Built-in Variables: –$PositionX –$PositionY User defined Variables: – $len Expressions are of the form: – –Function(value) –Function(value, value) $x = 5 $y = 17 $x2 = $x * $x $y2 = $y * $y $len2 = $x2 + $y2 $len = sqrt($len2)

Routines Routines receive zero or more parameters Can be recursive Do not return any value ROUTINE Square($len) { DrawSegment($len) TurnRight(90) DrawSegment($len) TurnRight(90) DrawSegment($len) TurnRight(90) DrawSegment($len) } ROUTINE Recurse($face, $grad) { if ($face>=0) DrawSegment(10) TurnRight($grad) $face = $face-1 Recurse($face, $grad) endif }

GNOME Graphics Canvas: rectangle of size n x m Coordinate system: origin (0,0) is on the canvas in the lower left corner Position of gnome is in floating point (5.5, 17.06). Canvas is a discrete pixel grid Mapping gnome drawing to canvas: Rasterization

Bitmap with 1bit per pixel (black/white 1/0) Data structure: typedef struct { int width; int height; unsigned char *bits; /* pointer to the bits array*/ } GnomeBitmap; Each row is stored in integer amount of bytes (if the number of pixels per row is not some multiplication of 8, last bits are ignored) Canvas

Black/White Bitmap unsigned char bottom_left_corner[] = { 0xff, 0xa0, /* */ 0x80, 0x0, /* */ 0x80, 0x0 /* */ }; GnomeBitmap canvas; canvas.width = 10; canvas.height = 10; canvas.bits = bottom_left_corner;

Rasterization Raster: coloring the appropriate pixels so that the resulting image resembles the lines that the gnome drew

Constraints Initialization: –gnome’s initial position/heading –canvas size Walking: –The gnome is not allowed to step out of the canvas –If the gnome is attempting to walk outside of the canvas: execution stops, output the resulting image created so far.

PGM file format PGM (portable graymap) “magic number” P2 Whitespace (blanks, TABs, CRs, LFs). Width Height Maximum gray value Width * Height gray values, ASCII decimal, between 0 and maximum #Comment Max line length = 70 characters. P2 # feep.pgm

Bresenham’s Midpoint Algorithm Goal: Draw the line between (x 1,y 1 ) and (x 2,y 2 ), m=dy/dy onto the discrete canvas. Assume: m<1, x 1 <x 2 and y 1 <y 2 At each step: x = x+1 y = ? Decision: –Calculate error between candidate pixels’ centers and real line (by looking at the vertical distance) –Choose pixel with the smaller error

PseudoCode m = (y 2 -y 1 )/( x 2 -x 1 ) i 1 = floor(x 1 ) j = floor(y 1 ) i 2 = floor(x 2 ) e = -(1-(y 1 - j)-m(1-(x 1 -i 1 ))) for i = i 1 to i 2 TurnOnPixel(i, j) if (e >= 0) j += 1 e -= 1.0 end if i += 1 e+= m end for

Flood Fill algorithm Problem: given a 2D closed polygon, fill its interior on a graphic display.

Pseudo Code void floodFill (int x, int y, int newColor) { color = readPoint(x,y); if (x,y) is on canvas boundary roll back; if ((x,y) not on boundary and color != newColor) { setPixel(newColor, x, y); floodFill(x+1, y, newColor); floodFill(x, y+1, newColor); floodFill(x-1, y, newColor); floodFill(x, y-1, newColor); }

Requirements A working project Documentation Examples

Developing software Specifications Final product Executable Documentation Examples [+User Manual] Design Implement Test Documentation User Manual

Design – Modules (modularity…) Manage a single independent entity/ one responsibility Hold a set of functionalities Modules interact through an interface List module –create –insert –delete –find –ComputeIntervals List module –create –insert –delete –find –ComputeIntervals

Modules You know your modules are OK if: –You can name your modules and their responsibility –You can define the interaction –You can specify the services modules require from one another Low Level I/O ReadBlock WriteBlock File Manager Read(bytes) Write(bytes) SetPosition Directory Manager User File Manager

Design Read the project definition carefully and then: Modules diagram Description of modules Data structures

Next week More about the project Software engineering Questions

Makefile Dependency tree –DAG actually myprogram : f1.o f2.o f3.o f1.o: f1.c myslist.h f2.o: f2.c graphics.h globals.h f3.o: f3.c globals.h myprogram f1.o f2.of3.o f1.cmylist.hf2.cf3.cglobals.h graphics.h

Makefile Dependency tree Commands myprogram : f1.o f2.o f3.o gcc –o myprogram f1.o f2.o f3.o f1.o: f1.c myslist.h gcc –c –Wall f1.c f2.o: f2.c graphics.h globals.h gcc –c –Wall f2.c f3.o: f3.c globals.h gcc –c –Wall f3.c

Makefile Dependency tree Commands Automatic variables what stands before the colon (:) –$^ everything that stands after the colon –$< the first thing that stands after the colon myprogram : f1.o f2.o f3.o gcc –o $^ f1.o: f1.c myslist.h gcc –c –Wall $< f2.o: f2.c graphics.h globals.h gcc –c –Wall $< f3.o: f3.c globals.h gcc –c –Wall $<

Makefile Dependency tree Commands Automatic variables Variables CFLAGS = -c -g –Wall LIBS = -lm myprogram : f1.o f2.o f3.o gcc –o $^ $(LIBS) f1.o: f1.c myslist.h gcc –c $(CFLAGS) $< f2.o: f2.c graphics.h globals.h gcc –c $(CFLAGS) $< f3.o: f3.c globals.h gcc –c $(CFLAGS) $<

Makefile Dependency tree Commands Automatic variables Variables Implicit rules Multiple targets –Default: make all –“make clean” More information –NOVA: “tkinfo make” CFLAGS = -g –Wall LIBS = -lm.c.o: $(CC) –c $(CFLAGS) $< all: myprogram myprogram : f1.o f2.o f3.o gcc –o $^ $(LIBS) f1.o: f1.c myslist.h f2.o: f2.c graphics.h globals.h f3.o: f3.c globals.h clean: rm –f *.o *~

Unix program Built of three.c files and appropriate.h files –main.c –strrdup.c –Another.c –Makefile

Debugging in Unix (gdb) Compile using “gcc -g” gdb myprogram l main - list the function main, l misc.c:foo - list foo() in misc.c b 52 - set a break point at line 52 help where prints the stack up,down move in the stack, to inspect variables of calling routines. run the program n,s step over and step into ddd – gdb + graphical interface (a bit more convenient) Resources Online help while using GDB. Quick reference card, download from the web-page > “info GDB” command on the unix