# Getting a specific character printed when mouse is clicked

**URL:** <https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138>\
**Category:** Coding Questions\
**Created:** [November 2, 2018, 10:51pm UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138 "2018-11-02T22:51:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![rebelcoder](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rebelcoder](https://discourse.processing.org/u/rebelcoder)\
**Post date:** [November 2, 2018, 10:51pm UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/1 "2018-11-02T22:51:37Z")

</div>

Hey Guys, I am trying to write a program in which the alphabets are rotating in a circle with constant speed. this is my code for drawing the characters in a circle and then rotating them in a circle. the first angle draws them, and the theta rotates them. the starting value of theta is 0 and it changes every frame. what I need to do is to make a textbox in the bottom so that when the mouse is clicked, only the character which is at the top if the circle gets displayed. any help would be greatly appreciated. the values of CenterX and Y are the middle of the canvas

```auto
for(i = 'a' ; i < 'z' ; i++){
   angle = (i/26.0)*(2*PI);
   x = (CenterX)+cos(angle+theta)*radius;
   y = (CenterY)+sin(angle+theta)*radius;
   textSize(20);
   text(i, x, y);
   theta += 0.005;
   }

```

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 3, 2018, 1:44am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/2 "2018-11-03T01:44:47Z")

</div>

I‘ll Post a link to another question about this assignment. (Just assume it is the Same, since i‘ve See this 3 Times These last 3 days.

> [@How to make shapes out of characters using loop?](https://discourse.processing.org/t/how-to-make-shapes-out-of-characters-using-loop/5134):
>
> I am trying to make a circle that is made out of English Alphabet. I made a String that included the entire alphabet and I tried creating the circle using each character from the string individually using ‘for’ command (loop) but it didn’t work out for me. I made a small example of what I am trying to create but this time I created the code without using a loop, I only created a small part of the circle since I didn’t want the code to get too repetitive and long for you to read. Can someone hel…

---

<div class="post-metadata">

**Author:** ![rebelcoder](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rebelcoder](https://discourse.processing.org/u/rebelcoder)\
**Post date:** [November 3, 2018, 2:00am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/3 "2018-11-03T02:00:41Z")

</div>

I’ve already made the circle, I need help with the next part. which is to print the character at the top of the circle when the mouse is clicked. my for loop is working

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 3, 2018, 2:17am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/4 "2018-11-03T02:17:06Z")

</div>

Hmm, you could probably do so, by doing something like :  
println(x+anglecalculation);  
Where x = ‘a’ and anglecalculation is so that if it is a, then it is 0 and if it is b then 1 and so on.  
Need Your Code to give you a more precise answer.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 3, 2018, 2:18am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/6 "2018-11-03T02:18:46Z")

</div>

Actually, probably something like map(angle, 0, 360, 0, 26) Would work too.

---

<div class="post-metadata">

**Author:** ![rebelcoder](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rebelcoder](https://discourse.processing.org/u/rebelcoder)\
**Post date:** [November 3, 2018, 2:19am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/7 "2018-11-03T02:19:51Z")

</div>

can you look at this code above and tell me what to put in the mouseClicked function. so that it prints the angle on the top of the circle on the rectangle created.

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 3, 2018, 2:24am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/8 "2018-11-03T02:24:37Z")

</div>

I can‘t just Post the Solution, since it‘s an assignment, But i‘ll explain how to get it done with you code right now. In the Alphabets.charAt() method, put ‘A’ - the inverse calculation you did in your for loop in drawChar() for angle.

---

<div class="post-metadata">

**Author:** ![rebelcoder](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rebelcoder](https://discourse.processing.org/u/rebelcoder)\
**Post date:** [November 3, 2018, 2:28am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/9 "2018-11-03T02:28:51Z")

</div>

The calculation for the angle is a float but char at only accepts ints

---

<div class="post-metadata">

**Author:** ![Lexyth](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/lexyth/32/7403_2.png) [@Lexyth](https://discourse.processing.org/u/Lexyth)\
**Post date:** [November 3, 2018, 2:29am UTC](https://discourse.processing.org/t/getting-a-specific-character-printed-when-mouse-is-clicked/5138/10 "2018-11-03T02:29:40Z")

</div>

Actually no, that Would only work if you knew the top letter beforehand… how do you rotate this Wheel? If there is a function that adds an rotazionale Offset, just get that and set the Alphabet.charAt() to it… Or if it‘s already an angle, inverse the calculation for it. Same as i said with angle, just that i falsely assumed that was used to rotate the wheel.  
Edit: just use int(float) to turn it into int.
