giovedì 18 luglio 2013

Mandelbrot con Processing+Android

Per mettere alla prova quanto appreso dal post precedente un classico, Mandelbrot
Il programma e' eseguito interamente sul telefono Android dopo essere stato compilato con Processing

Screenshot di Android
Il tempo di esecuzione e' inferiore ai 3 secondi e mezzo sul Samsung Next Turbo

-----------------------------------------
int larghezza = 200;
int altezza = 200;

float re_min = -2.0;
float im_min = -1.2;
float re_max = 1.0;
float im_max = 1.2;
int iterazioni = 255;

float a,b,x,y,x_new,y_new;
int i,j,k;
  
float re_factor=(re_max-re_min);
float im_factor=(im_max-im_min);

void setup() {
  size(200,200);
  background(0,0,0);
  stroke(255);
}

void draw() {
   for (i=0;i<altezza;i++)
    {
      for(j=0;j<larghezza;j++)
      {
        a = re_min+(j*re_factor/larghezza); 
        b = im_min+(i*im_factor/altezza);
   
        x = 0;
        y = 0;

   
        for (k=0;k<iterazioni;k++)
          {
          x_new = (x*x)-(y*y)+a;
          y_new = (2*x*y)+b;
          if (((x_new*x_new)+(y_new*y_new))>4)
             {
             if (k%2 == 0)  point(i,j);
             break;
             }
           x = x_new;
           y = y_new;
           }
  
       }
    }
        
}

Nessun commento:

Posta un commento

Bayesian linear regression

  import sys import numpy as np import pandas as pd import matplotlib.pyplot as plt # Load CSV data def load_data (csv_path): data = pd....