We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Drawing letters (Read 389 times)
Drawing letters
Aug 28th, 2006, 11:28am
 
Hi everybody,
a simple question,
how to make this program to draw the letter A with only 1 pressed at 'a' key ?

// var
byte fontSize;

byte v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y;

float l1x, l1y, l2x, l2y;

// var
//Structure
void setup(){

size(800,600);

}
//Structure

//Functions
void draw(){

noLoop();
beginShape(LINE_STRIP);
vertex(v1x, v1y);
vertex(v2x, v2y);
vertex(v3x, v3y);
vertex(v4x, v4y);
scale(fontSize);
line(l1x, l1y, l2x, l2y);
endShape();
redraw();

}

void keyPressed(){

if (key=='a'){

noLoop();
v1x=10;
v1y=15;
v2x=15;
v2y=0;
v3x=15;
v3y=0;
v4x=20;
v4y=15;
fontSize = 3;
line(12.5, 7.5, 17.5, 7.5);
redraw();

}

}
//Functions
Re: Drawing letters
Reply #1 - Aug 30th, 2006, 7:39am
 
hmmm ... is the keyPressed() not working ?
is anyone alive Wink ?

When i put the void keyPressed (){} instead of if(keyPressed==true) returns a not expected void .
and I want 1 key pressed = 1 letter.


<code>

void setup(){

size(800,600);
smooth();
}

float fontSize=1.5;

byte v1x, v1y, v2x, v2y, v3x, v3y, v4x, v4y;

float l1x, l1y, l2x, l2y;

int e1x, e1y, e2x, e2y;

int tx = 10;int ty=10;

void draw(){   keyPressed();
LetterA();
                       keyPressed();            
LetterO();

}
    int LetterA(){

if(keyPressed==true)
 if (key == 'a'){

translate(tx,ty);
scale(fontSize);

line(v1x, v1y, v2x, v2y);

line(v3x, v3y, v4x, v4y);

line(l1x, l1y, l2x, l2y);


scale(fontSize);
translate(tx,ty);

v1x=10;v1y=15;
v2x=15;v2y=0;
v3x=15;v3y=0;
v4x=20;v4y=15;

l1x = 12.5;l1y = 7.5;
l2x = 17.5;l2y = 7.5;

tx+=35; ty+=0;

if (tx>600){
tx=0;
ty+=30;
}
redraw();
}

return 0;
}

int LetterO(){

if(keyPressed==true)
 if (key == 'o'){

translate(tx,ty);

scale(fontSize);

ellipse(e1x, e1y, e2x, e2y);

scale(fontSize);

translate(tx,ty);

e1x=10; e1y=8; e2x=10;
e2y=10;

tx+=35;ty+=0;

if (tx>600){  
tx=0; ty+=30;
}

redraw();
}

return 0;
}

</code>
Page Index Toggle Pages: 1