Skip to content
This repository has been archived by the owner on Jun 10, 2021. It is now read-only.

Commit

Permalink
A few updates
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystalVulpine committed Aug 23, 2020
1 parent 396059a commit 80dc4ea
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 205 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ The political triangle test is an improvement upon the political compass. Instea

Take the test here: https://crystalvulpine.github.io/PoliticalTriangle/

[![Website](https://img.shields.io/website/https/crystalvulpine.github.io/PoliticalTriangle?down_color=red&down_message=down&up_message=up)](https://crystalvulpine.github.io/PoliticalTriangle) ![GitHub language count](https://img.shields.io/github/languages/count/CrystalVulpine/PoliticalTriangle) ![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/CrystalVulpine/PoliticalTriangle)
[![Website](https://img.shields.io/website/https/crystalvulpine.github.io/PoliticalTriangle?down_color=red&down_message=down&up_message=up)](https://crystalvulpine.github.io/PoliticalTriangle)

**Screenshots:**

Expand Down
59 changes: 59 additions & 0 deletions assets/js/quiz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
function calculateScore() {

var questionCount = 11;

// questions with only moderate answers
var moderateAnswers = 4;

// questions with strong answers
var strongAnswers = 7;

var moderateWeight = 1.0;
var strongWeight = 2.0;

// adds the submitted answers to the results URL, useful for feedback from test takers
var answers = '';
var right = 0.0;
var left = 0.0;
var lib = 0.0;

for (let q = 1; q <= questionCount; q++) {

let s = document.getElementById("s" + q);

if (s.options[s.selectedIndex].value === "Neutral") {
answers += 'n';
} else if (s.options[s.selectedIndex].value === "Left1") {
left += moderateWeight;
answers += 'l1';
} else if (s.options[s.selectedIndex].value === "Left2") {
left += strongWeight;
answers += 'l2';
} else if (s.options[s.selectedIndex].value === "Lib1") {
lib += moderateWeight;
answers += 'i1';
} else if (s.options[s.selectedIndex].value === "Lib2") {
lib += strongWeight;
answers += 'i2';
} else if (s.options[s.selectedIndex].value === "Right1") {
right += moderateWeight;
answers += 'r1';
} else if (s.options[s.selectedIndex].value === "Right2") {
right += strongWeight;
answers += 'r2';
}
}

// divide by the points in total for each axis (sum of the max amount of points for each question)
right /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight);
left /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight);
lib /= (moderateAnswers * moderateWeight) + (strongAnswers * strongWeight);

// convert to a number between 0 and 10 rounded to the nearest hundredth
right = Math.round(right * 1000) / 100;
left = Math.round(left * 1000) / 100;
lib = Math.round(lib * 1000) / 100;

window.location.href = "results.html?left=" + left + "&right=" + right + "&lib=" + lib + "&answers=" + answers;

}
61 changes: 61 additions & 0 deletions assets/js/results.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
function drawResults() {

let parser = document.createElement('a');
parser.href = window.location.href;
let vars = parser.search.substring(1).split('&');
for (let i = 0; i < vars.length; i++) {
let thevar = vars[i].split('=');
if (thevar[0] === "left") {
document.getElementById("left-score").innerHTML = parseFloat(thevar[1]);
var left = parseFloat(thevar[1]) / 10;
}
if (thevar[0] === "right") {
document.getElementById("right-score").innerHTML = parseFloat(thevar[1]);
var right = parseFloat(thevar[1]) / 10;
}
if (thevar[0] === "lib") {
document.getElementById("lib-score").innerHTML = parseFloat(thevar[1]);
var lib = parseFloat(thevar[1]) / 10;
}
}

let canvas = document.getElementById("canvas").getContext('2d');

// stops the edge of the canvas from cutting off parts of the image
let shift = 15;

canvas.lineWidth = 2;
canvas.beginPath();
canvas.moveTo(180 + shift, 311.769 + shift);
canvas.lineTo(360 + shift, 415.692 + shift);
canvas.lineTo(540 + shift, 311.769 + shift);
canvas.lineTo(360 + shift, 0 + shift);
canvas.lineTo(180 + shift, 311.769 + shift);
canvas.fillStyle = '#ffeeaa';
canvas.fill();
canvas.stroke();
canvas.beginPath();
canvas.moveTo(180 + shift, 311.769 + shift);
canvas.lineTo(360 + shift, 415.692 + shift);
canvas.lineTo(360 + shift, 623.538 + shift);
canvas.lineTo(0 + shift, 623.538 + shift);
canvas.lineTo(180 + shift, 311.769 + shift);
canvas.fillStyle = '#ffaaaa';
canvas.fill();
canvas.stroke();
canvas.beginPath();
canvas.moveTo(360 + shift, 415.692 + shift);
canvas.lineTo(540 + shift, 311.769 + shift);
canvas.lineTo(720 + shift, 623.538 + shift);
canvas.lineTo(360+ shift, 623.538 + shift);
canvas.lineTo(360 + shift, 415.692 + shift);
canvas.fillStyle = '#aaeeff';
canvas.fill();
canvas.stroke();

canvas.beginPath();
canvas.arc(360 - (left * 360) + (right * 360) + shift, 415.692 + (left * 207.846) + (right * 207.846) - (lib * 415.692) + shift, 12, 0, Math.PI * 2);
canvas.fillStyle = 'red';
canvas.fill();
canvas.stroke();
}
Loading

0 comments on commit 80dc4ea

Please sign in to comment.