Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
plodsmeade
plodsmeade's Profile
3
Posts
7
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
textAlign(RIGHT) problem with PDF export at small pt sizes
[2 Replies]
12-May-2013 08:04 AM
Forum:
Core Library Questions
Hi all
The code below writes text from a file to columns, backwards from the bottom right of the screen, and outputs to PDF.
I'd like to work with quite small pt sizes, but anything below 5pt doesn't justify right correctly - this is what 2pt looks like:
At least it's being consistent, but I can't tell what the problem is (number of spaces for instance - although it's a monotype font) or how to fix it.
Incidentally, although it's hard to tell because of the small pt size, I don't think processing has the same issue when it just renders to the window.
I suppose I could just use larger pt sizes and then scale the PDF down, but I've annoyed myself with the problem now.
Any help much appreciated
P
import processing.pdf.*;
String[] textData;
float pointSize = 2;
float leading = 3;
float xBorder;
float yBorder;
float x;
float y;
int widthMax;
PFont f;
int grey = 0;
void setup(){
size(400, 400, PDF, "test.pdf");
println("Width and height are " + width);
f = createFont("c:/windows/fonts/cour.ttf", pointSize, true);
textData = loadStrings("text.txt"); // populate array
println("There are " + textData.length + " lines");
}
void draw(){
background(255);
textAlign(RIGHT);
textFont(f, pointSize);
fill(grey,grey,grey);
xBorder = 10;
yBorder = 20;
x = width - xBorder;
y = height - yBorder;
for(int i = 0; i < textData.length; i++){
widthMax = max(widthMax, int(textWidth(textData[i])));
text(textData[i], x, y);
y = y - leading;
if(y <= yBorder){
x = x - widthMax - xBorder;
y = height - yBorder;
}
}
noLoop();
println("The maximum width is " + widthMax);
println("Finished.");
exit();
}
Draw text within a circle
[5 Replies]
01-May-2013 01:29 AM
Forum:
Programming Questions
Hi all
I'm trying to achieve three things:
1. To draw with random rotation single characters from a text file inside the area of a circle, until they are all used once.
2. To draw the contents of the text file, in order, within columns which fit inside the same circle area, so they are readable.
3. To draw the contents of the text file, in order, as a spiral within the same circle area, so it's readable.
All of these are to be output to separate Pdfs.
I've managed most of the first part in the attached code, adapting an
example by kobby
, but I'm unable to work out the rotation with this method.
Hopefully when this is done I can adapt it to achieve the other parts.
I'm guessing I have to get everything inside draw(), but I don't know how to do this and stop it when it reaches the last character.
best
P
PFont f = createFont( "Courier", 10, true);
float a = 200;
float b = 200;
float r;
float x;
float y;
float t;
void setup() {
size(400, 400);
textFont(f);
background(50,0,255);
String lines[] = loadStrings("list.txt");
println("there are " + lines.length + " lines");
for (int e = 0; e < lines.length; e++) {
String[] words = split(lines[e], ' ');
for(int i = 0; i< words.length; i++){
for(int j = 0; j<words[i].length(); j++){
char letter = words[i].charAt(j);
println(letter);
t = random(2*PI);
r = random(100);
x = a + r*(cos(t));
y = b + r*(sin(t));
text(letter, x, y);
}
}
}
}
void draw() {
}
controlling line drawing from a text file
[10 Replies]
09-Mar-2013 10:13 AM
Forum:
Programming Questions
Hello all
I want to draw lines based on coordinates from a text file formatted like so:
[0] x1,y1
[1] x2,y2
[2] x3,y3
..etc..
..which I have managed to get into 2 PVector classes, via tips on
iainmaxwell
's Supermanoeuvre blog.
I'd like to draw one line after the other when the user hits the RIGHT key.
At the moment, the program draws the first line, then all of the others together after RIGHT is hit only once.
Where am I going wrong?
I am sure there is a better way to draw the line from the data as well.
best
P
int grey = 180;
int x = 0;
ArrayList pointList = new ArrayList();
void setup(){
size(400,400);
background(255);
stroke(grey,grey,grey);
importTextFile();
}
void draw(){
PVector v1 = (PVector) pointList.get(x);
PVector v2 = (PVector) pointList.get(x+1);
line(v1.x,v1.y,v2.x,v2.y);
if(keyCode == RIGHT){
x = x + 2;
}
}
void importTextFile(){
String[] strLines = loadStrings("points.txt");
for(int i = 0; i < strLines.length; ++i){
String[] arrTokens = split(strLines[i], ',');
float xx = float(arrTokens[0]);
float yy = float(arrTokens[1]);
pointList.add(new PVector(xx,yy));
}
}
«Prev
Next »
Moderate user : plodsmeade
Forum