function main() {
// Define player object and statistics
var player = {};
player.life = 61;
player.defense = 45;
player.agility = 33;
player.intellect = 69;
player.power = 42;
// Array that takes information from the player object to get the order
// in which stats are displayed onscreen. Change the order in which
// the player stats are defined to change order.
var statOrder = [];
for (var i in player) statOrder.push(i);
// Define colors. I used simple three-digit hex colors, in this case.
var statColors = {};
statColors.life = "#339933";
statColors.defense = "#333399";
statColors.agility = "#999933";
statColors.intellect = "#993399";
statColors.power = "#993333";
// Define pentagon (or other polygon) size and coordinates.
var polygonX = 240;
var polygonY = 240;
var polygonSize = 120;
// Define size of circles.
var circleSize = 56;
var circles = [];
var circleIndexes = [];
for (var i in statColors) circleIndexes.push({
defaultColor: statColors[i],
color: statColors[i],
over: false
});
var innerPolygonColor = statColors.life;
var innerPolygonKnobs = [];
for (var i in statColors) innerPolygonKnobs.push({
over: false
});
// Function for adding elements to screen. Code is reusable.
function appendElement(type, properties, parent) {
if (parent === undefined) parent = document.body;
var element = document.createElement(type);
for (var i in properties) {
element.setAttribute(i, properties[i]);
}
parent.appendChild(element);
return element;
}
// Place canvas object centered in the screen.
var canvas = appendElement("canvas", {
width: "480",
height: "480",
class: "absolute-center",
});
// Get canvas context.
var ctx = canvas.getContext("2d");
String.prototype.toRGB = function () {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.