Commit c9edfab7 authored by Vladislav Perepelkin's avatar Vladislav Perepelkin
Browse files

added move and rest

parent 83adf28a
all: run avi
videos: run
make -B density/density.avi
make -B rest/rest.avi
make -B move/move.avi
run: hpprp FORCE
./hpprp
hpprp: hpprp.c config.c collide.c
g++ -O3 hpprp.c -o hpprp -lrt
......@@ -6,15 +12,16 @@ hpprp: hpprp.c config.c collide.c
collide.c: rules.txt scripts/rules_gen.py
python scripts/rules_gen.py rules.txt collide.c
run: hpprp FORCE
./hpprp
density/density.avi:
scripts/image_gen.sh density density/density.avi
avi: density/video.avi
rest/rest.avi:
scripts/image_gen.sh rest rest/rest.avi
density/video.avi: run
scripts/image_gen.sh density
move/move.avi:
scripts/image_gen.sh move move/move.avi
clean:
rm -f density/*.txt density/*.png density/video.avi hpprp collide.c
rm -f density/* rest/* move/* hpprp collide.c
FORCE:
......@@ -14,7 +14,7 @@ void init()
{
fill(0, 0, HEIGHT, WIDTH, // area
0.5, 0.5, 0.5, 0.5, // move
0.5, 0.0, 0.0, 0.0); // rest
0.0, 0.0, 0.0, 0.0); // rest
}
// Sources rules
......@@ -23,12 +23,12 @@ void sources(int iter)
if (iter==0) {
fill(0, WIDTH*4/10, HEIGHT, WIDTH*6/10, // area
1.0, 1.0, 1.0, 1.0, // move
1.0, 0.0, 0.0, 0.0); // rest
0.0, 0.0, 0.0, 0.0); // rest
}
if (iter==ITERS/3) {
fill(0, WIDTH*2/10, HEIGHT, WIDTH*3/10, // area
1.0, 1.0, 1.0, 1.0, // move
1.0, 0.0, 0.0, 0.0); // rest
0.0, 0.0, 0.0, 0.0); // rest
}
}
......@@ -9,8 +9,10 @@ char *field, *new_field;
void fill(int i0, int j0, int i1, int j1,
double r, double d, double l, double u,
double r1, double r2, double r3, double r4);
#include "config.c"
#include "collide.c"
void fill(int i0, int j0, int i1, int j1,
double r, double d, double l, double u,
double r1, double r2, double r3, double r4)
......@@ -32,14 +34,19 @@ void fill(int i0, int j0, int i1, int j1,
}
}
inline int get_mass(char cell)
inline int get_move(char cell)
{
int mass=0;
if (cell&1) mass+=1;
if (cell&2) mass+=1;
if (cell&4) mass+=1;
if (cell&8) mass+=1;
return mass;
}
inline int get_rest(char cell)
{
int mass=0;
if (cell&16) mass+=2;
if (cell&32) mass+=4;
if (cell&64) mass+=8;
......@@ -47,36 +54,45 @@ inline int get_mass(char cell)
return mass;
}
int sum_mass(int row, int col)
void sum_mass(int row, int col, int* rest, int* move)
{
int i, j, mass=0;
int i, j;
for (i=-AVERAGING_RADIUS; i<=AVERAGING_RADIUS; i++) {
for (j=-AVERAGING_RADIUS; j<=AVERAGING_RADIUS; j++) {
mass+=get_mass(FIELD(i+row, j+col));
*rest+=get_rest(FIELD(i+row, j+col));
*move+=get_move(FIELD(i+row, j+col));
}
}
return mass;
}
void save(int iter)
{
int i, j;
char file_name[100];
FILE *fl;
FILE *fl_density, *fl_move, *fl_rest;
double square=(AVERAGING_RADIUS*2+1)*(AVERAGING_RADIUS*2+1);
sprintf(file_name, "density/%06d.txt", iter);
fl=fopen(file_name, "w");
fl_density=fopen(file_name, "w");
sprintf(file_name, "move/%06d.txt", iter);
fl_move=fopen(file_name, "w");
sprintf(file_name, "rest/%06d.txt", iter);
fl_rest=fopen(file_name, "w");
for (j=AVERAGING_RADIUS; j<WIDTH-AVERAGING_RADIUS-1; j++) {
double density=0;
int rest=0, move=0;
for (i=AVERAGING_RADIUS; i<HEIGHT-AVERAGING_RADIUS-1; i++) {
density+=sum_mass(i, j);
sum_mass(i, j, &rest, &move);
}
density/=HEIGHT*AVERAGING_RADIUS*AVERAGING_RADIUS;
fprintf(fl, "%d\t%lf\n", j, density);
fprintf(fl_density, "%d\t%lf\n", j, (rest+move)/HEIGHT/square);
fprintf(fl_move, "%d\t%lf\n", j, move/HEIGHT/square);
fprintf(fl_rest, "%d\t%lf\n", j, rest/HEIGHT/square);
}
fclose(fl);
fclose(fl_density);
fclose(fl_rest);
fclose(fl_move);
}
void swap_buffers()
......
#!/bin/sh
zmin=0
zmax=6
for x in `ls $1/*.txt`; do
echo 'set term png
set yrange[0:20]
set yrange['$zmin':'$zmax']
set output '\"$x.png\"'
plot '\"$x\"'' | gnuplot - 2>/dev/null
done
mencoder mf://$1/*.png -mf fps=10:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o $1/video.avi
mencoder mf://$1/*.png -mf fps=10:type=png -ovc lavc -lavcopts vcodec=mpeg4:mbd=2:trell -oac copy -o $2
Markdown is supported
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