Move an array based on cos + sin using mouseY ?
in
Programming Questions
•
2 years ago
Hi
I have created four arrays of spheres based on sin and cos and I would like to be able to move two of the arrays clockwise and the other anti-clockwise based mouseY position.Any hints please?
--George
//variables
float radius=120;
int npoints=29;
float inc_angle=(2*PI)/float(npoints);
float rotcam=0;
color xrwma = color (211,234,141);
float angle=0;
point1[] Points1 = new point1[npoints];
point1[] Points2 = new point1[npoints];
point1[] Points3 = new point1[npoints];
point1[] Points4 = new point1[npoints];
//setup arrays of point(sphere) + background etc
void setup()
{
size(600,600,P3D);
smooth();
sphereDetail(13);
stroke(xrwma);
for (int i=0;i<npoints;i++)
{
angle+=inc_angle;
float xcoord=radius*cos(angle);
float ycoord=radius*sin(angle);
Points1[i] = new point1(xcoord,ycoord,300,2,xrwma);
}
for (int i=0;i<npoints;i++)
{
angle+=inc_angle;
float xcoord=radius*cos(angle);
float ycoord=radius*sin(angle);
Points2[i] = new point1(xcoord,ycoord,100,2,xrwma);
}
for (int i=0;i<npoints;i++)
{
angle+=inc_angle;
float xcoord=radius*cos(angle);
float ycoord=radius*sin(angle);
Points3[i] = new point1(xcoord,ycoord,-100,2,xrwma);
}
for (int i=0;i<npoints;i++)
{
angle+=inc_angle;
float xcoord=radius*cos(angle);
float ycoord=radius*sin(angle);
Points4[i] = new point1(xcoord,ycoord,-300,2,xrwma);
}
}
//displaying and animation on screen
void draw()
{
background(141,181,19);
translate(width/2,height/2);
lights();
camera(400,400,400,0,0,55,50.5,400,400);
rotate(rotcam);
for (int i=0;i<npoints;i++)
{
Points1[i].display();
//line(0,0,0,Points1[i].x,Points1[i].y,Points1[i].z);
}
for (int i=0;i<npoints;i++)
{
Points2[i].display();
//line(0,0,0,Points2[i].x,Points2[i].y,Points2[i].z);
}
for (int i=0;i<npoints;i++)
{
Points3[i].display();
//line(0,0,0,Points3[i].x,Points3[i].y,Points3[i].z);
}
for (int i=0;i<npoints;i++)
{
Points4[i].display();
//line(0,0,0,Points4[i].x,Points4[i].y,Points4[i].z);
}
//rotcam-=PI/200;
}
//CLASS
class point1
{
//var
float x,y,z;
float diametros;
color xrwma;
//const
//(thesix,thesiy,thesiz,diametros,xrwma)
point1 (float xpos, float ypos, float zpos, float diam, color xrw)
{
x=xpos;
y=ypos;
z=zpos;
diametros=diam;
xrwma=xrw;
}
//disp
void display()
{
pushMatrix();
translate(x,y,z);
sphere(diametros);
fill(xrwma);
popMatrix();
}
}
1
