프로세싱 태양계 |
|||||
---|---|---|---|---|---|
작성자 | 김용남 | 등록일 | 19.08.29 | 조회수 | 146 |
Planet[] myPlanet = new Planet[0]; void setup() { size(1000, 1000, P3D); Planet p1 = new Planet(25, 50, random(2*PI), 0.045); myPlanet = (Planet[])append(myPlanet, p1); Planet p2 = new Planet(27, 80, random(2*PI), 0.035); myPlanet = (Planet[])append(myPlanet, p2); Planet p3 = new Planet(30, 140, random(2*PI), 0.04); myPlanet = (Planet[])append(myPlanet, p3); Planet p4 = new Planet(26, 200, random(2*PI), 0.032); myPlanet = (Planet[])append(myPlanet, p4); Planet p5 = new Planet(60, 250, random(2*PI), 0.025); myPlanet = (Planet[])append(myPlanet, p5); Planet p6 = new Planet(35, 300, random(2*PI), 0.03); myPlanet = (Planet[])append(myPlanet, p6); Planet p7 = new Planet(33, 340, random(2*PI), 0.022); myPlanet = (Planet[])append(myPlanet, p7); Planet p8 = new Planet(28, 380, random(2*PI), 0.015); myPlanet = (Planet[])append(myPlanet, p8); Planet moon = new Planet(15, 40, random(2*PI), 0.036); myPlanet = (Planet[])append(myPlanet, moon); } void draw() { background(255); translate(width/2, height/2); noStroke(); fill(255, 0, 0); circle(0, 0, 50); rotateX(PI/3); for (int i=0; i<8; i++) { pushMatrix(); //myPlanet[i].orbit(); myPlanet[i].c(); myPlanet[i].display(); if (i==2) { myPlanet[8].moon(); //myPlanet[8].orbit(); myPlanet[8].c=myPlanet[i].c; myPlanet[8].display(); } popMatrix(); } } class Planet { float rad; float reach; float theta; float speed; float c; Planet(float tempRad, float tempR, float tempTheta, float tempSpeed) { rad = tempRad; reach = tempR; theta = tempTheta; speed = tempSpeed; } void moon() { rotateX(PI/3); } void orbit() { noFill(); stroke(0); circle(0, 0, 2*reach); } void c() { if (theta<PI){ c = map(theta, 0, PI, 0, 200); } else { c = map(theta, PI, 2*PI, 200, 0); } } void display() { rotateZ(theta); translate(0, reach); rotateZ(-theta); rotateX(-PI/3); fill(c); stroke(255); circle(0, 0, rad); theta += speed; theta %= 2*PI; } }
|
이전글 | 프로세싱 따라다니는 점 |
---|---|
다음글 | 파노라마 합성2 |