Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
iams223
iams223's Profile
1
Posts
0
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
how can i do this? T_T
[1 Reply]
06-Dec-2011 08:31 PM
Forum:
Programming Questions
I sketch this.
but I want to change the line, when i finished first text line.
-------1--------
int leftmargin = 10;
int rightmargin = 20;
PImage bg;
//int letter_width = 25;
//int x = letter_width;
//int y = 0;
String buff = "";
boolean didntTypeYet = true;
void setup()
{
size(700,500, P3D);
textFont(loadFont("Cochin-48.vlw"), 25);
bg = loadImage("text.jpg");
}
void draw()
{
background(bg);
if((millis() % 500) < 250){ // Only fill cursor half the time
noFill();
}
else {
fill(200);
stroke(0);
}
float rPos;
// Store the cursor rectangle's position
rPos = textWidth(buff) + leftmargin;
rect(rPos+1, 9, 3, 27);
// Some instructions at first
if(didntTypeYet) {
fill(0);
text("ses hommages a Borges.", 13, 30);
}
fill(0);
pushMatrix();
translate(rPos,10+25);
char k;
for(int i = 0;i < buff.length(); i++) {
k = buff.charAt(i);
translate(-textWidth(k),0);
// rotateY(-textWidth(k)/70.0);
// rotateX(textWidth(k)/70.0);
// scale(1.1);
text(k,0,0);
}
popMatrix();
}
void keyPressed()
{
char k;
k = (char)key;
switch(k){
case 8:
if(buff.length()>0){
buff = buff.substring(1);
}
break;
case 13: // Avoid special keys
case 10:
case 65535:
case 127:
case 27:// means don't?--
break;
default:
if(textWidth(buff+k)+leftmargin < width-rightmargin){
didntTypeYet = false;
buff=k+buff;
}
break;
}
}
like this code! this can change the line. but
this is not a text. it's rect . T_T
could u help me?
sorry I am not good at processing and english too.
it 's so difficult !!!
what i want to do is just typing text like this page.!!
int max_height = 20;
int min_height = 10;
int letter_height = max_height; // Height of the letters
int letter_width = 10; // Width of the letter
int x = -letter_width; // X position of the letters
int y = 0; // Y position of the letters
boolean newletter;
int numChars = 26; // There are 26 characters in the alphabet
color[] colors = new color[numChars];
void setup()
{
size(200, 200);
noStroke();
colorMode(RGB, numChars);
background(numChars/2);
// Set a gray value for each key
for(int i=0; i<numChars; i++) {
colors[i] = color(i, i, i);
}
}
void draw()
{
if(newletter == true) {
// Draw the "letter"
int y_pos;
if (letter_height == max_height) {
y_pos = y;
rect( x, y_pos, letter_width, letter_height );
} else {
y_pos = y + min_height;
rect( x, y_pos, letter_width, letter_height );
fill(numChars/2);
rect( x, y_pos-min_height, letter_width, letter_height );
}
newletter = false;
}
}
void keyPressed()
{
// if the key is between 'A'(65) and 'z'(122)
if( key >= 'A' && key <= 'z') {
int keyIndex;
if(key <= 'Z') {
keyIndex = key-'A';
letter_height = max_height;
fill(colors[key-'A']);
} else {
keyIndex = key-'a';
letter_height = min_height;
fill(colors[key-'a']);
}
} else {
fill(0);
letter_height = 10;
}
newletter = true;
// Update the "letter" position
x = ( x + letter_width );
// Wrap horizontally
if (x > width - letter_width) {
x = 0;
y+= max_height;
}
// Wrap vertically
if( y > height - letter_height) {
y = 0; // reset y to 0
}
}
«Prev
Next »
Moderate user : iams223
Forum