PFont f;
void setup() {
size(480, 270);
// Step 3: Create Font
f = createFont("Arial", 16);
}
void draw() {
background(255);
textFont(f, 16); // Step 4: Specify font to be used
fill(0); // Step 5: Specify font color
// Step 6: Display Text
text("Wow..LIT ... Strings ...", 10, height/2);
}
String message = "a bunch of text here.";
char c = message.charAt(3);
println(c);
PFont f;
void setup() {
size(480, 270);
f = createFont("Arial", 16);
}
void draw() {
background(255);
stroke(175);
line(width/2, 0, width/2, height);
textFont(f);
fill(0);
// textAlign() sets the alignment for displaying text. It takes one argument: CENTER, LEFT, or RIGHT.
textAlign(CENTER);
text("This text is centered, duh.", width/2, 160);
textAlign (LEFT) ;
text("This text is left aligned, duh.", width/2, 200);
textAlign(RIGHT);
text("This text is right aligned, oh.", width/2, 240);
}
/*
String message = "a bunch of text here." ;
for (int i = 0; i < ____________ ); i++ ) {
char c = _______________ ;
println(c);
}
*/
// An array of news headlines
String[] headlines = {
"Pierre's 6th Period class donates $100. New record.",
"New study shows computer programming raises ability to talk with girls.",
};
PFont f; // Global font variable
float x; // Horizontal location
int index = 0;
void setup() {
size(480, 270);
f = createFont( "Arial", 16);
// Initialize headline offscreen
x = width;
}
void draw() {
background(255);
fill(0);
// Display headline at x location
textFont(f, 16);
textAlign (LEFT);
// A specific String from the array is displayed according to the value of the "index" variable.
text(headlines[index], x, height-20);
// Decrement x
x = x - 3;
// If x is less than the negative width, then it is off the screen
// textWidth() is used to calculate the width of the current String.
float w = textWidth(headlines[index]);
if (x < -w) {
x = width;
// index is incremented when the current String has left the screen in order to display a new String.
index = (index + 1) % headlines.length;
}
}
String info = "A long long time ago\nIn a galaxy far far away";
PFont f;
float y = 0;
void setup() {
size(400, 200, P3D);
f = createFont( "Arial", 12);
}
void draw() {
background(255);
fill(0);
translate(width/2, height/2);
rotateX(PI/4);
textFont(f);
textAlign(CENTER);
text(info, 0, 0);
rectMode(CENTER);
fill(0,100);
rect(0,0,100,100);
}
import processing.video.*;
// Size of each cell in the grid, ratio of window size to video size
int videoScale = 10;
// Number of columns and rows in our system
int cols, rows;
// Variable to hold onto capture object
Capture video;
// The source text used in the mosaic pattern. A longer String might produce more interesting results.
String chars = "menforothers" ;
PFont f;
void setup() {
size(640, 480);
// Set up columns and rows
cols = width / videoScale;
rows = height / videoScale;
video = new Capture(this, cols, rows);
video.start();
// Create the font
// Using a fixed-width font. In most fonts, individual characters have different widths.
// In a fixed-width font, all characters have the same width.
// This is useful here since we intend to display the letters one at a time spaced out evenly.
// See Section 17.7 for how to display text character by character with a nonfixed width font.
f = createFont("Courier", 16);
}
void captureEvent(Capture video) {
video.read();
}
void draw() {
background(0);
video.loadPixels();
// Use a variable to count through chars in String
int charcount = 0;
// Begin loop for rows
for (int j = 0; j < rows; j++ ) {
// Begin loop for columns
for (int i = 0; i < cols; i++ ) {
// Where are we, pixel-wise?
int x = i * videoScale;
int y = j * videoScale;
// Looking up the appropriate color in the pixel array
color c = video.pixels[i + j*video.width];
// Displaying an individual character from the String instead of a rectangle
textFont(f);
fill(c);
// One character from the source text is displayed colored accordingly to the pixel location.
// A counter variable charcount is used to walk through the source String one character at a time.
text(chars.charAt(charcount), x, y);
// Go on to the next character
charcount = (charcount + 1) % chars.length();
}
}
}
PFont f;
String message = "you are getting very sleepy";
float theta;
void setup() {
size(480, 270);
f = createFont("Arial", 20);
}
void draw() {
background(255);
fill(0);
textFont(f); // Set the font
textAlign(CENTER);
pushMatrix();
translate(width/2, height/2); // Translate to the center
rotate(theta); // Rotate by theta
// The text is center aligned and displayed at (0,0) after translating and rotating.
// See Chapter 14 or a review of translation and rotation.
text(message, 0, 0);
popMatrix();
// Increase rotation
theta += 0.02;
}
// The radius of a circle
float r = 100;
// The width and height of the boxes
float w = 40;
float h = 40;
void setup() {
size(480, 270);
}
void draw() {
background(255);
// Start in the center and draw the circle
translate(width/2, height/2);
noFill();
stroke(0);
// Our curve is a circle with radius r in the center of the window.
ellipse(0, 0, r*2, r*2);
// 10 boxes along the curve
int totalBoxes = 10;
// We must keep track of our position along the curve
float arclength = 0;
// For every box
for (int i = 0; i < totalBoxes; i ++ ) {
// Each box is centered so we move half the width
arclength += w/2;
// Angle in radians is the arclength divided by the radius
float theta = arclength / r;
pushMatrix();
// Polar to cartesian coordinate conversion
translate(r*cos(theta), r*sin(theta));
// Rotate the box
rotate(theta);
// Display the box
fill(0, 100);
rectMode(CENTER);
rect(0, 0, w, h);
popMatrix();
// Move halfway again
arclength += w/2;
}
// The message to be displayed
String message = "smile like you mean it";
PFont f;
// The radius of a circle
float r = 100;
void setup() {
size(480, 270);
f = createFont("Georgia", 40);
textFont(f);
// The text must be centered!
textAlign(CENTER);
}
void draw() {
background(255);
// Start in the center and draw the circle
translate(width/2, height/2);
noFill();
stroke(0);
ellipse(0, 0, r*2, r*2);
// We must keep track of our position along the curve
float arclength = 0;
// For every box
for (int i = 0; i < message.length (); i ++ ) {
// The character and its width
char currentChar = message.charAt(i);
// Instead of a constant width, we check the width of each character.
float w = textWidth(currentChar);
// Each box is centered so we move half the width
arclength += w/2;
// Angle in radians is the arclength divided by the radius
// Starting on the left side of the circle by adding PI
float theta = PI + arclength / r;
pushMatrix();
// Polar to Cartesian conversion allows us to find the point along the curve. See Chapter 13 for a review of this concept.
translate(r*cos(theta), r*sin(theta));
// Rotate the box (rotation is offset by 90 degrees)
rotate(theta + PI/2);
// Display the character
fill(0);
text(currentChar, 0, 0);
popMatrix();
// Move halfway again
arclength += w/2;
}