Costellation Star
in
Programming Questions
•
2 years ago
Hello everyone I am a new member and I apologize for any mistake can do.
I'm working for a short time in processing. I would like to create a star system
of dots / ellipses that react to mouse movement. In
practice with the arrival of the mouse on the Stage are some stars
to convert the mouse to form a grid taken from a file
dxf. I colored in blue balls that must Getting around.
I'm working for a short time in processing. I would like to create a star system
of dots / ellipses that react to mouse movement. In
practice with the arrival of the mouse on the Stage are some stars
to convert the mouse to form a grid taken from a file
dxf. I colored in blue balls that must Getting around.
// dichiaro
Star [] starCostellation = new Star [20];
Formazione [] starFormation = new Formazione [10];
void setup() {
size(1200,600);
smooth();
// Inizializzo
for(int i = 0; i < starCostellation.length; i++) {
starCostellation[i] = new Star(random(0,width),random(0,height/2),random(0,width));
}
for (int n = 0; n < starFormation.length; n++) {
starFormation[n] = new Formazione();
}
}
void draw() {
background(0);
// funzione chiamata
for(int i = 0; i < starCostellation.length; i++) {
starCostellation[i].run();
}
for (int n = 0; n < starFormation.length; n++) {
starFormation[n].display();
starFormation[n].mouse();
}
}
///////////////////
class Formazione {
float beginX;
float beginY;
float endX;
float endY;
float distX;
float distY;
float x; // valore attuale x
float y; // valore attuale y
float exponent = 5; // grado curva esponenziale
float step = 0.01; // dmensione step di avanzamento
float pct = 1.0; // percentuale travel da 0 a 1
Formazione() {
beginX = x;
beginY = y;
endX = mouseX;
endY = mouseY;
x = random(width);
y = random(height/2);
}
void display() {
distX = endX - beginX;
distY = endY - beginY;
pct += step;
if (mouseX > 0.0) {
x = beginX + (pct * distX);
y = beginY + (pct * distY);//(pow(pct, exponent) * distY);
}
fill (155,155,100);
ellipse(x,y,7,7);
}
void mouse() {
pct = 0.0;
beginX = x;
beginY = y;
endX = mouseX;
endY = mouseY;
distX = endX - beginX;
distY = endY - beginY;
}
}
///////////////
class Star {
float x;
float y;
float z;
Star(float _x, float _y, float _z) {
x = _x;
y = _y;
z = _z;
}
void run() {
display();
}
void display() {
colorMode(HSB, 255);
color c = color(0, 0, 255);
fill(c);
ellipse(x,y,7,7);
float value = brightness(c); // Sets "value" to "255"
fill(value);
}
}