We are about to switch to a new forum software. Until then we have removed the registration on this forum.
So I am trying to populate an asteroid field where each asteroid is connected to an array, then the field rotates around the sun, and the earth. So far I have the earth rotating around the sun, and the field appears as a huge square of static that rotates around the sun. How can I make that field into a circle of asteroids around the sun (center)?
var backgroundie;
var suntext;
//var astertext;
var earthtext;
var data;
var ang;
var rad;
var zoom = 1;
var nea;
var asteroids= [];
function preload(){
nea = loadStrings('nea.csv');
backgroundie = loadImage('stars.jpg');
suntext = loadImage('suntext.jpg');
earthtext = loadImage('earth.jpg');
//astertext = loadImage('aster.jpg');
}
function setup(data){
cursor(CROSS);
createCanvas(innerWidth,innerHeight, WEBGL);
translate(width/2,height/2);
//imageMode(CORNER);
//image(backgroundie,((innerWidth/2)*-1),((innerHeight/2)*-1),innerWidth,innerHeight);
for(var i = 0; i < nea.length; i++){
var data = nea[i].split(',');
var name = data[0];
var type = data[1];
var sma = data[2];
var e = data[3];
var value = data[4];
var profit = data[5];
var accel = data[6];
var moid = data[7];
var group = data[8];
asteroids.push(new Asteroid(name,type,sma,e,value,profit,accel,moid,group));
console.log("for loop");
}
}
function draw(){
background(12);
push();
texture(suntext);
rotateZ(frameCount * 0.01);
sphere(30);
texture(earthtext);
translate(0,300,0);
sphere(10);
translate(0,-300,0);
field();
console.log("done");
pop();
}
function field(){
for(var i=1; i<500; i++){
asteroids[i].display();
}
}
function Asteroid(name,type,sma,e,value,profit,accel,moid,group){
this.name=name;
this.type=type;
this.sma=sma;
this.e=e;
this.value=value;
this.profit=profit;
this.accel=accel;
this.moid=moid;
this.group=group;
this.display=function(){
push();
ambientMaterial(41,41,41,100);
//console.log("Function Processed");
translate((random(30,250)),(random(30,250)),0);
sphere(1);
//console.log("Sphere Created");
pop();
}
}
Answers
we can't realistically run that without the images.
I figured it out by making a an x and y variable for each instance of the object and having those variables established like