Text David Meredith Aalborg University.

Slides:



Advertisements
Similar presentations
JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
Advertisements

Using the Kinect in Processing David Meredith Aalborg University.
Processing and Java David Meredith
Purpose : To convert this string to a new character array. Return Type : char[ ] Parameters : none Declaration : public char[ ] toCharArray() Returns.
Libraries David Meredith Aalborg University.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 9 Strings.
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.
Chapter 7 Strings F To process strings using the String class, the StringBuffer class, and the StringTokenizer class. F To use the String class to process.
1 Strings and Text I/O. 2 Motivations Often you encounter the problems that involve string processing and file input and output. Suppose you need to write.
Chapter 7 Strings F Processing strings using the String class, the StringBuffer class, and the StringTokenizer class. F Use the String class to process.
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 8 Strings.
Java Programming Strings Chapter 7.
Strings An extension of types A class that encompasses a character array and provides many useful behaviors Chapter 9 Strings are IMMUTABLE.
CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Data: Programming Design and Modularization IS 101Y/CMSC 101 Computational Thinking and Design Thursday, September 26, 2013 Marie desJardins University.
IAT 334 Lab 2 Computer Graphics: Rocket, PImage. June 4, 2010IAT 3342 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
©2004 Brooks/Cole Chapter 7 Strings and Characters.
Translation and Rotation in 2D and 3D David Meredith Aalborg University.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Strings and Arrays The objectives of this chapter are:  To discuss the String class and some of its methods  To discuss the creation and use of Arrays.
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.
Exercise 1 Checklist Dreamweaver - Local Root Folder –Make sure it is properly specified in Dreamweaver  Verify Otherwise can cause problems with local.
Chapter 2 storing numbers and creating objects Pages in Horstmann.
Introduction to Computers and Programming Strings Professor: Evan Korth New York University.
Characters and Strings. Characters In Java, a char is a primitive type that can hold one single character A character can be: –A letter or digit –A punctuation.
1 Strings and String Operations  What is a Strings?  Internal Representation of Strings  Getting Substrings from a String  Concatenating Strings 
Video in Processing David Meredith Aalborg University.
Games and Simulations O-O Programming in Java The Walker School
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
Recitation 2 Main Method, API & Packages, Java Basics.
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Characters The data type char represents a single character in Java. –Character values are written as a symbol: ‘a’, ‘)’, ‘%’, ‘A’, etc. –A char value.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 5 Working with Images Starting Out with Games & Graphics in.
DHTML AND JAVASCRIPT Genetic Computer School LESSON 5 INTRODUCTION JAVASCRIPT G H E F.
Chapter 6Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 6 l Array Basics l Arrays and Methods l Programming with Arrays.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
5 BASIC CONCEPTS OF ANY PROGRAMMING LANGUAGE Let’s get started …
String Manipulation Chapter 15 This chapter explains the String facilities. You have already seen some of the main methods of the String class.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Introduction to Java Java Translation Program Structure
Java Programming Java Basics. Data Types Java has two main categories of data types: –Primitive data types Built in data types Many very similar to C++
Variables Art &Technology, 3rd Semester Aalborg University Programming David Meredith
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
11 Writing Text Session 5.1. Session Overview  Show how fonts are managed in computers  Discover the difference between bitmap fonts and vector fonts.
1 SIC / CoC / Georgia Tech MAGIC Lab Rossignac Processing  Install Processing  Learn how to edit, run, save, export,
IAT 265 Images in Processing PImage. Jun 27, 2014IAT 2652 Outline  Programming concepts –Classes –PImage –PFont.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
Chapter 5: Arrays in Java. The objectives of this chapter are:  1. To discuss the creation and use of Arrays.   2. To continue to use the String class.
17-Mar-16 Characters and Strings. 2 Characters In Java, a char is a primitive type that can hold one single character A character can be: A letter or.
HTML Structure II (Form) WEEK 2.2. Contents Table Form.
Programs and Models Almost all computer programs model some artifact – Artifact: product of civilization, either concrete or abstract, simple or complex.
David Meredith Aalborg University
Some of Chap 17.
IAT 265 PImage and PFont.
David Meredith Aalborg University
String class.
String Objects & its Methods
AP Java Unit 3 Strings & Arrays.
Object Oriented Programming (OOP) LAB # 8
Chapter 7: Strings and Characters
Chapter 2 - Introduction to C Programming
Part a: Fundamentals & Class String
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
CHAPTER 3: String And Numeric Data In Python
Chap 17 Section 3.
Chapter 2 - Introduction to C Programming
Presentation transcript:

Text David Meredith Aalborg University

Source Chapter 17 of – Shiffman, D. (2008). Learning Processing. Morgan Kaufmann. ISBN:

Overview Storing text in a String object Basic String functionality Creating and loading fonts Displaying (rendering) text

Strings The String class is an inbuilt class in Processing A String object is designed to hold a string of characters You can tell a literal String because it has double-quotes around it, e.g., println(“Some text to print to the console”); PImage img = loadImage(“filename.jpg”);

Nothing special about in-built classes Processing has lots of in-built classes like – PImage for storing images – Movie for storing a movie – Capture for storing recorded video String is just like one of these, except that it’s designed to hold strings of text String is actually a standard Java class that is made accessible in Processing – Remember that Processing is an interface to (or “window onto”) the Java programming language – Some things are visible through this window, others aren’t – String is one of the things that is visible!

Help with using Strings String is a Java class, so if you’re brave, you can find out all about it by reading the String page in the Java API, which is here vase/6/docs/api/java/lang/S tring.html Before doing this, perhaps you should first look at the Processing reference entry on Strings, which you will find here erence/String.html

What is a String? A String is basically an array of characters If we didn’t have strings, then to process some text, we’d have to do something like char[] text = {‘H’, ’e’, ’l’, ’l’, ’o’, ’ ‘, ’W’, ’o’, ’r’, ’l’, ’d’}; But because we have Strings, we can do String text = “Hello World”;

Some String methods Because a String is an object, it has some useful methods defined for it If s is a string, then s.charAt(i) returns the (i+1)th char in the String (zero-based indexing) s.length() returns the number of characters in the String

Changing case If s is a String, then s.toUpperCase() returns a new String which is the same as s except that all the letters are upper case s.toLowerCase() returns a new String which is the same as s except that all the letters are lower case

The equals() method and concatenation (‘+’ with Strings) Strings can be chained together using the ‘+’ operator If s1 and s2 are Strings, then s1 == s2 is true if s1 and s2 occupy the same place in the computer’s memory If s1 and s2 are Strings, then s1.equals(s2) is true if every character in s1 is the same as the character at the same position in s2

Concatenating Strings with other things If you concatenate a String with a non- String using the + operator, then Processing automatically finds the String representation of the non-String and concatenates this with the String…get it?

6 Steps to displaying some text 1.Choose a font by selecting “Create Font” from the Tools menu 2.Declare a PFont object 3.Load the font into the PFont object by using loadFont() 4.Specify the font to use by calling textFont() 5.Set a fill colour using fill(c) 6.Use the text() function to draw the text in the display

Example This file has to be stored in a folder called ‘data’ inside the sketch folder Use textFont() to specify the font and size. The size of the font should be the same as the original size of the created font. If it isn’t, you may get pixelation and other quality problems. The text() function takes 3 arguments: the String to be displayed and the x and y co-ordinates of the position to display the String Use fill() to specify the colour of the text to be displayed

Listing all available fonts Use PFont.list() to list all the available fonts You can use any of these fonts when you call createFont() to make a font programmatically – Rather than making it by using the “Create Font” menu item in the “Tools” menu

createFont() createFont(font,size,smoothing) takes three arguments: font is the name of the font as a String size is the size of the font in points smoothing is either true or false and indicates whether the font should be smoothed (anti- aliasing) createFont(font,size,smoothing) takes three arguments: font is the name of the font as a String size is the size of the font in points smoothing is either true or false and indicates whether the font should be smoothed (anti- aliasing) createFont allows font to be scaled to any size without pixelation

textAlign()

textWidth(String) If s is a String, then textWidth(s) returns the width of s in pixels If s is a String, then textWidth(s) returns the width of s in pixels

A Text Mirror Remember we have to “loadPixels” before we can use the pixels array % chars.length() sets charCount to 0 again when it reaches the last char in chars Remember to read the next video frame in the captureEvent callback function

Rotating and translating text Increase theta by 1 degree on each frame Make the text size oscillate from very small to about twice the original size Translate the origin to the centre of the display Make the colour oscillate from very dark to very bright magenta

Text in 3D \n inserts a hard line return in a string Use rotateX() to rotate the co- ordinate system around the X-axis

Displaying text a character at a time

Shaking letters

Letters on a circle Text must be centered on x position Must advance theta by half of this character’s width before and after printing