IAT 265 PImage and PFont.

Slides:



Advertisements
Similar presentations
Image Processing … computing with and about data, … where "data" includes the values and relative locations of the colors that make up an image.
Advertisements

A Quick Introduction to Processing
Recursion October 5, Reading Read pp in the text.
Emerging Platform#5: Processing 2 B. Ramamurthy 6/13/2014B. Ramamurthy, CS6511.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 2 SORTING Lecture 05, file P2 Due January.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Programming Project 1 Truth Table Lecture 03, file P1 Due January.
Graphics Programming. In this class we will cover: Drawing lines, rectangles, and ellipses Copying an area Drawing an image.
Text David Meredith Aalborg University.
Grundaufbau import processing.core.PApplet; public class Proc_Minimal extends PApplet { public void setup(){ size(1024, 768); frameRate(60.0f);
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.
Processing Processing is a simple programming environment that was created to make it easier to develop visually oriented applications with an emphasis.
IAT 334 Java using Processing ______________________________________________________________________________________ SCHOOL OF INTERACTIVE ARTS + TECHNOLOGY.
, Fall 2006IAT 800 Lab 2: Polygons, Transformations, and Arrays.
IAT 800 Foundations of Computational Art and Design ______________________________________________________________________________________ SCHOOL OF INTERACTIVE.
IAT 800 Lecture 4. Sept 18, Fall 2006IAT 8002 Outline  Programming concepts –Methods –Classes  Talk about project 1  Reading: Read Chapters 1-4 of.
Four simple expressions in meta. Data objects Pieces of data in a computer are called objects Today, we’ll talk about four kinds of objects Numbers Pictures.
IAT 800 Lecture 8. Oct 13, Fall 2006IAT 8002 Outline  Programming concepts –BImage BFont –Creating XImage –Typography.
TOPIC 9 MODIFYING PIXELS IN A MATRIX: COPYING, CROPPING 1 Notes adapted from Introduction to Computing and Programming with Java: A Multimedia Approach.
IAT 355 Lecture 4 Computer Graphics: Rocket. May 9, 2014IAT 3552 Outline  Programming concepts –Programming Computer Graphics –Transformations –Methods.
2D Graphics: Rendering Details
1 k Jarek Rossignac,  2008 Processing  Install Processing  Learn how to edit, run, save, export, post programs  Understand.
Transforming Geometry Groundhog Day. Drawing Quads In a 300 by 200 window, draw two quads of different colors. Don’t show the grey grid.
Lecture 15: Intro to Graphics Yoni Fridman 7/25/01 7/25/01.
Programming for Artists ART 315 Dr. J. R. Parker Art/Digital Media Lab Lec 10 Fall 2010.
Processing can load images, display them on the screen, and change their size, position, opacity, and tint. You can load gif, png and jpg images in processing.
Introduction to Image processing using processing.
Graphic Basics in C ATS 315. The Graphics Window Will look something like this.
1 Georgia Tech, IIC, GVU, 2006 MAGIC Lab Rossignac Lecture 02b: Tutorial for Programming in Processing Jarek Rossignac.
B. RAMAMURTHY Simulating Motion and Implementing Animation.
Review Inheritance Overloading and overriding. example1.pde.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Words. Characters and Strings Character –A single character inside of single quotes char letter = 'A' ; char digit = '0' ; – Strings Zero or more character.
Computer Science I Recap: variables & functions. Images. Pseudo-random processing.
Processing TYWu. Where can I download? 2.0b9 Windows 32-bit.
Digital Media Lecture 5: Vector Graphics Georgia Gwinnett College School of Science and Technology Dr. Jim Rowan.
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.
Computer Science I Text input. Transformations. Yet another jigsaw. Classwork/Homework: Create new application making use of transformations.
IAT 800 Lecture 8 PImage and PFont. Oct 13, Fall 2009IAT 8002 Outline  Programming concepts –PImage –PFont.
Georgia Institute of Technology Drawing in Java – part 1 Barb Ericson Georgia Institute of Technology September 2005.
Programming in Processing Taught by Ms. Madsen Assistants: Ms. Fischer and Ms. Yen Winsor School, 2/20/08.
Task 1 and Task 2. Variables in Java Programs Variables start with lower case letter Variables are descriptive of what they store Variables are one word.
David Meredith Aalborg University
Some of Chap 17.
Logo with Curved Text.
Topic 9 Modifying Pixels in a Matrix: Copying, Cropping
Computer Graphics: Rocket, Java: Class
Emerging Platform#1: Processing 3
Chapter 14, Translate & Rotate
Polygons, Transformations, and Arrays
Barb Ericson Georgia Institute of Technology September 2005
Graphics Fundamentals
Example: Card Game Create a class called “Card”
Chapter 14 JavaFX Basics Dr. Clincy - Lecture.
Chapter 15, Images …a few points
Digital Media Dr. Jim Rowan ITEC 2110.
For Net Art Lecture 2 J Parker
Exam1 Review CSE113 B.Ramamurthy 11/29/2018 B.Ramamurthy.
Chapter 3 arrays of vertices vertex arrays display lists drawing text
More programming with "Processing"
Chapter 15, Images …a few points
IAT 265 Lecture 2: Java Loops, Arrays Processing setup, draw, mouse Shapes Transformations, Push/Pop.
Programming for Art: Images
Chap 17 Section 3.
Chapter 3 arrays of vertices vertex arrays display lists drawing text
Exam1 Review CSE113 B.Ramamurthy 4/17/2019 B.Ramamurthy.
LCC 6310 Computation as an Expressive Medium
LCC 6310 Computation as an Expressive Medium
Chapter 9 Arrays.
Presentation transcript:

IAT 265 PImage and PFont

Outline Programming concepts PImage PFont May 24, 2016 IAT 265

Loading Images Loading Images Give your project a name and save. Place the image file in: <processing dir>/sketchbook/<project name>/data/ Use this code: PImage im = loadImage(“<image filename>”); May 24, 2016 IAT 265

Displaying Images image() shows your image. image(im, 0, 0) will display your image from the last slide at the top left of the window. May 24, 2016 IAT 265

Accessing Pixels The PImage class allows you to access the RGB values of each individual pixel of the image, with the pixels[] array. You can get the width and height of the image file using the width and height fields of PImage. May 24, 2016 IAT 265

Accessing Pixels How do we know which pixel to look for in the array? 1 2 3 4 1 2 3 May 24, 2016 IAT 265

Accessing Pixels How do we know which pixel to look for in the array? 1 2 3 4 1 2 3 1 2 3 4 May 24, 2016 IAT 265

Accessing Pixels How do we know which pixel to look for in the array? 1 2 3 4 1 2 3 1 1 2 3 4 5 6 7 8 9 May 24, 2016 IAT 265

Accessing Pixels How do we know which pixel to look for in the array? 1 2 3 4 1 2 3 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 May 24, 2016 IAT 265

Accessing Pixels Array Index x + y*width 1 2 3 4 5 6 7 8 9 1 2 3 4 1 2 3 4 (4, 0) = 4 + 0*5 = 4 (3, 2) = 3 + 2*5 = 13 1 2 3 1 2 3 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 May 24, 2016 IAT 265

Accessing Pixels What would a piece of code look like that got a color from a pixel? Let’s look at some applications of this. PImage im = loadImage(“test1.jpg”); color c1 = im.pixels[3 + 2*im.width]; // gets color at (3, 2) stroke(c1); // set our line color so we can draw with this color. May 24, 2016 IAT 265

Window vs. Image The drawing window also has a pixels[] array. You must call loadPixels(); to get the image from the screen You don’t need a PImage object. loadPixels(); color c2 = pixels[3 + 2*width]; // gives us the color at (3, 2) in the window. May 24, 2016 IAT 265

Window vs. Image When would we want to use both of these? Use the Window’s pixels if you want to draw more things based on the image that’s already on the screen. Use the Image’s pixels if you want to manipulate the pixels of the image before you draw them. May 24, 2016 IAT 265

2D Arrays Java lets us make Arrays of Arrays, otherwise called 2D Arrays. These are very useful for accessing arrays of pixels like the ones we’ve been working with. int[][] bob = new int[3][4]; color[][] pixels2d = new color[200][200]; May 24, 2016 IAT 265

2D Arrays Processing doesn’t provide us with a 2D array of pixels to use, so let’s develop a class that will make manipulating pixels easier. May 24, 2016 IAT 265

2D Arrays Interestingly, 2D Arrays are just covering up a 1D array much like the pixels[] array. color[][] pixels2d = new color[20][20]; color c2 = pixels2d[3][2]; color[] pixels1d = new color[400]; color c1 = pixels1d[3 + 2*20]; Underneath, these two pieces of code do the same thing. The 2D array convention just makes it easier for us to access the array based on things like our x and y values. May 24, 2016 IAT 265

PFont PFont is the Processing class for manipulating fonts Like PImage for images Use PFont with PFont loadFont() – loads a font textFont(PFont font, int size) – sets the current font text(String str, int x, int y) – draws a string in the current font at the current location Also text(String str, float x, float y) May 24, 2016 IAT 265

Simple example // the fonts must be located in the data directory PFont eureka = loadFont("Eureka90.vlw"); PFont zig = loadFont("Ziggurat-HTF-Black-32.vlw"); textFont(eureka, 44); text("word", 10, 30); textFont(zig, 44); text("word", 10, 60); May 24, 2016 IAT 265

Use fill() to change the color of text // the fonts must be located in the data directory PFont eureka = loadFont("Eureka90.vlw"); PFont zig = loadFont("Ziggurat-HTF-Black-32.vlw"); fill( 0, 255, 0 ); textFont( eureka, 44); text( "word", 10, 30); textFont( zig, 44); fill( 255, 0, 0); text( "word", 10, 60); May 24, 2016 IAT 265

textMode sets the alignment textAlign( LEFT ); x, y is the upper left hand corner of the text textAlign( RIGHT ); x, y is the upper right hand corner of the text textAlign( CENTER ); x, y is the upper center of the text May 24, 2016 IAT 265

Producing text effects All the transform methods apply to drawing text That means you can translate, rotate, and scale text Combined with draw(), this means you can move text around the screen in real time Remember, the movement of the rocket and asteroids in our asteroids example was just translation and rotation So you can make textual machines where text moves around the screen! May 24, 2016 IAT 265

Processing example void draw( ) { image( im, mouseX-370, mouseY-210 ); color c1 = im.pixels[365 + 210 * im.width ] ; loadPixels(); c1 = pixels[ 3 + 2 * width ] ; stroke( c1 ); fill( c1 ); textAlign( LEFT ); ellipse( mouseX, mouseY, 20, 10 ); textFont( eur, 44 ); text( "Yo!", mouseX + 20, mouseY + 20 ); fill( 255, 0, 0); pushMatrix(); textAlign( RIGHT ); rotate( 0.2); textFont( zig, 44 ); text( "Yo?", mouseX, mouseY + 100 ); popMatrix(); } PImage im ; PFont eur ; PFont zig ; void setup() { size( 600, 600 ); im = loadImage( "cdshaw.96.jpg" ); for( int i = 600 ; i >= 0 ; i -= 50 ) image( im, i, i ); eur = loadFont( "Eureka90.vlw" ); zig = loadFont( "Ziggurat-HTF-Black-32.vlw" ); textFont( eur ); } May 24, 2016 IAT 265