# Change shape by sound input

**URL:** <https://discourse.processing.org/t/change-shape-by-sound-input/2877>\
**Category:** Coding Questions\
**Created:** [August 23, 2018, 9:25am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877 "2018-08-23T09:25:48Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiraw](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@kiraw](https://discourse.processing.org/u/kiraw)\
**Post date:** [August 23, 2018, 9:25am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/1 "2018-08-23T09:25:48Z")

</div>

Hey, after my first problem get solved here, I hope someone can help me again. 🙂  
I want the shape (as you can hopefully see on the picture) is changing by sound input. When the sound is loud, the shape should be bigger and in a different color as if the sound is quieter. The inner circle is constantly in the same position. Just the outer circle should change the size.

 ![Idea-01](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/1/1a35c11e248dfdb9f0dd2fcd65b602f8bec4df13.png)

This is my code so far:

```auto
float scale = 1;

int shapelength = 12;

int iterations = 22;

import ddf.minim.*;

Minim minim;
AudioInput in;

float[][][] shape_coords = new float[2][shapelength][2];

void setup() {

  size(3840, 2160);

  background (255, 48, 48);
  
  minim = new Minim(this);
  
  in = minim.getLineIn(); // Audio Input

// inner circle

  shape_coords[1][0][0] = 1500 * scale;

  shape_coords[1][0][1] = 1495 * scale;

  shape_coords[1][1][0] = 1500 * scale;

  shape_coords[1][1][1] = 1495 * scale;

  shape_coords[1][2][0] = 1500 * scale;

  shape_coords[1][2][1] = 1495 * scale;

  shape_coords[1][3][0] = 1500 * scale;

  shape_coords[1][3][1] = 1495 * scale;

  shape_coords[1][4][0] = 1500 * scale;

  shape_coords[1][4][1] = 1495 * scale;

  shape_coords[1][5][0] = 1500 * scale;

  shape_coords[1][5][1] = 1495 * scale;

  shape_coords[1][6][0] = 1500 * scale;

  shape_coords[1][6][1] = 1495 * scale;
    
  shape_coords[1][7][0] = 1500 * scale;

  shape_coords[1][7][1] = 1495 * scale;

  shape_coords[1][8][0] = 1500 * scale;

  shape_coords[1][8][1] = 1495 * scale;

  shape_coords[1][9][0] = 1500 * scale;

  shape_coords[1][9][1] = 1495 * scale;

  shape_coords[1][10][0] = 1500 * scale;

  shape_coords[1][10][1] = 1495 * scale;

  shape_coords[1][11][0] = 1500 * scale;

  shape_coords[1][11][1] = 1495 * scale;

// outer circle

  shape_coords[0][0][0] = 1520 * scale;

  shape_coords[0][0][1] = 485 * scale;

  shape_coords[0][1][0] = 2020 * scale;

  shape_coords[0][1][1] = 1150 * scale;

  shape_coords[0][2][0] = 2535 * scale;

  shape_coords[0][2][1] = 775 * scale;

  shape_coords[0][3][0] = 2880 * scale;

  shape_coords[0][3][1] = 1130 * scale;

  shape_coords[0][4][0] = 3100 * scale;

  shape_coords[0][4][1] = 1633 * scale;

  shape_coords[0][5][0] = 2720 * scale;

  shape_coords[0][5][1] = 1770 * scale;

  shape_coords[0][6][0] = 2170 * scale;

  shape_coords[0][6][1] = 1275 * scale;

  shape_coords[0][7][0] = 1365 * scale;

  shape_coords[0][7][1] = 1760 * scale;

  shape_coords[0][8][0] = 725 * scale;

  shape_coords[0][8][1] = 1160 * scale;

  shape_coords[0][9][0] = 1520 * scale;

  shape_coords[0][9][1] = 485 * scale;

  shape_coords[0][10][0] = 2020 * scale;

  shape_coords[0][10][1] = 1150 * scale;

  shape_coords[0][11][0] = 2535 * scale;

  shape_coords[0][11][1] = 1150 * scale;

}

void draw() {

  
  strokeWeight (2);

 //shaping
 

  for (int j = 0; j < iterations; j++) {

    
    stroke (118, 138, 0);
    noFill();

    beginShape();

    for (int i = 0; i < shapelength; i++) {

      curveVertex(lerp(shape_coords[0][i][0], shape_coords[1][i][0], float(j)/float(iterations)), lerp(shape_coords[0][i][1], shape_coords[1][i][1], float(j)/float(iterations)));

    }

    endShape();

  }

}

```

Thanks a lot for any help!

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [August 23, 2018, 9:34am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/2 "2018-08-23T09:34:43Z")

</div>

I learned that I am no longer allowed to give you the code but here is a nice quote from the guidelines:

> [@Guidelines—Answering Questions](https://discourse.processing.org/t/guidelines-answering-questions/2145/1):
>
> The only way to learn it is by going through it

Have fun.

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [August 23, 2018, 9:35am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/3 "2018-08-23T09:35:51Z")

</div>

Hint: There already is a scale-factor, maybee use that? Be careful tho since it applies to both shapes.

---

<div class="post-metadata">

**Author:** ![kiraw](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@kiraw](https://discourse.processing.org/u/kiraw)\
**Post date:** [August 23, 2018, 10:20am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/4 "2018-08-23T10:20:28Z")

</div>

Thanks. I just want to finish this project, after I will need processing never again. As I said in my first question, I need to understand the code by myself, so I don’t just copy and paste it. I have no idea how to start and build a working code by my own. A whole code is also a help like just a hint. Sometimes the better help. And I think it’s everybodys own business, if he or she just copy a code or try to understand it. 🙂

---

<div class="post-metadata">

**Author:** ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)\
**Post date:** [August 24, 2018, 9:27pm UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/5 "2018-08-24T21:27:13Z")

</div>

You need to look into some examples provided by the minim library. Any basic example will show you how you can get the amplitude from your input signal via your mic.

Then you need to associate the value of scale to the amplitude read by minim. This is done in setup.

The third thing you need to do is to move your points definitions into draw so they get updated every time scale is updated.

Kf

---

<div class="post-metadata">

**Author:** ![kiraw](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@kiraw](https://discourse.processing.org/u/kiraw)\
**Post date:** [August 30, 2018, 8:51am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/6 "2018-08-30T08:51:19Z")

</div>

Thanks for your help. I tried my best but can’t fix my problem. Are there any other tips or examples you can give?

---

<div class="post-metadata">

**Author:** ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)\
**Post date:** [August 30, 2018, 11:41am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/7 "2018-08-30T11:41:57Z")

</div>

Hi,  
how far did you get?  
Are you able to get the input volume as a number? If so try to print it with println(); and upload your code so we can help you go further.

---

<div class="post-metadata">

**Author:** ![kiraw](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@kiraw](https://discourse.processing.org/u/kiraw)\
**Post date:** [August 30, 2018, 11:47am UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/8 "2018-08-30T11:47:18Z")

</div>

Hey, my code doesn’t change. Everything I tried doesn’t work. ☹

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 2, 2018, 10:19pm UTC](https://discourse.processing.org/t/change-shape-by-sound-input/2877/10 "2018-09-02T22:19:05Z")

</div>

You may want to try using the `getVolume()` method of AudioInput. So: `in.getVolume()` will return a value – this value can then be used to scale a shape, or change the number of iterations in a loop.

[http://code.compartmental.net/minim/audioinput\_method\_getvolume.html](http://code.compartmental.net/minim/audioinput_method_getvolume.html)
