package processing.test.sample;

import processing.core.*; 
import processing.data.*; 
import processing.opengl.*; 

import android.view.MotionEvent; 
import android.view.KeyEvent; 
import android.graphics.Bitmap; 
import java.io.*; 
import java.util.*; 

public class Sample extends PApplet {


// The message to be displayed
String message = "How to Lie with Infographics, now an Android App!";

PFont f;
// The radius of a circle
float r = 100;

public void setup() {
 
  f = createFont("Georgia",24,true);
  textFont(f);
  // The text must be centered!
  textAlign(CENTER);
  smooth();
}

public void draw() {
  background(255);

  // Start in the center and draw the circle
  translate(width / 2, height / 2);
  noFill();
  stroke(0);
 
  // We must keep track of our position along the curve
  float arclength = 2*mouseX;

  // For every box
  for (int i = 0; i < message.length(); i++)
  {
    // Instead of a constant width, we check the width of each character.
    char currentChar = message.charAt(i);
    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 coordinate conversion
    translate(r*cos(theta), r*sin(theta));
    // Rotate the box
    rotate(theta+PI/2); // rotation is offset by 90 degrees
    // Display the character
    fill(0);
    text(currentChar,0,0);
    popMatrix();
    // Move halfway again
    arclength += w/2;
  }
}
  



  public int sketchWidth() { return 320; }
  public int sketchHeight() { return 320; }
}
