Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="object sun">
</div>
<div class="trajectory trajectory-venus"></div>
<div class="object venus">
    <div></div>
</div>
<div class="trajectory trajectory-earth"></div>
<div class="object earth">
    <div></div>
</div>
<div class="trajectory trajectory-mars"></div>
<div class="object mars">
    <div></div>
</div>
              
            
!

CSS

              
                html,
body {
    height: 100%;
}

body {
    margin: 0;
    background-color: #000;
}


body > div {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* // As the title says, this is a hangover sunday project, I know this css can be optimized a lot (or atleast im sure it could be) */

:root {
    --earth-orbit: 20s;
    --earth-size: 10px;
    --venus-orbit: calc(var(--earth-orbit) * 0.6);
    --venus-size: calc(var(--earth-size) * 0.94);
    --mars-orbit: calc(var(--earth-orbit) * 2);
    --mars-size: calc(var(--earth-size) * 0.53);
}

.sun {
    height: 120px;
    width: 120px;
    border-radius: 50%;
    background-color: yellow;
}

.venus {
    height: 10px;
    width: 260px;
    transform-origin: center;
    animation: rotate infinite var(--venus-orbit) linear;
}

.venus > div {
    height: 10px;
    width: 10px;
    border-radius: 50%;
    background-image: linear-gradient(90deg, black 50%, rgb(241, 208, 59));
}

.earth {
    height: 20px;
    width: 420px;
    transform-origin: center;
    animation: rotate infinite var(--earth-orbit) linear;
}

.earth > div {
    height: 20px;
    width: 20px;
    border-radius: 50%;
    background-image: linear-gradient(90deg, black 50%, rgb(70, 138, 255));
}

.mars {
    height: 40px;
    width: 640px;
    transform-origin: center;
    animation: rotate infinite var(--mars-orbit) linear;
}

.mars > div {
    height: 40px;
    width: 40px;
    border-radius: 50%;
    background-image: linear-gradient(90deg, black 50%, rgb(209, 121, 21));
}

.trajectory {
    border: 2px solid rgba(111, 111, 111, 0.5);
    border-radius: 50%;
}

.trajectory.trajectory-venus {
    height: calc(250px - 2px);
    width: calc(250px - 2px);
}

.trajectory.trajectory-earth {
    height: calc(400px - 2px);
    width: calc(400px - 2px);
}

.trajectory.trajectory-mars {
    height: calc(600px - 2px);
    width: calc(600px - 2px);
}

@keyframes rotate {
    from {
        transform: translate(-50%, -50%) rotate(0deg);
    }

    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

              
            
!

JS

              
                // set up canvas
const cvs = document.createElement('canvas');
const cw = cvs.width = window.innerWidth;
const ch = cvs.height = window.innerHeight;
document.body.appendChild(cvs);
const ctx = cvs.getContext('2d');
fillCanvas();


// set up variables
const sunR = 50;
const sunX = cw / 2;
const sunY = ch / 2;
const earthR = sunR * 0.05;
let earthX = sunX;
let earthY = sunY - 250;
let angle = 0;
const earthTrajectoryR = sunR * 5;
const earthTrajectoryX = sunX;
const earthTrajectoryY = sunY;


function animate() {
    requestAnimationFrame(animate);
    fillCanvas();
    drawSun();
    drawTrajectory();
    drawEarth();
    earthX += (4 + 1/3) * Math.cos(angle * Math.PI / 180);
    earthY += (4 + 1/3) * Math.sin(angle * Math.PI / 180);
    angle++;
}
animate();


function fillCanvas() {
    ctx.fillStyle = 'black';
    ctx.fillRect(0, 0, cw, ch);
}


function drawSun() {
    ctx.fillStyle = 'yellow';
    ctx.beginPath();
    ctx.arc(sunX, sunY, sunR, 0, 2 * Math.PI);
    ctx.fill();
}


function drawTrajectory() {
    ctx.strokeStyle = 'gray';
    ctx.lineWidth = 1;
    ctx.beginPath();
    ctx.arc(earthTrajectoryX, earthTrajectoryY, earthTrajectoryR, 0, 2 * Math.PI);
    ctx.stroke();
}


function drawEarth() {
    ctx.fillStyle = 'deepskyblue';
    ctx.beginPath();
    ctx.arc(earthX, earthY, earthR, 0, 2 * Math.PI);
    ctx.fill();
}


function testCircle() {
    ctx.beginPath();
    ctx.arc(100,75,50,0,2*Math.PI);
    ctx.stroke();
}

              
            
!
999px

Console