laser_tunnel/laser_tunnel.pde

137 lines
3.5 KiB
Plaintext
Raw Normal View History

/*
Alors petit programe du jour:
* On a une liste de point.
* On l'affiche a l'ecran.
* on format une chaine de charactere pour l'afficher avec le laser
*
* On definie des courbe de bezier
* On affiche un tunnel
* Il faudra un truc pour definir
*
* ===
* Il nous faut une structure de segment [{pos_x, pos_y, color}, {pos_x, pos_y, color}]
* Un tableau de
*
*/
Point[] c1, c2, c3, c4;
LaserOut laser_frame;
// evite de metre un nombre de point negatif
Point[] create_circle(float center_x, float center_y, float radius, int nb_point, int col){
Point[] line = new Point[nb_point + 1];
float px, py, factor;
for (int i = 0; i < line.length; i++){
factor = float(i) / float(line.length - 1);
px = center_x + radius * cos(factor * TWO_PI);
py = center_y + radius * sin(factor * TWO_PI);
line[i] = new Point(int(px), int(py), col);
}
return (line);
}
Point[] create_tunnel_line(float center_x, float center_y, float radius, float distance, int id, int nb_point, float prct_anime, int col){
Point[] line = new Point[nb_point + 1];
float px, py, factor, r;
//r = int(float(radius) / get_distance(i, nb_circle, distance, prct_anime));
factor = float(id) / float(nb_point);
for (int i = 0; i < line.length; i++){
r = int(radius / get_distance(i, nb_point, distance, prct_anime));
px = center_x + r * cos(factor * TWO_PI);
py = center_y + r * sin(factor * TWO_PI);
line[i] = new Point(int(px), int(py), col);
}
return (line);
}
void setup() {
size(800, 800);
background(0);
// ...
// circle = create_circle(400, 400, 70, 25);
laser_frame = new LaserOut();
}
int getColInt(int r, int g, int b){
int col;
col = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
return (col);
}
void draw_circle_test(){
int rad, radm, nb_point;
float cx, cy;
nb_point = 25;
rad = 40;
radm = rad / 2;
cx = 400;
cy = 400;
c1 = create_circle( cx, cy, rad, nb_point, getColInt(255, 255, 255));
c2 = create_circle(cx - radm, cy - radm, rad, nb_point, getColInt( 0, 255, 0));
c3 = create_circle(cx + radm, cy - radm, rad, nb_point, getColInt( 0, 0, 255));
c4 = create_circle( cx, cy + radm, rad, nb_point, getColInt(255, 0, 0));
// ajoute une chaine de charactere a la frame + dessine sur processing
laser_frame.add_line(c1);
laser_frame.add_line(c2);
laser_frame.add_line(c3);
laser_frame.add_line(c4);
}
float get_distance(int id, int max_id, float distance, float prct_anime){
float dist;
dist = distance * (((float(id) / float(max_id)) + prct_anime) % 1.0);
return (dist + 0.03);
}
void draw_tunel(int time_milis){
// on va tracer des crecle qui vont se raprocher et des ligne sur ces cercle
// plus les cercle sont loin plus les cercle on un radius petit
// on va aussi tracer des cercle
int nb_circle = 15;
int time_periode = 20 * 1000; // 10 seconde
float distance = 1;
float prct_anime = 5 - (float(time_milis % time_periode) / float(time_periode));
int pt_per_circle = 15;
// position du cercle
// radius
int cx, cy, radius, r;
cx = 400;
cy = 400;
radius = 30;
// on dessine les cercle
for (int i = 0; i < nb_circle; i++){
r = int(float(radius) / get_distance(i, nb_circle, distance, prct_anime));
laser_frame.add_line(create_circle(cx, cy, r, pt_per_circle, getColInt(255, 255, 255)));
}
// on dessine les ligne qui vont avec
for (int i = 0; i < pt_per_circle; i++){
laser_frame.add_line(create_tunnel_line(cx, cy, radius, distance, i, pt_per_circle, prct_anime, getColInt(255, 255, 255)));
}
}
void draw(){
background(0);
draw_tunel(millis());
laser_frame.print_frame();
}