drawing letters
in
Processing with Other Languages
•
1 years ago
I am trying to draw letters in processing right now i have H and C but i cant do a V with slope i really need help.
Here is my code.
int x;
float y;
float slope;
float b;
int cSize;
int change;
boolean bInit;
int hStroke;
int cStroke;
int angle;
int radius;
int xCenter;
int yCenter;
void setup() {
size(800, 600);
background(255);
bInit = true;
cSize = 30;
hStroke = 1;
cStroke = 1;
change = 3;
angle=30;
radius=75;
xCenter=width/2;
yCenter=height/2;
}
void draw() {
switch (hStroke) {
case 1:
draw1stStrokeH();
break;
case 2:
draw2ndStrokeH();
break;
case 3:
draw3rdStrokeH();
break;
}
switch (cStroke) {
case 1:
draw1stStrokeC();
break;
}
}
void draw1stStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
hStroke++;
bInit = true;
}
}
}
void draw2ndStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 250;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
hStroke++;
bInit = true;
}
}
}
void draw3rdStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 185;
}
else { // draw
ellipse(x, y, cSize, cSize);
x = x + change;
y = 185;
if (x > 250) {
hStroke++;
bInit = true;
}
}
}
void draw1stStrokeC() {
if (bInit) { // initialize
bInit = false;
}
else { // draw
float x; // local variable
float y;
x=xCenter+radius * cos(radians(angle));
y=yCenter+radius * sin(radians(angle));
ellipse(x, y, cSize, cSize);
angle = angle + change;
if (angle>310)
cStroke++; {
bInit = true;
}
}
}
i was taught how to do an letter N but since the Y axis is inverted i couldn't calculate the slope for V.
this is the code for a Letter N
// initial N
int x;
float y;
float slope;
float b;
int cSize;
int change;
boolean bInit;
int nStroke;
void setup() {
size(800, 600);
background(255);
bInit = true;
cSize = 30;
nStroke = 1;
change = 3;
}
void draw() {
switch (nStroke) {
case 1:
draw1stStrokeN();
break;
case 2:
draw2ndStrokeN();
break;
case 3:
draw3rdStrokeN();
break;
}
}
void draw1stStrokeN() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
nStroke++;
bInit = true;
}
}
}
void draw2ndStrokeN() {
if (bInit) { // initialize
bInit = false;
x = 250;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
nStroke++;
bInit = true;
}
}
}
void draw3rdStrokeN() {
if (bInit) { // initialize
bInit = false;
slope = 200.0 / 150.0; // do not use 1.33
b = -100.0 / 3.0; // do not use -33.3
x = 100;
y = slope * x + b;
}
else { // draw
ellipse(x, y, cSize, cSize);
x = x + change;
y = slope * x + b;
if (x > 250) {
nStroke++;
bInit = true;
}
}
}
Here is my code.
int x;
float y;
float slope;
float b;
int cSize;
int change;
boolean bInit;
int hStroke;
int cStroke;
int angle;
int radius;
int xCenter;
int yCenter;
void setup() {
size(800, 600);
background(255);
bInit = true;
cSize = 30;
hStroke = 1;
cStroke = 1;
change = 3;
angle=30;
radius=75;
xCenter=width/2;
yCenter=height/2;
}
void draw() {
switch (hStroke) {
case 1:
draw1stStrokeH();
break;
case 2:
draw2ndStrokeH();
break;
case 3:
draw3rdStrokeH();
break;
}
switch (cStroke) {
case 1:
draw1stStrokeC();
break;
}
}
void draw1stStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
hStroke++;
bInit = true;
}
}
}
void draw2ndStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 250;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
hStroke++;
bInit = true;
}
}
}
void draw3rdStrokeH() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 185;
}
else { // draw
ellipse(x, y, cSize, cSize);
x = x + change;
y = 185;
if (x > 250) {
hStroke++;
bInit = true;
}
}
}
void draw1stStrokeC() {
if (bInit) { // initialize
bInit = false;
}
else { // draw
float x; // local variable
float y;
x=xCenter+radius * cos(radians(angle));
y=yCenter+radius * sin(radians(angle));
ellipse(x, y, cSize, cSize);
angle = angle + change;
if (angle>310)
cStroke++; {
bInit = true;
}
}
}
i was taught how to do an letter N but since the Y axis is inverted i couldn't calculate the slope for V.
this is the code for a Letter N
// initial N
int x;
float y;
float slope;
float b;
int cSize;
int change;
boolean bInit;
int nStroke;
void setup() {
size(800, 600);
background(255);
bInit = true;
cSize = 30;
nStroke = 1;
change = 3;
}
void draw() {
switch (nStroke) {
case 1:
draw1stStrokeN();
break;
case 2:
draw2ndStrokeN();
break;
case 3:
draw3rdStrokeN();
break;
}
}
void draw1stStrokeN() {
if (bInit) { // initialize
bInit = false;
x = 100;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
nStroke++;
bInit = true;
}
}
}
void draw2ndStrokeN() {
if (bInit) { // initialize
bInit = false;
x = 250;
y = 100;
}
else { // draw
ellipse(x, y, cSize, cSize);
y = y + change;
if (y > 300) {
nStroke++;
bInit = true;
}
}
}
void draw3rdStrokeN() {
if (bInit) { // initialize
bInit = false;
slope = 200.0 / 150.0; // do not use 1.33
b = -100.0 / 3.0; // do not use -33.3
x = 100;
y = slope * x + b;
}
else { // draw
ellipse(x, y, cSize, cSize);
x = x + change;
y = slope * x + b;
if (x > 250) {
nStroke++;
bInit = true;
}
}
}
1