Can someone help draw a robot?

i need to make a target that includes ellipses, triangles, rectangles and lines. so im trying to make a robot but im struggling on drawing the triangles and lines. i was thinking to have two triangles for ears directly above the eyes on top of the rectangle and have two lines on the bottom directly under the eyes starting at the bottom of the rectangle.

Also how do i make it disappear when a new one shows up so theres only one on at one time and so they only spawn within the yellow area and why is the yellow intruding into the white area is it because of rect mode in the target?

int xTarget;
int yTarget;
int randomTime; 
int counter;
PFont f;

void setup() {
  size (700, 800);
  background(255);
  frameRate(30);
  f = createFont("Arial",16,true);
}

void draw() {
  fill(240, 239, 94);
  strokeWeight(0);
  rect(0, 160, width, height);
  fill(0);
  strokeWeight(0);
  textFont(f);
  textSize(20);
  text("Score: 0, Lives left: 3", 260, 80);
  if(counter>randomTime) 
  {
    randomTime=int(random(60,150));
    xTarget=int(random(0,width));

    
    randomTime=int(random(60,150));
    yTarget=int(random(0,height));
    counter=0;
  }
  counter++;
  
  drawTarget();
}

void drawTarget() {
  noStroke();
  rectMode(CENTER);
  fill(0, 0, 255);
rect(xTarget - 100, yTarget, 125, 75);
fill(255, 105, 180);
  ellipse(xTarget - 135, yTarget-10, 25, 25);
   fill(0, 255, 0);
  ellipse(xTarget - 65, yTarget-10, 25, 25);
   fill(255, 0, 0);
  rect(xTarget - 100, yTarget+25, 50, 15);
  fill(0, 255, 55);
  triangle(xTarget, yTarget, xTarget-75, yTarget, xTarget-60, yTarget -60);
  strokeWeight(2);
  fill(0);
  line(xTarget, yTarget, xTarget-50, yTarget-50);
}
1 Like

You should repeat this at start of draw()

In these line use other values that are of the
yellow rectangle plus / minus the size of the robot

when i do that it stops there being more than one robot being there at a single time but the yellow rectangle changes its position (its supposed to be the bottom 4/5ths of the screen

1 Like

Before drawing it say rectMode(CORNER);

thanks, could you help with the drawing of the robot triangles and lines

1 Like

Line is connection between 2 points

Just adjust the values and draw 2
different lines.

Same for triangles

ill try it some more but thats kinda what ive been trying but idk what numbers will make it go where

1 Like

That’s first point x, y

and left (!) of this second point x,y

x leads right from the left screen border

y leads down from top screen border

Here the first point is left:::

line(xTarget-65-50, yTarget-50, 
     xTarget-65, yTarget-50);

the line is not visible on the screen

Depending on target variables

try

line(65+50, 65+150, // point 1 
     65, 65);  // point 2

Just learn it, play with it and
make yourself familiar with it.

Also check website : reference and text (!) tutorials , especially the first three text tutorials on the website

Example

  • where the mouse coordinates are shown so that you make notes where you want your points to be

int xTarget;
int yTarget;
int randomTime; 
int counter;
PFont myFont;

void setup() {
  size (700, 800);
  background(255);
  frameRate(30);
  myFont = createFont("Arial", 16, true);
}

void draw() {
  background(255);
  rectMode(CORNER); 

  fill(240, 239, 94);
  strokeWeight(0);
  rect(0, 160, width, height);
  fill(0);
  strokeWeight(0);
  textFont(myFont);
  textSize(20);
  text("Score: 0, Lives left: 3", 260, 80);
  text("mouseX "
    +mouseX+", mouseY "
    +mouseY, 260, 80+80);

  if (counter>randomTime) 
  {
    randomTime=int(random(60, 150));
    xTarget=int(random(30, width-30));
    randomTime=int(random(60, 150));
    yTarget=int(random(30, height-30));
    counter=0;
  }
  counter++;

  drawTarget();
}

void drawTarget() {
  noStroke();
  rectMode(CENTER);
  fill(0, 0, 255);
  rect(xTarget - 100, yTarget, 125, 75);
  fill(255, 105, 180);
  ellipse(xTarget - 135, yTarget-10, 25, 25);
  fill(0, 255, 0);
  ellipse(xTarget - 65, yTarget-10, 25, 25);
  fill(255, 0, 0);
  rect(xTarget - 100, yTarget+25, 50, 15);

  fill(0, 255, 55);
  triangle(xTarget, yTarget-33, 
    xTarget-75, yTarget-33, 
    xTarget-60, yTarget -60-33);

  triangle(  xTarget-75-110, yTarget-33, 
    xTarget-110, yTarget-33, 
    xTarget-60-110, yTarget -60-33);

  strokeWeight(2);
  fill(0);
  int yAdd=2; 
  stroke(255, 0, 0); //RED LINE
  int xPos = xTarget-80+4; 
  line(xPos, yTarget+yAdd, 
    xPos+24, yTarget+yAdd);
  stroke(0, 255, 0); //GREEN LINE
  xPos=xTarget-150+4; 
  line(xPos, yTarget+yAdd, 
    xPos+24, yTarget+yAdd);
}

1 Like