# Can someone help draw a robot?

**URL:** <https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461>\
**Category:** Beginners\
**Created:** [August 23, 2022, 8:35am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461 "2022-08-23T08:35:41Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Frost](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Frost](https://discourse.processing.org/u/Frost)\
**Post date:** [August 23, 2022, 8:35am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/1 "2022-08-23T08:35:41Z")

</div>

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?

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 8:50am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/2 "2022-08-23T08:50:21Z")

</div>

> [@Frost](#):
>
> `background(255);`

You should repeat this at start of draw()

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 8:52am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/3 "2022-08-23T08:52:05Z")

</div>

> [@Frost](#):
>
> `xTarget=int(random(0,width));`

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

---

<div class="post-metadata">

**Author:** ![Frost](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Frost](https://discourse.processing.org/u/Frost)\
**Post date:** [August 23, 2022, 9:04am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/4 "2022-08-23T09:04:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 9:11am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/5 "2022-08-23T09:11:14Z")

</div>

> [@Frost](#):
>
> the yellow rectangle changes its position

Before drawing it say rectMode(CORNER);

---

<div class="post-metadata">

**Author:** ![Frost](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Frost](https://discourse.processing.org/u/Frost)\
**Post date:** [August 23, 2022, 9:16am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/6 "2022-08-23T09:16:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 9:21am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/7 "2022-08-23T09:21:44Z")

</div>

> [@Frost](#):
>
> `line(xTarget-65, yTarget-50, xTarget-65-50, yTarget-50);`

Line is connection between 2 points

Just adjust the values and draw 2  
different lines.

Same for triangles

---

<div class="post-metadata">

**Author:** ![Frost](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Frost](https://discourse.processing.org/u/Frost)\
**Post date:** [August 23, 2022, 9:24am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/8 "2022-08-23T09:24:27Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 9:33am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/9 "2022-08-23T09:33:10Z")

</div>

> [@Frost](#):
>
> line(xTarget-65, yTarget-50, xTarget-65-50, yTarget-50);

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:::

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

```

---

<div class="post-metadata">

**Author:** ![Frost](https://avatars.discourse-cdn.com/v4/letter/f/90db22/32.png) [@Frost](https://discourse.processing.org/u/Frost)\
**Post date:** [August 23, 2022, 9:37am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/11 "2022-08-23T09:37:38Z")

</div>

the line is not visible on the screen

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 9:50am UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/12 "2022-08-23T09:50:41Z")

</div>

> [@Chrisir](#):
>
> ```auto
> line(xTarget-65-50, yTarget-50, 
> xTarget-65, yTarget-50);
> 
> ```

Depending on target variables

try

```auto
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

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [August 23, 2022, 12:39pm UTC](https://discourse.processing.org/t/can-someone-help-draw-a-robot/38461/13 "2022-08-23T12:39:40Z")

</div>

**Example**

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

```auto

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);
}

```
