# Processing magic

**URL:** <https://discourse.processing.org/t/processing-magic/28072>\
**Category:** Gallery\
**Created:** [February 25, 2021, 3:15am UTC](https://discourse.processing.org/t/processing-magic/28072 "2021-02-25T03:15:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 25, 2021, 3:15am UTC](https://discourse.processing.org/t/processing-magic/28072/1 "2021-02-25T03:15:56Z")

</div>

```auto
int num = 6000;

float[] x01 = new float[num];
float[] y01 = new float[num];
float[] z01 = new float[num];
float[] x02 = new float[num];
float[] y02 = new float[num];
float[] z02 = new float[num];
float[] deg01 = new float[num];
float[] deg02 = new float[num];
float rot_x;
float rot_y;
float rot_z;
float amp01;
float amp02;
float range;

void setup () {

  
    amp01 = 200.0;

    rot_x = 0.0;
    rot_y = 0.0;
    rot_z = 0.0;

    range = 4.0;

    size (1920, 1080, P3D);
    colorMode (RGB, 256);
    background (0);
    frameRate (60);

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

        deg01[i] = random (360);
        deg02[i] = random (360);

    }

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

        
        x01[i] = amp01 * cos (radians (deg01[i])) * sin (radians (deg02[i]));
        y01[i] = amp01 * sin (radians (deg01[i]));
        z01[i] = amp01 * cos (radians (deg01[i])) * cos (radians (deg02[i]));

    }

}

void draw () {

    background (0);

    
    camera (mouseX - (width / 2), mouseY - (height / 2), 0.0,
            width / 2, height / 2, 0.0,
            0.0, 1.0, 0.0);

    translate (width / 2, height / 2);
    rotateX (radians (rot_x));
    rotateY (radians (rot_y));
    rotateZ (radians (rot_z));

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

       
        float offsetx = mouseX - (width / 2);
        float offsety = mouseY - (height / 2);

       
        float diffx = abs (offsetx - x01[i]);
        float diffy = abs (offsety - y01[i]);

       
        amp02 = (4000 / (diffx + diffy + 1)) + amp01 + 1;

      
        x02[i] = amp02 * cos (radians (deg01[i])) * sin (radians (deg02[i]));
        y02[i] = amp02 * sin (radians (deg01[i]));
        z02[i] = amp02 * cos (radians (deg01[i])) * cos (radians (deg02[i]));

        stroke (int (abs (x01[i])), int (abs (y01[i])), int (abs (z01[i])));
        strokeWeight (1);
        noFill ();
       
        line (x01[i], y01[i], z01[i], x02[i], y02[i], z02[i]);

    }

    rot_x += map (mouseY, 0, height, -range, range);
    rot_y += map (mouseX, 0, width, -range, range);
    rot_z += ((map (mouseY, 0, height, -range, range) + map (mouseX, 0, width, -range, range)) / 2);

    //saveFrame ();

}

```

---

<div class="post-metadata">

**Author:** ![jafal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jafal/32/19112_2.png) [@jafal](https://discourse.processing.org/u/jafal)\
**Post date:** [February 25, 2021, 3:16am UTC](https://discourse.processing.org/t/processing-magic/28072/2 "2021-02-25T03:16:40Z")

</div>

![magic](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/60bec1a617eef8677db8df65051f4f48781ab735.jpeg)
