first commit

ther is a base to draw line and covert to str format to the standar
output.
This commit is contained in:
lapin 2020-10-06 22:55:32 +02:00
commit 732dd6fb5f
4 changed files with 189 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# java binary
application.linux-arm64/
application.linux-armv6hf/
application.linux32/
application.linux64/
#vim temporaty file
.*.sw*
*.autosave

63
LaserOut.pde Normal file
View File

@ -0,0 +1,63 @@
public void processing_draw_line(Point[] line)
{
int i;
Point p1, p2;
for (i = 0; i < line.length - 1; i++)
{
p1 = line[i];
p2 = line[i + 1];
stroke(p1.r, p1.g, p1.b);
line(p1.x, p1.y, p2.x, p2.y);
}
}
public class LaserOut
{
String laser_out;
boolean is_empty;
LaserOut()
{
laser_out = new String();
laser_out += "[";
is_empty = true;
}
void print_frame()
{
// to terminate json array
laser_out += "]";
println(laser_out);
// println("\n\n==\n\n");
// flush the string, prepar for next frame
laser_out = "";
//laser_out = new String();
laser_out += "[";
is_empty = true;
}
void add_line(Point[] line)
{
if (is_empty)
is_empty = false;
else
{
laser_out += ", ";
}
// on met un point noir quoi qu'il arrive
laser_out += "[" + str(line[0].x) + ", " + str(line[0].y) + ", 0]";
for (int i = 0; i < line.length; i++)
{
laser_out += ", [" + str(line[i].x) + ", " + str(line[i].y) + ", " + str(line[i].col) + "]";
}
laser_out += ", [" + str(line[line.length - 1].x) + ", " + str(line[line.length - 1].y) + ", 0]";
processing_draw_line(line); // On pourait rajouter une condition si un paraetre est activer
}
}

34
Point.pde Normal file
View File

@ -0,0 +1,34 @@
public class Point
{
public int x;
public int y;
public int r;
public int g;
public int b;
public int col;
Point(int in_x, int in_y, int c)
{
x = in_x;
y = in_y;
r = (c >> 17) & 0xFF;
g = (c >> 8) & 0xFF;
b = (c >> 0) & 0xFF;
col = c;
}
Point(int in_x, int in_y, int col_r, int col_g, int col_b)
{
x = in_x;
y = in_y;
r = col_r & 0xFF;
g = col_g & 0xFF;
b = col_b & 0xFF;
col = (r & 0xFF) << 16| ((g & 0xFF) << 8) | ((b & 0xFF));
}
}

83
test_laserisation.pde Normal file
View File

@ -0,0 +1,83 @@
/*
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];
int i;
for (i = 0; i < line.length; i++)
{
float px, py, factor;
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);
}
void setup() {
size(800, 800);
background(255);
// ...
// circle = create_circle(400, 400, 70, 25);
laser_frame = new LaserOut();
////////////
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));
}
int getColInt(int r, int g, int b)
{
int col;
col = ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF));
return (col);
}
void draw(){
// 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);
laser_frame.print_frame();
}