# Can someone tell me what is wrong with my conversion of this code?

**URL:** <https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370>\
**Category:** Coding Questions\
**Created:** [July 4, 2020, 12:47am UTC](https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370 "2020-07-04T00:47:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tinkrit](https://avatars.discourse-cdn.com/v4/letter/t/ba9def/32.png) [@tinkrit](https://discourse.processing.org/u/tinkrit)\
**Post date:** [July 4, 2020, 12:47am UTC](https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370/1 "2020-07-04T00:47:54Z")

</div>

```auto
//
// Conversione in P5.js di "Quasicrystals as sums of waves in the plane"
// http://mainisusuallyafunction.blogspot.it/2011/10/quasicrystals-as-sums-of-waves-in-plane.html
//

var dimPix = 0.4;
var numeroLivelli = 7;

var passoOrientamenti;

var xPixMax;
var yPixMax;

function setup()
{
    createCanvas(400, 400);
	 //createCanvas(windowWidth, windowHeight);
	
	
	  pixelDensity(1);
	  background(0);

	  passoOrientamenti = PI / numeroLivelli;
	  xPixMax = width / 2;
    yPixMax = height / 2;

    loadPixels();
}

function draw()
{
    var tempo = frameCount*0.1;
  
    var iPix = 0;
    for (var yPix = -yPixMax; yPix < yPixMax; yPix++)
    {
        var y = yPix*dimPix;

        for (var xPix = -xPixMax; xPix < xPixMax; xPix++, iPix+=4) 
        {
            var x = xPix*dimPix;              

            var orientamento = 0.0;
            var seno;
            var coseno;
            var somma = 0;

            for (var i = 0; i < numeroLivelli; i++) {
                seno = sin(orientamento);
                coseno = cos(orientamento);
                somma += (atan( coseno*x + seno*y + tempo) + 1.0) / 2.0;
                orientamento += passoOrientamenti;
            }
      
            var interoSomma = floor(somma);
            var decimaliSomma = somma - interoSomma;
            somma = (interoSomma % 2) == 0 ? decimaliSomma : 1.0 - decimaliSomma; 

            var grigio = somma*256;
	      		pixels[iPix] = grigio; 
	      		pixels[iPix+1] = grigio; 
		      	pixels[iPix+2] = grigio; 
        }
    } 
    updatePixels();
}

```

 ![imcompare](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/0/0ea2653d6fed9252b1d3cb628fa830552ca84b20.png)  
The image one the left shows the original code above the image on the right shows the code below

```auto
//
// Conversione in P5.js di "Quasicrystals as sums of waves in the plane"
// http://mainisusuallyafunction.blogspot.it/2011/10/quasicrystals-as-sums-of-waves-in-plane.html
//

float dimPix = 0.4;//.4
int numeroLivelli =7;//7

float passoOrientamenti;

int xPixMax;
int yPixMax;

void setup()
{
    size(400, 400,P3D);
	 //createCanvas(windowWidth, windowHeight);
	
	
	// pixelDensity(1);
	  background(0);

	float passoOrientamenti = PI / numeroLivelli;
	  xPixMax = width / 2;
    yPixMax = height / 2;

    loadPixels();
    all= width*height;
}
int all;
 void draw()
{
    float tempo = frameCount*0.1;
  
    int iPix = 0;
    for (int yPix = -yPixMax; yPix < yPixMax; yPix++)
    {
        float y = yPix*dimPix;

        for (int xPix = -xPixMax; xPix < xPixMax; xPix++, iPix+=4) 
        {
            float x = xPix*dimPix;              

            float orientamento = 0.0;
            float seno;
            float coseno;
            float somma = 0;

            for (int i = 0; i < numeroLivelli; i++) {
                seno = sin(orientamento);
                coseno = cos(orientamento);
                somma += (atan( coseno*x + seno*y + tempo) + 1.0) / 2.0;
                orientamento += passoOrientamenti;
            }
      
            float interoSomma = floor(somma);
            float decimaliSomma = somma - interoSomma;
            somma = (interoSomma % 2) == 0 ? decimaliSomma : 5 - decimaliSomma;//1.0

            int grigio = int( somma*256);//256
            int val = iPix/4;
           // pixels[val] = grigio;
           // if(val<all-1)pixels[val+1] = grigio;
	      		pixels[iPix/4] = grigio; 
	      		//pixels[iPix+1] = grigio; 
		       //pixels[iPix+2] = grigio; 
        }
    } 
    updatePixels();
}

```

Can anyone see what is wrong with my conversion code?

---

<div class="post-metadata">

**Author:** ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)\
**Post date:** [July 4, 2020, 1:17am UTC](https://discourse.processing.org/t/can-someone-tell-me-what-is-wrong-with-my-conversion-of-this-code/22370/2 "2020-07-04T01:17:36Z")

</div>

This matches your desired outcome I think …

```auto
//
// Conversione in P5.js di "Quasicrystals as sums of waves in the plane"
// http://mainisusuallyafunction.blogspot.it/2011/10/quasicrystals-as-sums-of-waves-in-plane.html
//

var dimPix = 0.4;
var numeroLivelli = 7;

var passoOrientamenti;

var xPixMax;
var yPixMax;

function setup()
{
    createCanvas(400, 400);
	 //createCanvas(windowWidth, windowHeight);
	
	
	  pixelDensity(1);
	  background(0);

	  passoOrientamenti = PI / numeroLivelli;
	  xPixMax = width / 2;
    yPixMax = height / 2;

    loadPixels();
}

function draw()
{
    var tempo = frameCount*0.1;
  
    var iPix = 0;
    for (var yPix = -yPixMax; yPix < yPixMax; yPix++)
    {
        var y = yPix*dimPix;

        for (var xPix = -xPixMax; xPix < xPixMax; xPix++, iPix+=4) 
        {
            var x = xPix*dimPix;              

            var orientamento = 0.0;
            var seno;
            var coseno;
            var somma = 0;

            for (var i = 0; i < numeroLivelli; i++) {
                seno = sin(orientamento);
                coseno = cos(orientamento);
                somma += (atan( coseno*x + seno*y + tempo) + 1.0) / 2.0;
                orientamento += passoOrientamenti;
            }
      
            var interoSomma = floor(somma);
            var decimaliSomma = somma - interoSomma;
            somma = (interoSomma % 2) == 0 ? decimaliSomma : 1.0 - decimaliSomma; 

            var grigio = somma*256;
	      		pixels[iPix] = grigio; 
	      		pixels[iPix+1] = grigio; 
		      	pixels[iPix+2] = grigio; 
        }
    } 
    updatePixels();
}

```
