# Hi I need help with this question (triangle at mouse position)

**URL:** <https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593>\
**Category:** Beginners\
**Tags:** homework\
**Created:** [April 4, 2023, 4:45am UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593 "2023-04-04T04:45:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Computerscience](https://avatars.discourse-cdn.com/v4/letter/c/3da27b/32.png) [@Computerscience](https://discourse.processing.org/u/Computerscience)\
**Post date:** [April 4, 2023, 4:45am UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593/1 "2023-04-04T04:45:26Z")

</div>

Write a program to draw a triangle() with its center at the mouse pointer. The triangle should not change size or rotate as it moves. Give each triangle a different fill() colour. Try using a different mouse cursor.

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [April 4, 2023, 6:25am UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593/2 "2023-04-04T06:25:10Z")

</div>

Hi @Computerscience,

what exactly is your problem on creating a solution for it ?

Here are some resources to look into …

> **[triangle() / Reference](https://processing.org/reference/triangle_.html)**
>
> A triangle is a plane created by connecting three points. The first two arguments specify the first point, the middle two arguments specify the second point, and the last two arguments specify the thi…

> **[fill() / Reference](https://processing.org/reference/fill_.html)**
>
> Sets the color used to fill shapes. For example, if you run fill(204, 102, 0), all subsequent shapes will be filled with orange. This color is either specified in terms of the RGB or HSB color …

> **[Reference](https://processing.org/reference/)**
>
> Find further documentation of the Processing language

> **[cursor() / Reference](https://processing.org/reference/cursor_.html)**
>
> Sets the cursor to a predefined symbol or an image, or makes it visible if already hidden. If you are trying to set an image as the cursor, the recommended size is 16x16 or 32x32 pixels. The values fo…

Hope that helps you finding a solution…

Cheers  
— mnse

---

<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:** [April 4, 2023, 7:59am UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593/3 "2023-04-04T07:59:20Z")

</div>

You need a sketch with setup and draw

You can say if (mousePressed) triangle (…

Use mouseX and mouseY to draw triangle

Show your own code and ask a specific question

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [April 4, 2023, 10:50am UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593/4 "2023-04-04T10:50:03Z")

</div>

Hello @Computerscience,

All the resources (tutorials, examples, references, etc.) you need are here:

> **[Welcome to Processing!](https://processing.org/)**
>
> Processing is a flexible software sketchbook and a language for learning how to code. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology…

Once you understand the basics build on that.

Look these up in the references once you have explored the basics:

- createShape()

Reference:

> **[Triangle](https://en.wikipedia.org/wiki/Triangle)**
>
> A triangle is a polygon with three edges and three vertices. It is one of the basic shapes in geometry. A triangle with vertices A, B, and C is denoted 
>   
>     
>       
> △
> A
> B
> C
>       
>     
> {\\displaystyle \\triangle ABC}
>   
> .
> In Euclidean geometry, any three points, when non-collinear, determine a unique triangle and simultaneously, a unique plane (i.e. a two-dimensional Euclidean space). In other words, there is only one plane that contains that triangle, and...

`:)`

---

<div class="post-metadata">

**Author:** ![JoseMY](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josemy/32/2016_2.png) [@JoseMY](https://discourse.processing.org/u/JoseMY)\
**Post date:** [April 9, 2023, 9:07pm UTC](https://discourse.processing.org/t/hi-i-need-help-with-this-question-triangle-at-mouse-position/41593/5 "2023-04-09T21:07:24Z")

</div>

Hi, ComputerScience.

I learnt to program a ZX Spectrum when I was 12, 3 years before I studied trigonometry, so I am taking into consideration you could be in the same case.

Just in case your problem is about drawing a triangle with known centre, and you NEVER before studied trigonometry:

You can use sin() and cos() to make a equilateral triangle of known centre.

cy+sin(angle)\*r, cx+cos(angle)\*r is always a point in the limit of a circle with centre (cx,cy) and radius r.

An equilateral triangle has their angles separated 60 degrees each, this makes PI/3 radians (computers use radians instead of degrees).

I am surprised none gave help on the “triangle with known centre” issue. Triangles can have many kinds of “centre”, and only equilateral triangles have all “centres” in the same point. So if, by chance, your teacher wanted a square triangle with baricenter at mousex, mousey, the solution would be completely different.
