# Developing a coding to move on a robot

Hello Processing community. I am learning Processing by myself and I found some interesting exercises to develop coding, for a robot in this case. I have created the code. However, I am still do not know how I can transform this code from mouse functions into commands such as command key or use alt shift command plus or commands with letters such as S, A, W, J, H, to substitute mouse functions.

loat xVal = 50;
float yVal = 1100;
int myBodyHeight = 1000;
int myBodyWidth = 500;
int myNeckHeight = 200;
// Our text included this without using it…
float easingVal = 0.1;

void setup() {
size(1200,1200);
ellipseMode(RADIUS); // draw ellipse from top
}

void draw() {
strokeWeight(90);

background(0, 100, 200); // Blue

translate(mouseX, yVal); // Move all to myNewX

// Toggle the scale of everything
if (mousePressed) {
scale(0.6);
} else {
scale(0.4);
}

// Body
noStroke();
fill(255, 204, 0); // Orange
ellipse(0, -99, 99,99); // The leg
fill(0); // Black
// Calculate the rect for the body relative to the 0,0 center
rect(-myBodyWidth/2, -myBodyHeight, myBodyWidth, myBodyHeight-99);

// Neck
// Set the y location of the neck relative to the size of the
// other components
stroke(255); // White
line(30, -myBodyHeight, 10, myNeckY);

// Hair
pushMatrix(); // Isolate translation and rotation
// translate from the top of the head
translate(44, myNeckY);
// set myAngle to 1/90th of half way around
float myAngle = -PI/444.0;
for (int i = 0; i <= 444; i++) {
// do these statement 99 times, rotating a bit each time
line(444, 0, 0, 0);
rotate(myAngle);
}
popMatrix(); // end isolation of translate and rotate

noStroke();
fill(0); // Red
// White eyeball
fill(255); // White
int eyeSize = 200;
ellipse(12, myNeckY-12, eyeSize, eyeSize);
// Green Iris
fill(0, 200, 200); // Green
ellipse(24, myNeckY-9, eyeSize0.66,eyeSize0.66);
// Black pupil
fill(0); // Black
ellipse(20, myNeckY-2, eyeSize0.33,eyeSize0.33);

I want to ask you a big favor. Could you please tell me how to turn this code from mouse function into commandkeys? Do I have to change floats into bolans? I want to be able to build the same robot, but with command keys functions.

Thank you so much.

Sincerely
Steve

Also, please try to format your code. You can edit your post to format your code using the `</>` button.

here i try to help even i must start also to put down your code posting, pls

``````// reduce your code down to the minimum
// just to show what is the question.

``````

like

``````void setup() {
size(300, 300);
rectMode(CENTER);
}

void draw() {
background(0, 100, 200); // Blue
translate(width/2, height/2);

// Toggle the scale of everything
if (mousePressed) {
scale(0.6);
} else {
scale(0.4);
}

fill(255, 204, 0); // Orange
rect(0, 0, 100, 100);
}

``````

so that is you current operation concept?

mouse click ( keep pressed ) for zoom factor 1.5

and now you would like to use keyboard too?
try this:

``````void setup() {
size(300, 300);
rectMode(CENTER);
}

void draw() {
background(0, 100, 200); // Blue
translate(width/2, height/2);

// Toggle the scale of everything
if (mousePressed) {
scale(0.6);
} else {
scale(0.4);
}

fill(255, 204, 0); // Orange
rect(0, 0, 100, 100);
}

// to make a real zoom by mouse wheel and keyboard [page up down] add:

float Zmag = 1.0, Zoomf = 5.0;
//_________________________________________________________________ mouseWheel ZOOM
void mouseWheel(MouseEvent event) {
Zmag += event.getCount()/Zoomf;
println("mousewheel: "+Zmag);
}

void keyPressed(){
if ( keyCode == 33 )   {Zmag += 1/Zoomf ;}      // [page up]
if ( keyCode == 34 )   {Zmag -= 1/Zoomf ;}      // [page down]
println("keypressed: key: "+key+" keyCode: "+keyCode+" zoom: "+Zmag);
}

void setup_zoom_info(){
println(" operation: ");
println(" for zoom use keyboard: [Page Up] or [Page Down] ");
println(" or mouse click for toggle ");
println(" or mouse wheel ");
}

``````

Here:

I add a keyPressed and the Xpos var

void keyPressed() {
if (key == CODED) {
if (keyCode == LEFT) {
Xpos=Xpos-7;
} else if (keyCode == RIGHT) {
Xpos=Xpos+7;
}
}
}

``````
float xVal = 50;
float yVal = 1100;
int myBodyHeight = 1000;
int myBodyWidth = 500;
int myNeckHeight = 200;
// Our text included this without using it…
float easingVal = 0.1;

int Xpos=20;

void setup() {
size(1200, 1200);
ellipseMode(RADIUS); // draw ellipse from top
}

void draw() {
strokeWeight(90);

background(0, 100, 200); // Blue

translate(Xpos, yVal); // Move all to myNewX

// Toggle the scale of everything
if (mousePressed) {
scale(0.6);
} else {
scale(0.4);
}

// Body
noStroke();
fill(255, 204, 0); // Orange
ellipse(0, -99, 99, 99); // The leg
fill(0); // Black
// Calculate the rect for the body relative to the 0,0 center
rect(-myBodyWidth/2, -myBodyHeight, myBodyWidth, myBodyHeight-99);

// Neck
// Set the y location of the neck relative to the size of the
// other components
stroke(255); // White
line(30, -myBodyHeight, 10, myNeckY);

// Hair
pushMatrix(); // Isolate translation and rotation
// translate from the top of the head
translate(44, myNeckY);
// set myAngle to 1/90th of half way around
float myAngle = -PI/444.0;
for (int i = 0; i <= 444; i++) {
// do these statement 99 times, rotating a bit each time
line(444, 0, 0, 0);
rotate(myAngle);
}
popMatrix(); // end isolation of translate and rotate

noStroke();
fill(0); // Red
// White eyeball
fill(255); // White
int eyeSize = 200;
ellipse(12, myNeckY-12, eyeSize, eyeSize);
// Green Iris
fill(0, 200, 200); // Green
ellipse(24, myNeckY-9, 66, 66);
// Black pupil
fill(0); // Black
ellipse(20, myNeckY-2, 33, 33);
}

void keyPressed() {

if (key == CODED) {
if (keyCode == LEFT) {
Xpos=Xpos-7;
} else if (keyCode == RIGHT) {
Xpos=Xpos+7;
}
}
}
``````