<commit_before>var system;

function setup(){
  createCanvas(windowWidth, windowHeight);

  system = new SolarSystem();
}

function draw(){
  background(25);
  system.draw();
}


class SolarSystem {
  constructor() {
    this.objects = [];
    this.init();
  }

  static get scale_space(){ return 4.5e9 / width; }

  init(){
    let numObjects = 10;
    for(var i=0; i<numObjects; i++){

      if(i == 0){
        this.objects.push(this.generateStar());
      }else{
        this.objects.push(this.generatePlanet());
      }
    }
  }

  generateStar(idx){
    return new MassiveObject(0, 0, 1.9885e30, color(200,190,40));
  }

  generatePlanet(idx){
    // our solar system is 4.5e9 km along major axis;
    // mecury, perihelion: 46,001,200 km
    let randLoc = createVector(random(40, 2500) * 1e6, random(40, 2500) * 1e6);
    let randTheta = random(0, TWO_PI);
    randLoc.rotate(randTheta);

    // jupiter: 1.8982×1027 or 18,982x1023
    // mecury   3.3011×1023
    let mass = random(3, 20000) * 1e23;

    let surfaceColor = color(random(50, 200),random(50, 200),random(50, 200));
    return new MassiveObject(randLoc.x, randLoc.y, mass, surfaceColor);
  }

  draw(){
    push();
    translate(width/2, height/2);
    for(var i=0; i < this.objects.length; i++){
      this.objects[i].draw();
    }
    pop();
  }
}

class MassiveObject {
  constructor(x, y, mass, color) {
    this.pos = createVector(x, y);
    this.accel = createVector(0, 0);
    this.speed = createVector(0, 0);
    this.mass = mass; // kg
    this.c = color;
  }

  get x(){ return this.pos.x; }
  get y(){ return this.pos.y; }

  tick(){
    this.pos.add(this.speed);
    this.speed.add(this.accel);
  }

  draw(){
    fill(this.c);
    ellipse(this.x / SolarSystem.scale_space, this.y / SolarSystem.scale_space, 
                10, 10);
  }
}<commit_msg>p5js/solar-system - Add scaling of object radius based on mass<commit_after>var system;

function setup(){
  createCanvas(windowWidth, windowHeight);

  system = new SolarSystem();
}

function draw(){
  background(25);
  system.draw();
}


class SolarSystem {
  constructor() {
    this.objects = [];
    this.init();
  }

  static get scale_space(){ return 4.5e9 / width; }

  init(){
    let numObjects = 10;
    for(var i=0; i<numObjects; i++){

      if(i == 0){
        this.objects.push(this.generateStar());
      }else{
        this.objects.push(this.generatePlanet());
      }
    }
  }

  generateStar(idx){
    return new MassiveObject(0, 0, 1.9885e30, color(200,190,40));
  }

  generatePlanet(idx){
    // our solar system is 4.5e9 km along major axis;
    // mecury, perihelion: 46,001,200 km
    let randLoc = createVector(random(40, 2500) * 1e6, random(40, 2500) * 1e6);
    let randTheta = random(0, TWO_PI);
    randLoc.rotate(randTheta);

    // jupiter: 1.8982×1027 or 18,982x1023
    // mecury   3.3011×1023
    let mass = random(3, 10000) * 1e23;

    let surfaceColor = color(random(50, 200),random(50, 200),random(50, 200));
    return new MassiveObject(randLoc.x, randLoc.y, mass, surfaceColor);
  }

  draw(){
    push();
    translate(width/2, height/2);
    noStroke();
    for(var i=0; i < this.objects.length; i++){
      this.objects[i].draw();
    }
    pop();
  }
}

class MassiveObject {
  constructor(x, y, mass, color) {
    this.pos = createVector(x, y);
    this.accel = createVector(0, 0);
    this.speed = createVector(0, 0);
    this.mass = mass; // kg
    this.c = color;

    this.scaledRadius = Math.log10(this.mass);
  }

  get x(){ return this.pos.x; }
  get y(){ return this.pos.y; }

  tick(){
    this.pos.add(this.speed);
    this.speed.add(this.accel);
  }

  draw(){
    fill(this.c);
    ellipse(this.x / SolarSystem.scale_space, this.y / SolarSystem.scale_space, 
                this.scaledRadius, this.scaledRadius);
  }
}
{'fraction_non_alphanumeric': 0.16076580120639916, 'fraction_numerical': 0.06058221872541306, 'mean_word_length': 2.77998017839445, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2397310', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1379, 'n_words': 299}