Compare commits

...

39 Commits

Author SHA1 Message Date
  edoardoo 129fa23fa8 cleaned around 9 years ago
  edoardoo 484161fd51 initial commit for release branch 9 years ago
  root ee5610a692 added a first elmeent of leaderboards collection 9 years ago
  edoardoo 6e14367855 fix: insert first leaderboard data 9 years ago
  edoardoo 50265b96d4 fix: insert first leaderboard data 9 years ago
  edoardoo 7f2492c020 fixed timestamp undefined, maybe 9 years ago
  edoardoo 357fdce325 fixed timestamp undefined, maybe 9 years ago
  edoardoo 4480d8feb8 added sync chart report server, removed mongodb folder from repo 9 years ago
  edoardoo 4642366e08 odd rows and json input on left 9 years ago
  edoardoo 5ae919c9d7 added score column on leader boards 9 years ago
  edoardoo 43acc73d41 corrected leaderboard bug 9 years ago
  edoardoo c65ba53518 now save on server 9 years ago
  edoardoo 88271fab2c fixed wrong row shift problem 9 years ago
  edoardoo 050644b02c added play/pause function 9 years ago
  edoardoo b31080139a fixed inverted y bug, odd/even rows 9 years ago
  edoardoo afe1a876c7 fix 9 years ago
  edoardoo 1027aa7046 initial commit 9 years ago
  edoardoo 148ec764a3 bigger font 9 years ago
  edoardoo c9df78338e fixed multiple object local json 9 years ago
  edoardoo 07869652b2 added local json input 9 years ago
  edoardoo 758568c033 undefined score fix 9 years ago
  edoardoo 23121ca1ff added keystroke arrows and strings on score and index rendered image 9 years ago
  edoardoo 77af021323 added score image, and fixed leaderbard menu zindex 9 years ago
  edoardoo 14ebfb1a5d fixed overflow on slide rendered images, maybe 9 years ago
  edoardoo 3da181d58d fixed overflow on slide rendered images 9 years ago
  edoardoo 6f2d6ddcba fixed max length of renderedImage 9 years ago
  edoardoo a67786faee added multiple honeycmob rendering, diahane 9 years ago
  edoardoo e69e7f5614 added update time and script for screenshot 9 years ago
  edoardoo 573b6e6a6a aligned with master and the mother fucking sample problems, beacuse: ce l'avete tutti 9 years ago
  edoardoo 66da973e02 leaderboard with alarm on new points 9 years ago
  edoardoo b7c4ac7c95 fix: client wasn't conneting if server is not restarted meanwhile 9 years ago
  edoardoo af91d6fb3c working live update through /show POST 9 years ago
  edoardoo 0bfcf47f33 added node 9 years ago
  edoardoo 41a2511a1d honeycomb working with marked cells 9 years ago
  edoardoo 88e1254fb7 fix: problem on multiple sessions 9 years ago
  edoardoo ef4956007c fix: client wasn't conneting if server is not restarted meanwhile 9 years ago
  edoardoo 140caf7b53 working live update through /show POST 9 years ago
  edoardoo 75a4006218 added node 9 years ago
  edoardoo 7c53f0d53b honeycomb working with marked cells 9 years ago
17 changed files with 371 additions and 2 deletions
Split View
  1. +2
    -0
      .gitignore
  2. +0
    -0
      index.html
  3. +23
    -0
      package.json
  4. BIN
      public/images/active.png
  5. BIN
      public/images/neutral.png
  6. BIN
      public/images/touched.png
  7. BIN
      public/images/unit.png
  8. +28
    -0
      public/index.html
  9. +17
    -0
      public/scripts/less.min.js
  10. +176
    -0
      public/scripts/renderer.js
  11. +12
    -0
      public/scripts/tools.js
  12. +7
    -0
      public/style/style.css.map
  13. +89
    -0
      public/style/style.less
  14. +1
    -0
      sample_problems/lilik.json
  15. +1
    -1
      sample_problems/problem_0.json
  16. +1
    -1
      sample_problems/problem_1.json
  17. +14
    -0
      server.js

+ 2
- 0
.gitignore View File

@ -0,0 +1,2 @@
node_modules/
mongodb/

+ 0
- 0
index.html View File


+ 23
- 0
package.json View File

@ -0,0 +1,23 @@
{
"name": "icfp2015",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"body-parser": "^1.13.3",
"cookie-parser": "^1.3.5",
"express": "^4.13.3",
"mongojs": "^1.2.1",
"socket.io": "^1.3.6"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://edoardoo@bitbucket.org/lilik/icfp2015.git"
},
"author": "",
"license": "ISC"
}

BIN
public/images/active.png View File

Before After
Width: 779  |  Height: 901  |  Size: 36 KiB

BIN
public/images/neutral.png View File

Before After
Width: 779  |  Height: 901  |  Size: 39 KiB

BIN
public/images/touched.png View File

Before After
Width: 779  |  Height: 901  |  Size: 29 KiB

BIN
public/images/unit.png View File

Before After
Width: 779  |  Height: 901  |  Size: 37 KiB

+ 28
- 0
public/index.html View File

@ -0,0 +1,28 @@
<!DOCTYPE html>
<html>
<head>
<title>Icfp 2015 visualizer</title>
<link rel="stylesheet/less" type="text/css" href="style/style.less" />
<script type="text/javascript" src="scripts/less.min.js"></script>
</head>
<body>
<div id="controlBar">
<div class="lefting">
<span>Index: </span><div id="index"></div>
<span>Score: </span><div id="score"></div>
</div>
<button onclick="slideBack()"><</button>
<button id="playSlide" data-intervalid="-1"onclick="slidePlay()">PLAY/PAUSE</button>
<button onclick="slideForward()">></button>
</div>
<div class="bottomRight"><input placeholder="Paste Json, visible only locally." type="text" id="sendHCJson"><button onclick="sendJson()">Send</button></div>
<section id="honeyComb">
</section>
<script type="text/javascript" src="scripts/tools.js"></script>
<script type="text/javascript" src="scripts/renderer.js"></script>
</body>
</html>

+ 17
- 0
public/scripts/less.min.js
File diff suppressed because it is too large
View File


+ 176
- 0
public/scripts/renderer.js View File

@ -0,0 +1,176 @@
var points = 0;
var totalRenders = 0;
var urlToImageMap = {};
function loadImageGroup(urls, onCompleteFunc) {
var numImagesNotYetLoaded = urls.length;
urlToImageMap = {};
var markLoaded = function() {
if (--numImagesNotYetLoaded == 0)
onCompleteFunc(urlToImageMap);
}
for (var i = 0; i < urls.length; i++) {
var img = new Image();
img.onload = markLoaded;
img.src = urls[i];
urlToImageMap[urls[i]] = img;
}
}
function prePopulate(honeyCells){
var honeyCells = JSON.parse(honeyCells);
var urls = [
'images/neutral.png',
'images/active.png',
'images/touched.png',
'images/unit.png',
];
document.getElementById("honeyComb").innerHTML="";
loadImageGroup(urls, function(urlToImageMap) {
//all are loaded. draw to canvas here
if( honeyCells.constructor === Array){
for (var i = 0; i < honeyCells.length; i++) {
populateHoneycomb( honeyCells[i], i );
};
}else{
populateHoneycomb( honeyCells , 0);
}
});
}
function populateHoneycomb( honeyCells , index){
var height = "innerHeight" in window
? window.innerHeight
: document.documentElement.offsetHeight;
var width = "innerWidth" in window
? window.innerWidth
: document.documentElement.offsetWidth;
var cellWidth = width/(honeyCells.width);
var cellHeigth = (cellWidth / Math.sqrt(3))*2;
var canvas = document.createElement("canvas");
canvas.id = "canvas_"+index;
canvas.width = (honeyCells.width+1)*cellWidth;
var heightDifference = 0;
for( var i = 0; i < honeyCells.height; i++){
heightDifference = ((cellHeigth-(cellHeigth/2))/2)*i;
}
canvas.height = honeyCells.height*cellHeigth - heightDifference;
document.getElementById("honeyComb").appendChild(canvas);
canvas.setAttribute("data-index", index);
if( typeof honeyCells.score == "undefined"){
honeyCells.score = 0;
}
canvas.setAttribute("data-score", honeyCells.score );
canvas.className += " canvasRendered";
if(index == 0){
canvas.className += " visible";
updateLabels(document.getElementById("canvas_0"));
}
var context = canvas.getContext('2d');
for (var i = 0; i < honeyCells.height; i++) {
var even = (i%2 == 0) ? true : false;
for (var j = 0; j < honeyCells.width; j++) {
var startx = (even) ? j*cellWidth : (j*cellWidth)+(cellWidth*0.5);
var starty = i*cellHeigth-((cellHeigth-(cellHeigth/2))/2)*i;
context.drawImage(urlToImageMap['images/neutral.png'], startx, starty , cellWidth, cellHeigth);
};
};
addDetails( honeyCells, cellWidth, cellHeigth, context );
}
function addDetails( honeyCells, cellWidth, cellHeigth, context ){
setFilled( honeyCells, honeyCells.filled, "active" , cellWidth, cellHeigth, context);
if(honeyCells.touched){
setFilled( honeyCells, honeyCells.touched, "touched" , cellWidth, cellHeigth, context);
}
if(honeyCells.unit){
setFilled( honeyCells, honeyCells.unit, "unit" , cellWidth, cellHeigth, context);
}
}
function setFilled( honeyCells, cellsToCheck, className, cellWidth, cellHeigth, context ){
// honeyCells = jsonExample;
for (var i = 0; i < cellsToCheck.length; i++) {
var x = cellsToCheck[i].x;
var y = cellsToCheck[i].y;
var even = ( y % 2 == 0 ) ? true : false;
var startx = (even) ? x*cellWidth : (x*cellWidth)+(cellWidth*0.5);
var starty = y*cellHeigth-((cellHeigth-(cellHeigth/2))/2)*y;
context.drawImage(urlToImageMap['images/'+className+'.png'], startx, starty , cellWidth, cellHeigth);
};
}
function slideBack(){
var actual = document.getElementById("honeyComb").getElementsByClassName("visible")[0];
var actualId = actual.id.split("_")[1];
if(actualId > 0){
actualId--;
actual.className = "canvasRendered";
document.getElementById("canvas_"+actualId).className += " visible";
}
updateLabels(document.getElementById("canvas_"+actualId));
}
function slideForward(){
var actual = document.getElementById("honeyComb").getElementsByClassName("visible")[0];
var actualId = actual.id.split("_")[1];
if(actualId < document.getElementsByClassName("canvasRendered").length - 1){
actualId++;
}else{
actualId = 0;
}
actual.className = " canvasRendered";
document.getElementById("canvas_"+actualId).className += " visible";
updateLabels(document.getElementById("canvas_"+actualId));
}
function updateLabels( e ){
document.getElementById("score").innerHTML = e.getAttribute("data-score");
document.getElementById("index").innerHTML = e.getAttribute("data-index");
}
function slidePlay(){
var play = document.getElementById("playSlide");
if( play.getAttribute("data-intervalId") == "-1"){
var intervalID = setInterval( function(){
slideForward();
}, 50);
play.setAttribute('data-intervalId', intervalID);
}else{
var intervalID = play.getAttribute("data-intervalId");
clearInterval( intervalID );
play.setAttribute('data-intervalId', "-1");
}
}
function sendJson(){
var query = document.getElementById("sendHCJson").value;
// socket.emit("jsonToParse", query);
prePopulate( query);
}

+ 12
- 0
public/scripts/tools.js View File

@ -0,0 +1,12 @@
function hasClass(el, cls) {
return el.className && new RegExp("(\\s|^)" + cls + "(\\s|$)").test(el.className);
}
function removeClass(ele,cls) {
if (hasClass(ele,cls)) {
var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
ele.className=ele.className.replace(reg,' ');
}
}
function removeId(id) {
return (elem=document.getElementById(id)).parentNode.removeChild(elem);
}

+ 7
- 0
public/style/style.css.map View File

@ -0,0 +1,7 @@
{
"version": 3,
"mappings": "AAiBA,UAAU;EACT,MAAM,EAAE,CAAC;EACT,OAAO,EAAE,CAAC;EACV,MAAM,EAAE,IAAI;EACZ,KAAK,EAAE,IAAI;;AAEZ,IAAI;EACH,gBAAgB,EAAE,IAAI;;AAEvB,IAAK;EACJ,KAAK,EAAE,IAAI;EACX,WAAW,EAAE,GAAG;EAChB,aAAa,EAAE,KAAK;EAEpB,6BAAK;IACJ,KAAK,EAAE,CAAC;IACR,aAAa,EAAE,qBAAyB;IACxC,WAAW,EAAE,sBAA+B;IAC5C,YAAY,EAAE,sBAA+B;EAE9C,YAAQ;IACP,KAAK,EAzBK,KAAK;IA0Bf,MAAM,EAxBK,UAAkB;IAyB7B,UAAU,EAAE,IAAI;EAEjB,YAAQ;IACP,KAAK,EAAE,CAAC;IACR,UAAU,EAAE,qBAAwB;IACpC,WAAW,EAAE,sBAA8B;IAC3C,YAAY,EAAE,sBAA8B;EAI5C,kBAAI;IAEH,mBAAmB,EAxCN,OAAO;EA2CrB,qBAAO;IACN,UAAU,EA5CG,OAAO;EA8CrB,qBAAO;IACN,gBAAgB,EA/CH,OAAO;EAkDtB,QAAK;IACJ,KAAK,EAAE,IAAI;IACX,aAAO;MACN,WAAW,EAAE,IAAgB",
"sources": ["style.scss"],
"names": [],
"file": "style.css"
}

+ 89
- 0
public/style/style.less View File

@ -0,0 +1,89 @@
@color: #efefef;
html, body{
margin: 0;
padding: 0;
height: auto;
width: 100%;
}
body{
background-color: #333;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
}
.transition{
-webkit-transition: all .5s ease-in-out; /* Android 2.1+, Chrome 1-25, iOS 3.2-6.1, Safari 3.2-6 */
transition: all .5s ease-in-out;
}
.bottomRight{
position: fixed;
left: 0;
bottom: 0;
z-index: 9999;
background: #666;
padding: 10px;
button{
margin-left: 10px;
margin-right: 10px;
}
input{
min-width: 200px;
}
}
#controlBar{
position: fixed;
top: 0;
width: 100%;
margin: 0 auto;
text-align: center;
z-index: 999;
// display: none;
&.visible{
display: block;
}
.lefting{
background: rgba(20,20,20, .5);
color: white;
float: left;
padding: 10px;
}
}
#honeyComb{
canvas{
position: absolute;
display: none;
height: 100%;
&.visible{
display: block;
}
}
}
.honeycombIndex{
position: fixed;
top: 0;
left: 0;
background-color: rgba(185, 5, 198, 0.29);
padding: 20px;
z-index: 999;
font-size: 50px;
}
.honeycombScore:extend(.honeycombIndex){
top: 120px;
background-color: rgba(175, 0, 198, 0.29);
}
.canvasRendered{
background-color: #333;
}

+ 1
- 0
sample_problems/lilik.json View File

@ -0,0 +1 @@
{"height":10,"width":20,"filled":[ {"x": 2, "y": 4 }],"unit":[ {"x": 2, "y": 4 }, {"x": 6, "y": 4 }, {"x": 8, "y": 4 }, {"x": 12, "y": 4 }, {"x": 14, "y": 4 }, {"x": 16, "y": 4 }, {"x": 2, "y": 5 }, {"x": 5, "y": 5 }, {"x": 8, "y": 5 }, {"x": 13, "y": 5 }, {"x": 15, "y": 5 }, {"x": 2, "y": 6 }, {"x": 6, "y": 6 }, {"x": 8, "y": 6 }, {"x": 12, "y": 6 }, {"x": 14, "y": 6 }, {"x": 15, "y": 6 }, {"x": 2, "y": 7 }, {"x": 5, "y": 7 }, {"x": 8, "y": 7 }, {"x": 11, "y": 7 }, {"x": 13, "y": 7 }, {"x": 15, "y": 7 }, {"x": 2, "y": 8 }, {"x": 3, "y": 8 }, {"x": 4, "y": 8 }, {"x": 6, "y": 8 }, {"x": 8, "y": 8 }, {"x": 9, "y": 8 }, {"x": 10, "y": 8 }, {"x": 12, "y": 8 }, {"x": 14, "y": 8 }, {"x": 16, "y": 8 } ],"sourceLength":100}

+ 1
- 1
sample_problems/problem_0.json View File

@ -1 +1 @@
{"height":10,"width":10,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":2,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":2,"y":0},{"x":0,"y":1},{"x":2,"y":2}],"pivot":{"x":1,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":2,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":2}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":0}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":1}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":2}}],"id":0,"filled":[],"sourceLength":100}
{"height":10,"width":10,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":2,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":2,"y":0},{"x":0,"y":1},{"x":2,"y":2}],"pivot":{"x":1,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":1,"y":0}},{"members":[{"x":0,"y":0},{"x":1,"y":0},{"x":2,"y":0}],"pivot":{"x":2,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":0}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":1}},{"members":[{"x":0,"y":0},{"x":0,"y":1},{"x":0,"y":2}],"pivot":{"x":0,"y":2}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":0}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":1}},{"members":[{"x":1,"y":0},{"x":0,"y":1},{"x":1,"y":2}],"pivot":{"x":1,"y":2}}],"id":0,"filled":[],"sourceLength":100}

+ 1
- 1
sample_problems/problem_1.json View File

@ -1 +1 @@
{"height":15,"width":15,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}}],"id":1,"filled":[{"x":2,"y":4},{"x":3,"y":4},{"x":4,"y":4},{"x":5,"y":4},{"x":6,"y":4},{"x":11,"y":4},{"x":2,"y":5},{"x":8,"y":5},{"x":11,"y":5},{"x":2,"y":6},{"x":11,"y":6},{"x":2,"y":7},{"x":3,"y":7},{"x":4,"y":7},{"x":8,"y":7},{"x":11,"y":7},{"x":2,"y":8},{"x":9,"y":8},{"x":11,"y":8},{"x":2,"y":9},{"x":8,"y":9},{"x":2,"y":10},{"x":3,"y":10},{"x":4,"y":10},{"x":5,"y":10},{"x":6,"y":10},{"x":9,"y":10},{"x":11,"y":10}],"sourceLength":100}
{"height":15,"width":15,"sourceSeeds":[0],"units":[{"members":[{"x":0,"y":0}],"pivot":{"x":0,"y":0}}],"id":1,"touched":[{"x":2,"y":4}],"filled":[{"x":2,"y":4},{"x":3,"y":4},{"x":4,"y":4},{"x":5,"y":4},{"x":6,"y":4},{"x":11,"y":4},{"x":2,"y":5},{"x":8,"y":5},{"x":11,"y":5},{"x":2,"y":6},{"x":11,"y":6},{"x":2,"y":7},{"x":3,"y":7},{"x":4,"y":7},{"x":8,"y":7},{"x":11,"y":7},{"x":2,"y":8},{"x":9,"y":8},{"x":11,"y":8},{"x":2,"y":9},{"x":8,"y":9},{"x":2,"y":10},{"x":3,"y":10},{"x":4,"y":10},{"x":5,"y":10},{"x":6,"y":10},{"x":9,"y":10},{"x":11,"y":10}],"sourceLength":100}

+ 14
- 0
server.js View File

@ -0,0 +1,14 @@
var express = require('express'),
http = require('http');
var app = express();
app.use(express.static('./public'));
var server = http.createServer(app).listen(8080);
console.log("Listening on port 8080");
console.log("Visit http://localhost:8080 please.");

Loading…
Cancel
Save