Skip to content
Snippets Groups Projects
Commit 078ba0a9 authored by Damien OLIVIER's avatar Damien OLIVIER
Browse files

maj Gray-Scott

parent 8386a3a3
Branches master
No related merge requests found
final String CONFIG = "config.csv";
final int DIMENSION = 600; // Taille de la grille
final String CONFIG = "config.csv"; // Taille de la grille
final double convolution [][] = {{0.05, 0.2, 0.05}, {0.2, -1., 0.2}, {0.05, 0.2, 0.05}}; // Pour le Laplacien, matrice de convolution
double diffA; // Taux de diffusion du produit A
......@@ -7,28 +6,27 @@ double diffB;
double f; // Pour la production de A
double k; // Pour la destructon de B
double [][] A = new double[DIMENSION][DIMENSION]; // Concentration en A
double [][] B = new double[DIMENSION][DIMENSION]; // Concentration en B
double [][] dA = new double[DIMENSION][DIMENSION]; // Variation de concentration en A
double [][] dB = new double[DIMENSION][DIMENSION]; // Variation de concentration en B
double [][] A; // Concentration en A
double [][] B; // Concentration en B
double [][] dA; // Variation de concentration en A
double [][] dB; // Variation de concentration en B
void settings()
{
size(DIMENSION, DIMENSION);
}
void setup() {
size(800, 800);
frameRate(25);
smooth();
colorMode(HSB, 1.0);
A = new double[width][width];
B = new double[width][width];
dA = new double[width][width];
dB = new double[width][width];
experience();
}
/**
Lecture des paramètres initiaux dans un fichier csv
et
Initialisation des concentrations
*/
void experience()
......@@ -46,18 +44,18 @@ void experience()
/**
Initialisation des concentrations
La grille est remrmplie de composant A. Seules quelques cellules au centre on du B.
La grille est remplie de composant A. Seules quelques cellules au centre on du B.
*/
void etatInitial() {
for (int i = 0; i < DIMENSION; i++) {
for (int j = 0; j < DIMENSION; j++) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < width; j++) {
A[i][j] = 1.0;
B[i][j] = 0.0;
dA[i][j] = dB[i][j] = 0;
}
}
for (int i = DIMENSION/3; i < 2 * DIMENSION / 3; i++) {
for (int j = DIMENSION/3; j < 2 * DIMENSION / 3; j++)
for (int i = width/2 - width/10 ; i < width/2 + width/10; i++) {
for (int j = width/2 - width/10 ; j < width/2 + width/10; j++)
B[i][j] = (random(0, 1) > 0.99 ? 1 : 0);
}
}
......@@ -77,8 +75,8 @@ void reactionDiffusion(double diffA, double diffB, double f, double k) {
La réaction telle que définie
*/
void reaction(double k, double f) {
for (int i = 0; i < DIMENSION; i++)
for (int j = 0; j < DIMENSION; j++) {
for (int i = 0; i < width; i++)
for (int j = 0; j < width; j++) {
dA[i][j] = - (A[i][j] * B[i][j] * B[i][j]) + f * (1 - A[i][j]);
dB[i][j] = (A[i][j] * B[i][j] * B[i][j]) - (k + f) * B[i][j];
}
......@@ -90,8 +88,8 @@ void reaction(double k, double f) {
*/
void diffusion(double diffA, double diffB) {
for (int i = 0; i < DIMENSION; i++)
for (int j = 0; j < DIMENSION; j++)
for (int i = 0; i < width; i++)
for (int j = 0; j < width; j++)
for (int l = -1; l < 2; l++) // Parcours du voisinage dans le cadre de la diffusion
for (int c = -1; c < 2; c++) {
dA[calculPos(i + l)][calculPos(j + c)] += diffA * A[i][j] * convolution[l+1][c+1];
......@@ -103,8 +101,8 @@ void diffusion(double diffA, double diffB) {
int calculPos(int z)
{
if (z == -1)
return DIMENSION - 1;
else if (z == DIMENSION)
return width - 1;
else if (z == width)
return 0;
else return z;
}
......@@ -114,8 +112,8 @@ int calculPos(int z)
*/
void bilan()
{
for (int i = 0; i < DIMENSION; i++)
for (int j = 0; j < DIMENSION; j++)
for (int i = 0; i < width; i++)
for (int j = 0; j < width; j++)
{
A[i][j] += dA[i][j];
B[i][j] += dB[i][j];
......@@ -130,9 +128,9 @@ void bilan()
void draw() {
for (int p = 0; p < 100; p++)
reactionDiffusion(diffA, diffB, f, k);
for (int i = 0; i < DIMENSION; i++) {
for (int j = 0; j < DIMENSION; j++) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < width; j++) {
set(i, j, color(0.23, 0.71, (float)(1-A[i][j])));
}
}
}
\ No newline at end of file
}
main=AutomateGS.pde
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment