add line on tunnel

ajout des ligne autoure des cercle du tunelle
This commit is contained in:
lapin 2020-10-07 01:29:40 +02:00
parent 24126bc840
commit 18312c3b4a

View File

@ -20,14 +20,11 @@ Point[] c1, c2, c3, c4;
LaserOut laser_frame; LaserOut laser_frame;
// evite de metre un nombre de point negatif // 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[] create_circle(float center_x, float center_y, float radius, int nb_point, int col){
{
Point[] line = new Point[nb_point + 1]; Point[] line = new Point[nb_point + 1];
int i;
for (i = 0; i < line.length; i++)
{
float px, py, factor; float px, py, factor;
for (int i = 0; i < line.length; i++){
factor = float(i) / float(line.length - 1); factor = float(i) / float(line.length - 1);
px = center_x + radius * cos(factor * TWO_PI); px = center_x + radius * cos(factor * TWO_PI);
py = center_y + radius * sin(factor * TWO_PI); py = center_y + radius * sin(factor * TWO_PI);
@ -36,6 +33,21 @@ Point[] create_circle(float center_x, float center_y, float radius, int nb_point
return (line); 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() { void setup() {
size(800, 800); size(800, 800);
@ -46,8 +58,7 @@ void setup() {
laser_frame = new LaserOut(); laser_frame = new LaserOut();
} }
int getColInt(int r, int g, int b) int getColInt(int r, int g, int b){
{
int col; int col;
col = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF)); col = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
@ -77,12 +88,11 @@ void draw_circle_test(){
} }
float get_distance(int id, int max_id, float distance, float prct_anime) float get_distance(int id, int max_id, float distance, float prct_anime){
{
float dist; float dist;
dist = ((float(id) / float(max_id)) + prct_anime) % 1.0; dist = distance * (((float(id) / float(max_id)) + prct_anime) % 1.0);
return (dist); return (dist + 0.03);
} }
void draw_tunel(int time_milis){ void draw_tunel(int time_milis){
@ -91,9 +101,9 @@ void draw_tunel(int time_milis){
// on va aussi tracer des cercle // on va aussi tracer des cercle
int nb_circle = 20; int nb_circle = 15;
int time_periode = 5 * 1000; // 10 seconde int time_periode = 20 * 1000; // 10 seconde
float distance = 20; float distance = 1;
float prct_anime = 5 - (float(time_milis % time_periode) / float(time_periode)); float prct_anime = 5 - (float(time_milis % time_periode) / float(time_periode));
int pt_per_circle = 15; int pt_per_circle = 15;
@ -105,14 +115,17 @@ void draw_tunel(int time_milis){
cy = 400; cy = 400;
radius = 30; radius = 30;
float prct;
// on dessine les cercle
for (int i = 0; i < nb_circle; i++){ for (int i = 0; i < nb_circle; i++){
prct = float(i) / float(nb_circle);
prct = 1;
r = int(float(radius) / get_distance(i, nb_circle, distance, prct_anime)); 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(int(255 * prct), int(255 * prct), int(255 * prct)))); 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)));
} }
} }