Question

In: Computer Science

Could you function key to move the arms and legs to this code? so a key...

Could you function key to move the arms and legs to this code? so a key function for each direction of the robot. left right forward and back.

void setup()

{

size(500, 250);

background(255);

draw();

}

void draw()

{

  

{

  

fill(100, 100, 97);

rect(45, 0, 50, 32); // Head

rect(45, 32, 50, 50); // Body

line(90, 20, 50, 20);// Mouth

  

rect(33, 32, 12, 42); // Left arm

rect(95, 32, 12, 42); // Right arm

  

rect(33, 72, 12, 14); // Left hand

rect(95, 72, 12, 14); // Right hand

  

rect(45, 82, 14, 40); // Left leg

rect(81, 82, 14, 50); // Right leg

  

rect(40,120,20,20); // Left foot

rect(80,120,20,20); // Right foot

  

fill(245, 17, 33);

ellipse(55, 10, 13, 12); // Left eye

ellipse(85, 10, 13, 12); // Right eye

  

}

}

Solutions

Expert Solution

Answer : Before writing the function we will see what would be our approach for this method:

Approach : Count number of Forward movements (F), Backward movements (B), left movements (L) and right movements (R) as countForward, countBackward, countLeft and countRight respectively. Final x-coordinate will be (countRight – countLeft) and y-coordinate will be (countForward – countBackward).

Below is the function for movement of Robot .

#include <bits/stdc++.h>
using namespace std;
  
// function to find final position of
// robot after the complete movement
void finalPosition(string move)
{
int l = move.size();
int countForward = 0, countBackward = 0;
int countLeft = 0, countRight = 0;
  
// traverse the instruction string 'move'
for (int i = 0; i < l; i++) {
  
// for each movement increment its
// respective counter
if (move[i] == 'F')
countForward++;
else if (move[i] == 'B')
countBackward++;
else if (move[i] == 'L')
countLeft++;
else if (move[i] == 'R')
countRight++;
}
  
// required final position of robot
cout << "Final Position: ("
<< (countRight - countLeft)
<< ", " << (countForward - countBackward)
<< ")" << endl;
}
  
// Driver program to test above
int main()
{
string move = "FBBLLRFFFBFBRFBBFFLLBRRRR";
finalPosition(move);
return 0;
}

Note: Provide your Feedback as thumbs up and vice-versa. For any query ask in comment section. Always happy to help you.


Related Solutions

. Be able to identify the following muscles of arms and legs, Also know their origin,...
. Be able to identify the following muscles of arms and legs, Also know their origin, insertion and movement caused by them A. Deltoid, Biceps brachii, Brachialis and other major muscles of arm. B. Sartorius, Rectus femoris, Vastus medialis and Vastus lateralis muscle, Gluteus maximus
What disease present with pinkish rash on hands and feet them arms and legs and fever...
What disease present with pinkish rash on hands and feet them arms and legs and fever in children
Emmy the trapeze artist flies through the air with her arms and legs stretched out, tumbling...
Emmy the trapeze artist flies through the air with her arms and legs stretched out, tumbling head over heels. As she rotates, she pulls her arms and legs close to her chest, as shown in the illustration. As Emmy pulls her arms and legs in, how does her rotational inertia change?it increasesit decreasesit remains constant As Emmy pulls her arms and legs in, how does her angular momentum change? it increases it decreases it remains constant As Emmy pulls her arms and legs in, how does...
The robot in Futurama, Bender, has insured several of his body parts. His arms, legs, and...
The robot in Futurama, Bender, has insured several of his body parts. His arms, legs, and head are insured. His policy costs a total of $1000 a year, and pays out $10000 if he loses his legs, $25000 is he loses his head, and $50000 if he loses his arms. (a) List the sample space for the outcomes of Bender’s damages. Note that it is possible he loses both his legs and arms simultaneously, and so on. Sadly, the policy...
30. The axial skeleton includes ________. A) skull, vertebral column, and pelvis B) arms, legs, hands,...
30. The axial skeleton includes ________. A) skull, vertebral column, and pelvis B) arms, legs, hands, and feet C) skull, vertebral column, and rib cage D) skull, scapula and vertebral column 34) A dendritic or Langerhans cell is a specialized ________ that engulfs cells or waste products. A) squamous epithelial cell          B) phagocytic cell          C) nerve cell            D) melanocyte 40) Elastic cartilage is found in the _______________. A) ears, nose and glottis            B) ears, nose, and epiglottis          C) ears and glottis           D) ears and epiglottis 42)...
Could you modify my code so it meets the following requirement? (Python Flask) I want the...
Could you modify my code so it meets the following requirement? (Python Flask) I want the user to register for account using email and password, then store that data into a text file. Then I want the data to be read when logging in allowing the user to go to home page. -------------Code-------------------- routes.py from flask import Flask, render_template, redirect, url_for, request, session import json, re app = Flask(__name__) '''@app.before_request def before_request(): if 'visited' not in session: return render_template("login.html") else:...
What industries do you think could successfully move to a peer production model? Which could not?...
What industries do you think could successfully move to a peer production model? Which could not? Why? Is the key factor the nature of the industry, the nature of the technology in use, social factors, or something else?
Thank you in advance, i'm not so good with this subject so could you include the...
Thank you in advance, i'm not so good with this subject so could you include the steps you did please 1. The gross weekly sales at a certain super market are a Gaussian random with mean $2200 and standard deviation $230. Assume that the sales from week to week are independent. (a) Find the probability that the gross sales over the next two weeks exceed $5000. (b) Find the probability that the gross weekly sales exceed $2000 in at least...
Complete this return statement so that it could be used in the function body offind_percentageto fulfill...
Complete this return statement so that it could be used in the function body offind_percentageto fulfill the requirements for the last step's program. Fill in the Blanks — Fill in the blanks return ________ /___________
Identify the skills of the leader that are key in leading a team to move a...
Identify the skills of the leader that are key in leading a team to move a company toward a social entrepreneurial model. Investigate Hot Bread Kitchen Find Hot Bread Kitchen on the Internet (http://hotbreadkitchen.org/) What is their mission and vision? Who leads Hot Bread Kitchen and what was the motivation to start the company? What impact does Hot Bread Kitchen hope to have on stakeholders? Analyze their leadership style and qualities of Jessamyn W. Rodriguez, Founder and Chief Executive Officer...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT