Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float theta;
- float dTheta;
- Sun theSun;
- float fps;
- void setup() {
- size(480, 480);
- noStroke();
- colorMode(HSB, 360, 100, 100);
- theta = 0;
- dTheta = 0;
- theSun = new Sun(50, width / 2, height / 2);
- }
- void draw() {
- background(0, 0, 100);
- theSun.drawFigure();
- theSun.move();
- }
- class Sun {
- float d; // 直径(50)
- float x; // 中心のx座標(240)
- float y; // 中心のy座標(240)
- Earth theEarth;
- Sun(float d, float x, float y) {
- this.d = d;
- this.x = x;
- this.y = y;
- theEarth = new Earth(0.6 * d, 150); // 直径および回転の半径を与える
- }
- void move() {
- theEarth.move(x, y); // 地球を動かす (太陽の周りを回るので太陽の位置を与える)
- }
- void drawFigure() {
- theEarth.drawFigure(); // Earthオブジェクトに描画を指示
- fill(30, 100, 100);
- ellipse(x, y, d, d); // 自分自身を描画
- }
- }
- class Earth {
- float d;
- float x;
- float y;
- float x1;
- float y1;
- float radEarth;
- float orbitRadius = 100;
- Moon theMoon;
- Earth(float d, float x) {
- this.d = d;
- this.x = x;
- theMoon = new Moon (0.3 * d, 30);
- }
- void drawFigure() {
- fill(216, 86, 84);
- ellipse(x + 240, y + 240, d, d);
- theMoon.drawFigure();
- }
- void move(float x, float y) {
- theMoon.move(x, y);
- theta += 1;
- radEarth = radians(theta);
- this.x = orbitRadius * cos(radEarth);
- this.y = -orbitRadius * sin(radEarth);
- }
- }
- class Moon {
- float d;
- float x;
- float y;
- float x1;
- float y1;
- float x2;
- float y2;
- float radMoon;
- float orbitRadius = 30;
- Moon(float d, float x) {
- this.d = d;
- this.x = x;
- }
- void drawFigure() {
- fill(50, 69, 61);
- ellipse(x, y, d, d);
- }
- void move(float x, float y) {
- dTheta += 2;
- radMoon = radians(dTheta);
- this.x = x + orbitRadius * cos(radMoon);
- this.y = x - orbitRadius * sin(radMoon);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement