User Tools

Site Tools


cs276:spc.lab6

CSci 276 Lab #6

The purpose of this lab is to play with text and fonts.

Lab Exercises

Part 1

  • Copy the sketch ArrayListFontDemo to the Processing editor. Before running it, select the menu item Tools→Create Font to create a font that matches that used in the loadFont function in setup. Or don't, and try running it (spoiler alert: it will crash).
  • Run the sketch; the words should look crammed together. Modify the line textfont(font, 16); by removing the second argument then run the sketch again. Does it look better? Determine the purpose of the 16 in the original call.
  • Change the sketch so that the words have more space and are easier to read (your choice as to the size of the font). Also, change the color of the text and the background. Your goal is readability.
  • Determine what the 3rd argument to size is for. Try running the sketch without it. Any obvious change?

Part 2

  • Create a new sketch and copy the program below into it. You'll need to create a new font for this one.
  • Run the program as is, then uncomment the two lines in draw and try again.
  • Now remove the P3D from the size function and try again. Explain why you need P3D in this sketch.
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
 
// Exercise 17-8: Display text that is centered and rotated to appear flat. Have the text scroll off into the distance.
 
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, y);
  rectMode(CENTER);
  fill(0,100);
  rect(0,0,100,100);
  //y--;
}

Demonstrate your sketches to the instructor.

cs276/spc.lab6.txt · Last modified: 2022/09/27 02:57 by scarl