Skip to content

Commit

Permalink
refactor, docs, and first demo
Browse files Browse the repository at this point in the history
  • Loading branch information
williamngan committed Jun 17, 2017
1 parent 8674fc0 commit e9a692d
Show file tree
Hide file tree
Showing 62 changed files with 16,143 additions and 3,837 deletions.
224 changes: 224 additions & 0 deletions demo/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
body {
background: #fff;
font-family: "Helvetica", sans-serif;
font-size: 10px;
line-height: 1.35;
}
html {
overflow-x: hidden;
overflow-y: auto;
}

html * {
box-sizing: border-box;
}

#board {
position: absolute;
left: 0; top: 0; bottom: 0; right: 50%;
overflow: hidden;
cursor: pointer;
}

#pt {
position: relative;
width: 100%;
height: 100%;
overflow: hidden;
}

#page {
position: absolute;
right: 0; top: 0; bottom: 0; left: 50%;
overflow: auto;
padding: 0 10px 0 5vw;
background-color: #fff;
}
#page:before {
display: inline-block;
content: " ";
width: 0;
height: 100%;
vertical-align: middle;
background: transparent;
}

#cover {
display: inline-block;
vertical-align: middle;
width: 90%;
white-space: normal;
margin-bottom: 5vh;

-webkit-column-count: 3;
-moz-column-count: 3;
-ms-column-count: 3;
column-count: 3;

-webkit-column-gap: 50px;
-moz-column-gap: 50px;
-ms-column-gap: 50px;
column-gap: 50px;

text-overflow: ellipsis;
background: #fff;
}

#menu {
position: absolute;
top: 0; left: 0; right: 0;
padding-left: 5vw;
background-color: #fff;
z-index: 1;
}

#menu > span {
display: inline-block;
vertical-align: middle;
font-size: 1.2em;
padding-right: 30px;
margin-top: 20px;
font-family: "Roboto Slab", sans-serif;
}


#menu > span.title {
font-size: 4em;

}



#hint {
position: absolute;
bottom: 30px;
left: 5vw;
right: 5vw;

font-size: 12px; color: #666;
line-height: 1.35;
word-wrap: normal;
max-width: 350px;
}

#hint a {
border: none;
text-decoration: none;
color: #334fff;
}

#hint a:hover {
color: #4a11df;
}

h1 {
font-family: "Roboto Slab", sans-serif;
font-size: 8em;
color: #fff;
font-weight: 300;
margin: 0;
}

p {
font-size: 1.4em;
color: rgba(255,255,255,.8);
}

h3 {
font-weight: 400;
font-size: 1.4em;
color: #fff;
margin: 1em 0 2em 0.15em;
}

a {
color: #334fff;
font-weight: 500;
text-decoration: none;
display: inline-block;
}

a:hover {
border-bottom: 1px solid #334fff;
}

.demo, .section {
cursor: pointer;
font-size: 12px; line-height: 1.5; margin: 0;
color: #667;
white-space: nowrap;
}

.demo > span {
font-size: 10px;
}
.demo > strong {
font-weight: 400;
}
.demo:hover { color: #334fff;}

.section {
font-weight: 600;
color: #222;
}

@media only screen and (max-device-width : 800px) {
#board {
bottom: 40%;
left: 0; right: 0;
}

#hint {
bottom: auto; top: 30px; left: 30%;
max-width: 100%;
}

#menu {
background-color: transparent;
}

#menu span {
display: none;
}

#menu .title {
display: inline-block;
}

#cover {
display: block;
top: 22vh;
position: absolute;
}

#page {
top: 60%;
left: 0; right: 0;
}

}

@media only screen and (max-device-width : 600px) {
#cover {
-webkit-column-count: 2;
column-count: 2;
}

.demo {
padding: 3px 0;
}
}

@media only screen and (max-device-width : 320px) {
#cover {
top: 25vh;
}

}

@media (max-height: 500px) {
.demo, #hint {
font-size: 10px;
line-height: 1.2;
}
}
117 changes: 117 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
<link href='http://fonts.googleapis.com/css?family=Roboto+Slab:400,700,300' rel='stylesheet' type='text/css'>

<meta charset="UTF-8">
<script type="text/javascript" src="../dist/pts.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<!--<script type="text/javascript" src="../dist/core/pt-core.js"></script>-->
<!--<script type="text/javascript" src="../dist/extend/pt-extend.js"></script>-->

<link href="./css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">

function mobileAndTabletcheck() {
var check = false;
(function(a){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4)))check = true})(navigator.userAgent||navigator.vendor||window.opera);
return check;
}

function qs(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

var src = null;
var qfile = qs("name");
if (qfile) {
if (qfile.indexOf("/") >= 0 || qfile.split(".").length > 2 ) qfile="";

src = document.createElement('script');
src.setAttribute("type", "text/javascript");
src.setAttribute("id", "src");
src.setAttribute("src", "../demo/" + qfile + ".js");

var link = document.createElement("a");
link.setAttribute("href", "https://github.com/williamngan/pt/blob/master/demo/" + qfile +".js");
link.setAttribute("target", "_blank");
link.textContent = "(demo source code)";

src.onload = function () {
var hint = document.querySelector("#hint");
var arrow = (mobileAndTabletcheck()) ? "▲" : "◄";
hint.innerHTML = "";
hint.textContent = arrow + " " + (window.demoDescription || "") + " ";
hint.appendChild( link );
};
}

function screenshot(w, h) {
var demo = document.querySelector( "#pt > canvas" );
var img = document.createElement( "img" );
img.setAttribute( "style", "position: absolute; top: 90vh; left: 0; z-index:1000; width: " + w + "px; height: " + h + "px;" );
var page = document.querySelector( "#page" );
page.appendChild( img );
img.src = demo.toDataURL();
var qf = qfile.split( "." );
qf.pop();
return qf.join( "." ) + ".png";
}


</script>

</head>
<body>

<div id="page">

<div id="menu">
<span class="title"><a href="../index.html">Pts</a></span>
</div>

<div id="cover">

<p class="section">core demos</p>
<p class="section">&nbsp;</p>
<p class="demo" data-src="op.bisect"><span>op.</span><strong>bisect</strong></p>
<p class="demo" data-src="canvasspace.resize"><span>canvasspace.</span><strong>resize</strong></p>
</div>
<div id="hint"></div>
</div>


<div id="board">
<div id="pt"></div>


</div>


<script type="text/javascript">

if (src) document.querySelector("body").appendChild( src );

if (window.location.pathname.indexOf("index.html") < 0) {
window.location.href = window.location.origin+window.location.pathname+"index.html?name=color.LABtoRGB";
}

var demos = document.querySelectorAll(".demo");

for (var i=0; i<demos.length; i++) {
var file = demos[i].getAttribute("data-src");
demos[i].addEventListener("click", function() {
var sel = this.getAttribute("data-src");
window.location.href = window.location.origin+window.location.pathname+"?name="+sel;
}.bind( demos[i] ) );
}

</script>


</body>
</html>
36 changes: 36 additions & 0 deletions demo/op.bisect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Pts.scope( Pts, window );

var space = new CanvasSpace("#pt").setup({retina: true});
var form = space.getForm();
console.log( form );

var ratio = 0.5;

space.add( {
animate: (time, fps, ctx) => {

var center = space.size.$divide(2);
let a = [center, center.$subtract(100, 40)];
let b = [center, center.$subtract(-50, 200)];
let c = [center, center.$subtract(-100, -250)];

form.stroke("#f00").line( a );
form.stroke("#0f0").line( b );
form.stroke("#00f").line( c );

let p1 = Geom.bisect( a[1].$subtract(a[0]), b[1].$subtract(b[0]), ratio );
let p2 = Geom.bisect( b[1].$subtract(a[0]), c[1].$subtract(c[0]), ratio );
let p3 = Geom.bisect( c[1].$subtract(c[0]), a[1].$subtract(b[0]), ratio );

form.fill(false);
form.stroke("#333").line([center, center.$add(p1)] );
form.stroke("#999").line([center.$add(p1), center.$add(p2), center.$add(p3), center.$add(p1)] );

},
onMouseAction:( type, px, py) => {
ratio = Num.normalizeValue( px, 0, space.size.x)
}
})

space.bindMouse();
space.play();
Loading

0 comments on commit e9a692d

Please sign in to comment.