Computer Programming Methodology Files and Colors

Slides:



Advertisements
Similar presentations
Technology ICT Option: Data Representation. Data Representation In our everyday lives, we communicate with each other using analogue data. This data takes.
Advertisements

Programming In C++ Spring Semester 2013 Lecture 8 Programming In C++, Lecture 8 By Umer Rana.
 2005 Pearson Education, Inc. All rights reserved Introduction.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
10-Jun-15 Introduction to Primitives. 2 Overview Today we will discuss: The eight primitive types, especially int and double Declaring the types of variables.
Introduction to Primitives. Overview Today we will discuss: –The eight primitive types, especially int and double –Declaring the types of variables –Operations.
1 Programming & Programming Languages Overview l Machine operations and machine language. l Example of machine language. l Different types of processor.
2.01 Understand Digital Raster Graphics
March 2006Taner Erig - EMU2-1 Metamorphosis of Information How is information represented and how do computers store information?
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
Management Information Systems Lection 06 Archiving information CLARK UNIVERSITY College of Professional and Continuing Education (COPACE)
 COMPUTER & INDUSTRY LANGUAGE For Commercial Art.
ULI101: XHTML Basics (Part III) Introduction to XHTML / Continued … Block-Level vs. Inline Elements (tags) Manipulating Text,  , Text Characteristics,,,,,,,,,,,,,,,
Java: Chapter 1 Computer Systems Computer Programming II.
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Data Representation CS280 – 09/13/05. Binary (from a Hacker’s dictionary) A base-2 numbering system with only two digits, 0 and 1, which is perfectly.
Introduction to Java Thanks to Dan Lunney (SHS). Java Basics File names The “main” method Output to screen Escape Sequence – Special Characters format()
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
CIS 260: App Dev I. 2 Programs and Programming n Program  A sequence of steps designed to accomplish a task n Program design  A detailed _____ for implementing.
Chapter 2: Java Fundamentals
1 Week 12 l Overview of Streams and File I/O l Text File I/O Streams and File I/O.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Fall 2002CS 150: Intro. to Computing1 Streams and File I/O (That is, Input/Output) OR How you read data from files and write data to files.
1 WELCOME TO CIS 1068! Instructor: Alexander Yates.
Introduction to Computing Concepts Note Set 12. Writing a Program from Scratch public class SampleProgram1 { public static void main (String [] args)
Lab 01-2 Objectives:  Writing a Java program.  How to send output to the command line console.  Learn about escape sequences.  Learn how to compile,
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) { public static void main(String[]
Data Representation. What is data? Data is information that has been translated into a form that is more convenient to process As information take different.
Chapter -7 Basic function of Input/output system basics and file processing Stream classes : I/O Streams. A stream is a source or destination for collection.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Input and Output.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
Data Representation. In our everyday lives, we communicate with each other using analogue data. This data takes the form of: Sound Images Letters Numbers.
DATA Unit 2 Topic 2. Different Types of Data ASCII code: ASCII - The American Standard Code for Information Interchange is a standard seven-bit code that.
UNITS OF MEASUREMENT 2.01 Understand Digital Raster Graphics.
Text and Images Key Revision Points.
28 Formatted Output.
User Input ICS2O.
Data Representation Images.
2.01 Understand Digital Raster Graphics
CS0007: Introduction to Computer Programming
CSC201: Computer Programming
2.01 Understand Digital Raster Graphics
hardware bits and bytes Java
Chapter 3 GC 101 Java Fundamentals.
Yanal Alahmad Java Workshop Yanal Alahmad
Reading Netpbm Images.
2.01 Understand Digital Raster Graphics
Computer Programming Methodology Introduction to Java
Units of Measurement, Image Resolution, & Color Mode
Computer Programming Methodology File Input
Microprocessor and Assembly Language
Chapter 2 part #3 C++ Input / Output
Statements, Comments & Simple Arithmetic
Ch2: Data Representation
2.01 Understand Digital Raster Graphics
Java Tutotrial for [NLP-AI] 2
2.01 Understand Digital Raster Graphics
2.01 Understand Digital Raster Graphics
The keyboard is the standard input device.
Introduction to Primitives
Introduction to Primitives
Chapter 2 part #3 C++ Input / Output
Option: Data Representation
Review of Previous Lesson
Binary CSCE 101.
Unit 3: Variables in Java
2.01 Understand Digital Raster Graphics
Computer Programming-1 CSC 111
Option: Data Representation
Presentation transcript:

Computer Programming Methodology Files and Colors COS 130 Computer Programming Methodology Files and Colors

Files May be a device, like a printer Or a section of the disk (document) By default the input is the keyboard By default the output is the screen We can redirect this with > < To get things into the program we use read instructions To get things out of the program we use write or print instructions

Letters vs. Numbers “11” is not the same as 11 “11” is two letters that happen to be ‘1’ and ‘1’ 11 is a number that we can do math with In the computer “11” is 0011000100110001 11 is 1011

Text Files Text files have only characters (letters) Many programs know how to look at text files (Notepad, etc.) It is possible to use only text files However, For some things text files become very large and inefficient.

Binary Files May be much smaller Allows numbers to be saved in the format we need for computation, without translating back and forth to characters However, Programs must be written specifically for the format used.

Binary Numbers “Natural” for the computer Base 2 Roll to the next column every time we reach 2

Decimal 123 Ones 100 Tens 101 Hundreds 102 Binary 1010 Ones 20 Twos 21 Fours 22 Eights 23

Let’s Count Decimal Binary 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111

Red, Green, Blue (RGB) Model http://en.wikipedia.org/wiki/RGB_color_model How to Represent a Color with 1’s and 0’s

RGB Model For each pixel (spot) use 3 numbers Each number is between 0 – 255 (inclusive) First number is the Red value Second number is the Green value Third number is Blue value The higher the number the greater the color intensity

Examples Red 255 0 0 0 255 0 Green 0 0 255 Blue

PPM Format A file header A sequence of pixels Tells what the rest of the file is like Metadata A sequence of pixels As many as we said in the header Each pixel is an RGB triple

PPM Header P6 White spaces Width using ASCII (letters) in decimal Height using ASCII (letters) in decimal Max color value using ASCII (letters) in decimal A SINGLE White space # to end of line are comments, they may occur anywhere in the header

PPM Header Example P6 800 600 255 P6 #Image by John Hunt #This is a rainbow 800 #Width 600 #Height 255 #This many shades

Writing to Files System.out.print(…); Prints characters Always takes a single argument Converts argument to a String Example System.out.print(“The “); System.out.print(“quick “); System.out.print(“brown fox”); Outputs The quick brown fox

Writing to Files System.out.println(…); Like System.out.print But, goes to the next line This varies depending on system Example System.out.println(“The “); System.out.println(“quick “); System.out.println(“brown fox”); Outputs The quick brown fox

Writing to Files Both print and println can use special control characters \n puts a new line character in. In most situations this causes the text to go to the next line. \t puts a tab character in. In most situations this causes multiple spaces to be displayed.

Writing to Files Example Outputs System.out.print(“The \n“); System.out.println(“quick \n“); System.out.println(“brown fox\n”); Outputs The quick brown fox

Writing to Files A Caution System.out.println(); uses two characters to move to a new line on MS Windows PPM allows only a single white space character at the end of a header To avoid this use System.out.print(“\n”); which will always use just a single new line character

Writing to Files System.out.write(…); Writes binary Will use the least number of bytes Example System.out.write(255); System.out.write(0); Example int red = 255; int green = 0; int blue = 0; System.out.write(red); System.out.write(green); System.out.write(blue);

Write the whole file When writing to disk, using write, your program puts data in memory, then moves it in big blocks to disk When your program ends the data in memory is thrown away without being written You must tell your program when to wrap it up Use System.out.flush();

Example public class Flush { public static void main(String args[]) { for(int i = 0; i < 800; i=i+1){ System.out.write(i); } System.out.flush();

What does this print out? A Last Trick int numTimes = 100; for(int i=0; i < numTimes; i=i+1) { System.out.println(i%4); } What does this print out?