Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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

              
                <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<body id="mainbody">		
    <header id="mainheader">
        <div class="box-with-text">
            <div class="text-fill">
                <div class="splash-container" id="mesh-container">
                    <canvas id="canvas" width="100%" height="100%" style="display:block;"></canvas>
                </div>
            </div>
        </div>
        <div class="subtitle-nice noselect wowAnimation"></div>
        <div class="instructions noselect">Use your mouse to follow a sunbeam and score!</div>
        <div class="instructions-bottom noselect"></div>
    </header>
</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Gloria+Hallelujah);

html,
body {
    font-family: 'Gloria Hallelujah';
    padding: 0;
    margin: 0;
    overflow:hidden;
}

#mainbody {
    width: 680px;
    height: 405px;
}

#mesh-container {
    width: 680px;
    height: 405px;
}

.canvas {
    margin: 0 auto;
    width: 680px;
    height: 405px;
}

.subtitle-nice, .wowAnimation {
    color: #FFFFBB;
    text-align:center;
    position:absolute;
    left:44%;
    top: 20%;
    font-size: 3em;
}

#scoreContainer {
    position: absolute;
}

.noselect {
    cursor:default;
    -webkit-touch-callout: none; 
    -webkit-user-select: none;     -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;     }

.subtitle-score {	
	position: absolute;
	text-align: center;
	left: 46%;
	top: 44%;
	font-size: 2em;
	font-weight: 900;
    color: #FFFFBB;
	z-index: 9999;
	animation-timing-function:linear;
	animation-duration: .25s;
	animation-fill-mode: both;
	animation-iteration-count: 1;
	animation-name: fadeIn;
}
@keyframes fadeIn {
	0% {transform: translateY(0px); opacity: 0;}	
  	100% {transform: translateY(-2px); opacity: 1; }
}

@keyframes translateUpThenFadeOut {
	0% {transform: translateY(0px); opacity: 0;}
	10% { opacity: 1;}
	50% { opacity: 1;}
  	100% {transform: translateY(-40px); opacity: 0; }
}

.wowAnimation {
	animation-timing-function:linear;
	animation-duration: 2s;
	animation-fill-mode: both;
	animation-iteration-count: 1;
	animation-name: translateUpThenFadeOut;
}

.instructions {
    color: black;
    text-align:center;
    position:absolute;
    width:95%;
    margin: 0 auto;
    top: 3%;
    font-size: 1.4em;
    z-index:6;
}

.instructions-bottom {
    color: black;
    text-align:center;
    position:absolute;
    width:95%;
    margin: 0 auto;
    bottom: 3%;
    font-size: 1.4em;
    z-index:6;
}
              
            
!

JS

              
                var can = document.getElementById('canvas');
con = can.getContext('2d');
var DRAW_SPEED = 30;
var WHEEL_SPEED = 120;
var offsetLastSet = -1;

var score = 0;
var wowText = "Wow!";

var canvasPosition = $(can).offset();
var scrollPos = $(window)[0].scrollY;

var circleCenterX = .5;
var circleCenterY = .5;

var wheelColor_01 = 'rgb(039,083,086)';
var wheelColor_02 = 'rgb(071,130,135)';

function wedge(id, startX, startY, width, height, offset, context, color) {
    this.id = id;

    this.context = context;
    this.color = color;
    this.colorWithFlash = '#FFFFFF';

    this.setFlash = false;
    this.flashTimer = 0;
    this.flashR = 255;
    this.flashG = 255;
    this.flashB = 255;

    this.addR = true;
    this.addG = true;
    this.addB = false;

    this.startX = startX;
    this.startY = startY;
    this.width = width;
    this.height = height;
    this.offset = offset;

    this.offsetComboTimer = 0;

    this.p1 = [startX, startY];
    this.p2 = [startX + width, startY];
    this.p3 = [startX + width - offset, startY + height];
    this.p4 = [startX - offset, startY + height];
}
wedge.prototype.updateme = function() {
    var red = this.color.slice(4, 7);
    var green = this.color.slice(8, 11);
    var blue = this.color.slice(12, 15);

    this.addR = setAddOrSubColor(this.addR, red, 75, 250);
    this.addG = setAddOrSubColor(this.addG, green, 75, 250);
    this.addB = setAddOrSubColor(this.addB, blue, 75, 250);

    red = updateColor(red, this.addR, 1);
    blue = updateColor(blue, this.addB, 2);
    green = updateColor(green, this.addG, 3);

    if (this.setFlash) {
        this.flashTimer = 60;
        this.flashR = 255;
        this.flashG = 255;
        this.flashB = 215;
    }

    this.flashR = updateFlashColor(this.flashR, red);
    this.flashG = updateFlashColor(this.flashG, green);
    this.flashB = updateFlashColor(this.flashB, blue);

    red = parseNumberToColor(red);
    blue = parseNumberToColor(blue);
    green = parseNumberToColor(green);
    this.color = "rgb(" + red + "," + green + "," + blue + ")";

    var flashR = parseNumberToColor(this.flashR);
    var flashG = parseNumberToColor(this.flashG);
    var flashB = parseNumberToColor(this.flashB);
    this.flashColor = "rgb(" + flashR + "," + flashG + "," + flashB + ")";

    this.p1[0] = this.startX;
    this.p1[1] = this.startY;
    this.offset = timer / WHEEL_SPEED;

    if (this.offsetComboTimer < 0) {
        if (offsetLastSet == this.id) {
            showWow();
            DRAW_SPEED -= 3;
            clearInterval(drawInterval);
            drawInterval = setInterval(draw, DRAW_SPEED);
            this.offsetComboTimer = WHEEL_SPEED;
        }
    }

    if (this.flashTimer > 0) {
        this.flashTimer--;
    }
}
wedge.prototype.drawme = function() {
    this.context.fillStyle = this.color;
    if (this.flashTimer > 0) {
        this.context.fillStyle = this.flashColor;
    }
    this.context.beginPath();
    this.context.moveTo(this.p1[0], this.p1[1]);
    this.context.arc(this.p1[0], this.p1[1], this.height, this.id * this.width + this.offset, (this.id * this.width) + this.width + this.offset);
    this.context.lineTo(this.p1[0], this.p1[1]);
    if (this.context.isPointInPath(mouseX - canvasPosition.left, mouseY - canvasPosition.top + scrollPos) == true) {
        this.setFlash = true;
        if (offsetLastSet != this.id) {
            offsetLastSet = this.id;
            this.offsetComboTimer = WHEEL_SPEED;
        } else {
            this.offsetComboTimer--;
        }
    } else {
        this.setFlash = false;
    }
    this.context.closePath();
    this.context.fill();
}

function showWow() {
    score++;
    if (score == 1) {
        $(".instructions-bottom").html("Cool! You can play on my website's header too!");
        $(".instructions").html("");
    }
    if (score < 5) {
        wowText = "Nice!";
    } else if (score < 10) {
        wowText = "Wow!";
    } else if (score < 20) {
        wowText = "OMG!";
    } else if (score >= 20) {
        wowText = "WTF?!";
    }
    $("#mainheader").append('<div class="subtitle-nice noselect wowAnimation">' + wowText + '</div>');
    setTimeout(removeTempElement, 1300);
    if ($('#scoreContainer').length == 0) {
        $("#mainheader").append('<div id="scoreContainer" class="subtitle-score noselect">+1</div>');
    } else {
        $("#scoreContainer").first().html("+" + score);
    }
}

function removeTempElement() {
    $("#mainheader").find(".wowAnimation").first().remove();
}

function setAddOrSubColor(current, color, min, max) {
    if (parseInt(color) >= max)
        return false;
    else if (parseInt(color) <= min)
        return true;
    return current;
}

function parseNumberToColor(color) {
    color = Math.min(color, 255);

    if (color < 10) {
        color = "00" + color.toString();
    } else if (color < 100) {
        color = "0" + color.toString();
    } else {
        color = color.toString();
    }
    return color;
}

function updateColor(color, add, speed) {
    color = parseInt(color);

    if (timer % speed == 0) {
        if (add)
            color++;
        else
            color--;
    }
    return color;
}

function updateFlashColor(flashColor, color) {
    if (flashColor > 0) {
        flashColor -= 15;
    }
    return Math.max(flashColor, color);
}

var circle = [];
var NUM_WEDGES = 16;
var timer = 0;
createCircle(NUM_WEDGES);

function createCircle(wedges) {
    var shapecolor;
    var centerX = $('#mesh-container').width() * circleCenterX;
    var centerY = $('#mesh-container').height() * circleCenterY;

    for (var i = 0; i < wedges; i++) {
        if (i % 2 == 0) {
            shapecolor = wheelColor_01;
        } else {
            shapecolor = wheelColor_02;
        }
        circle[i] = new wedge(i, centerX, centerY, (2 * Math.PI) / NUM_WEDGES, 1000, 50, con, shapecolor);
    }
}

function draw() {
    con.clearRect(0, 0, can.width, can.height);
    for (i = 0; i < NUM_WEDGES; i++) {
        circle[i].updateme();
        circle[i].drawme();
    }
    timer++;
}

function resizeCanvas() {
    can.width = $('#mesh-container').width();
    can.height = $('#mesh-container').height();
    canvasPosition = $(can).offset();

    for (var i = 0; i < NUM_WEDGES; i++) {
        circle[i].startX = can.width * circleCenterX;
        circle[i].startY = can.height * circleCenterY;
    }

    draw();
}

window.addEventListener('resize', resizeCanvas, false);
resizeCanvas();
var drawInterval = setInterval(draw, DRAW_SPEED);

var mouseX, mouseY, prevMouseX, prevMouseY;

$('#mainheader').mousemove(function(event) {
    prevMouseX = mouseX;
    prevMouseY = mouseY;
    mouseX = event.clientX;
    mouseY = event.clientY;
});
              
            
!
999px

Console