-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created the first version of the Siteswap Analyzer
- Loading branch information
Showing
8 changed files
with
1,092 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,44 @@ | ||
# analysis | ||
# Siteswap Analyzer | ||
|
||
You can analyze siteswaps. | ||
If the siteswap is valid, the number of balls, the period, and the state are displayed respectively. | ||
You can also demonstrate using JuggleMaster JavaScript. | ||
|
||
# File list | ||
|
||
<dl> | ||
<dt>index.html</dt> | ||
<dd>This is the main page for the Siteswap Analyzer.</dd> | ||
<dt>default.css</dt> | ||
<dd>The style sheet for the main page.</dd> | ||
<dt>siteswap.js</dt> | ||
<dd>The classes of the grammar, parser, syntax tree, and siteswap validator.</dd> | ||
<dt>controller.js</dt> | ||
<dd>This is a controller that receives the input of the main page and outputs the analysis result.</dd> | ||
<dt>test.html</dt> | ||
<dd>This is a page for testing siteswap.js.</dd> | ||
<dt>test.css</dt> | ||
<dd>The style sheet for the test page.</dd> | ||
<dt>test.js</dt> | ||
<dd>This is a controller that receives the input of the test page and outputs the test result to the table.</dd> | ||
</dl> | ||
|
||
# Siteswap specifications by ABNF | ||
|
||
The followings are the specifications of the pattern of the siteswap to be accepted. | ||
|
||
```ABNF | ||
Pattern = Async / Synch | ||
Async = 1*EachHand | ||
EachHand = AsyncSimple / AsyncMulti | ||
AsyncSimple = Even / Odd | ||
Even = "0" / "2" / "4" / "6" / "8" / "a" / "c" / "e" / "g" / "i" / "k" / "m" / "o" / "q" / "s" / "u" / "w" / "y" | ||
Odd = "1" / "3" / "5" / "7" / "9" / "b" / "d" / "f" / "h" / "j" / "l" / "n" / "p" / "r" / "t" / "v" / "x" / "z" | ||
AsyncMulti = "[" 2*AsyncSimple "]" | ||
Synch = 1*BothHand ["*"] | ||
BothHand = "(" OneHand "," OneHand ")" | ||
OneHand = SynchSimple / SynchMulti | ||
SynchSimple = Even ["x"] | ||
SynchMulti = "[" 2*SynchSimple "]" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Controller class | ||
var Controller = function() { | ||
// fields | ||
this._prev = ""; | ||
this._parser = new Parser(Grammar); | ||
this._validator = new Validator(); | ||
|
||
// events | ||
window.addEventListener("load", this._initialize.bind(this), false); | ||
} | ||
|
||
// Controller prototype | ||
Controller.prototype = { | ||
|
||
// initialize the private fields | ||
"_initialize": function() { | ||
// DOM elements | ||
this._patternText = document.getElementById("pattern"); | ||
this._analyzeButton = document.getElementById("analyze"); | ||
this._startButton = document.getElementById("start"); | ||
this._stopButton = document.getElementById("stop"); | ||
this._resultArea = document.getElementById("result"); | ||
this._messageArea = document.getElementById("message"); | ||
|
||
// button events | ||
this._analyzeButton.addEventListener("click", this._analyze.bind(this), false); | ||
this._startButton.addEventListener("click", this._start.bind(this), false); | ||
this._stopButton.addEventListener("click", this._stop.bind(this), false); | ||
|
||
// JuggleMaster | ||
var board = document.getElementById("board"); | ||
board.width = board.clientWidth; | ||
board.height = board.width; | ||
this._jmj = new Jmj({ "canvas": board }); | ||
}, | ||
|
||
// "Analyze" button process | ||
"_analyze": function(e) { | ||
// initialize | ||
this._stop(e); | ||
this._prev = this._patternText.value; | ||
this._resultArea.innerHTML = ""; | ||
this._validator.reset(); | ||
|
||
// lexical and syntax analyze | ||
var result = this._parser.tokenize(this._prev); | ||
if (result.tokens == null) { | ||
this._setError("unknown character(s)", result.valid, result.invalid); | ||
return; | ||
} | ||
result = this._parser.parse(result.tokens); | ||
if (result.tree == null) { | ||
this._setError("syntax error", result.valid, result.invalid); | ||
return; | ||
} | ||
this._setResult(result.tree); | ||
}, | ||
|
||
// "Start" button process | ||
"_start": function(e) { | ||
// validate input text | ||
this._messageArea.innerHTML = ""; | ||
if (this._patternText.value != this._prev) { | ||
this._analyze(e); | ||
} | ||
if (this._validator.pattern == "") { | ||
return; | ||
} | ||
|
||
// start | ||
var obj = { "siteswap": this._validator.pattern, "showSiteswap": false }; | ||
if (!this._jmj.startJuggling(obj)) { | ||
this._messageArea.innerHTML = "JuggleMaster error"; | ||
this._messageArea.className = "error"; | ||
} | ||
}, | ||
|
||
// "Stop" button process | ||
"_stop": function(e) { | ||
this._jmj.stopJuggling(); | ||
}, | ||
|
||
// show the error string | ||
"_setError": function(title, valid, invalid) { | ||
// does the valid text exist? | ||
if (0 < valid.length) { | ||
valid = "OK : " + valid; | ||
invalid = "NG : " + invalid; | ||
} | ||
|
||
// write to the DOM elements | ||
var head = document.createElement("div"); | ||
var ok = document.createElement("div"); | ||
var ng = document.createElement("div"); | ||
head.innerHTML = title; | ||
head.className = "error"; | ||
ok.innerHTML = valid; | ||
ng.innerHTML = invalid; | ||
ng.className = "error"; | ||
this._resultArea.appendChild(head); | ||
this._resultArea.appendChild(ok); | ||
this._resultArea.appendChild(ng); | ||
}, | ||
|
||
// show the result string | ||
"_setResult": function(tree) { | ||
var head = document.createElement("div"); | ||
this._resultArea.appendChild(head); | ||
|
||
// get the result | ||
this._validator.validate(tree); | ||
if (!this._validator.valid) { | ||
// not a siteswap | ||
head.innerHTML = "Invalid"; | ||
head.className = "error"; | ||
return; | ||
} | ||
|
||
// siteswap | ||
head.innerHTML = "Valid"; | ||
var balls = document.createElement("div"); | ||
var period = document.createElement("div"); | ||
var state = document.createElement("div"); | ||
balls.innerHTML = "balls : " + this._validator.balls; | ||
period.innerHTML = "period : " + this._validator.period; | ||
state.innerHTML = "state : " + this._validator.state.join(" "); | ||
this._resultArea.appendChild(balls); | ||
this._resultArea.appendChild(period); | ||
this._resultArea.appendChild(state); | ||
}, | ||
|
||
} | ||
|
||
// start the controller | ||
new Controller(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
@charset "utf-8"; | ||
|
||
input { | ||
width: 90%; | ||
} | ||
|
||
input[type="button"] { | ||
margin-top: 2ex; | ||
} | ||
|
||
canvas { | ||
border: 1px solid gray; | ||
width: 90%; | ||
} | ||
|
||
.table .row { | ||
margin-bottom: 2ex; | ||
} | ||
|
||
.error { | ||
color: red; | ||
} | ||
|
||
@media (min-width: 768px) { | ||
|
||
#pattern { | ||
width: 300px; | ||
} | ||
|
||
input[type="button"] { | ||
margin-top: 0ex; | ||
width: auto; | ||
} | ||
|
||
canvas { | ||
width: 300px; | ||
} | ||
|
||
.table { | ||
display: table; | ||
} | ||
|
||
.table .row { | ||
display: table-row; | ||
} | ||
|
||
.table .row .cell { | ||
display: table-cell; | ||
padding: 0.5ex 2ex 0.5ex 0ex; | ||
vertical-align: middle; | ||
} | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width,initial-scale=1"> | ||
<link rel="stylesheet" type="text/css" href="./default.css"> | ||
<script src="https://yuji-k64613.github.io/jmjs/tmp/v/0.1/js/jmjs.js"></script> | ||
<script src="./siteswap.js"></script> | ||
<script src="./controller.js"></script> | ||
<title>Siteswap Analyzer</title> | ||
</head> | ||
|
||
<body> | ||
<article> | ||
<h1>Siteswap Analyzer</h1> | ||
|
||
<div class="table"> | ||
<div class="row"> | ||
<div class="cell"><label for="pattern">Pattern</label></div> | ||
<div class="cell"><input type="text" id="pattern"></div> | ||
<div class="cell"><input type="button" id="analyze" value="Analyze"></div> | ||
</div> | ||
<div class="row"> | ||
<div class="cell">Result</div> | ||
<div class="cell" id="result"> </div> | ||
</div> | ||
<div class="row"> | ||
<div class="cell">Demonstration</div> | ||
<div class="cell"><canvas id="board"></canvas></div> | ||
<div class="cell"><input type="button" id="start" value="Start"></div> | ||
<div class="cell"><input type="button" id="stop" value="Stop"></div> | ||
</div> | ||
<div class="row"> | ||
<div class="cell"> </div> | ||
<div class="cell" id="message"> </div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<small>JuggleMaster JavaScript Ver1.4.1 © 2013-2020 Yuji Konishi.</small> | ||
</div> | ||
|
||
</article> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.