Permalink
Browse files

chippy demo

  • Loading branch information...
zot committed May 9, 2012
1 parent 0e63328 commit 8d97571588d3e74666a7a9204443eacafca1b7b6
Showing with 699 additions and 357 deletions.
  1. +9 −0 TODO.html
  2. +5 −0 TODO.md
  3. +11 −9 bootLeisure.cs
  4. +3 −12 bootLeisure.js
  5. +3 −1 build
  6. +21 −10 chippy.cs
  7. +39 −304 chippy.html
  8. +25 −10 chippy.js
  9. +295 −0 map.svg
  10. +274 −0 map2.svg
  11. +6 −5 notebook.cs
  12. +8 −6 notebook.js
View
@@ -27,6 +27,11 @@ <h1>BUGS</h1>
<h1>TODO</h1>
<ul>
+<li>chippy demo
+<ul>
+<li>pan/zoom</li>
+<li>Leisure-based mouse controls -- rotate rock with arrow keys</li>
+</ul></li>
<li>notebook
<ul>
<li>use file system api
@@ -38,6 +43,10 @@ <h1>TODO</h1>
<li>"save-as" saves the web page</li>
</ul></li>
<li>incremental compilation (automatically recompile and update all errors)</li>
+<li>function preconditions
+<ul>
+<li>"make precondition" button</li>
+</ul></li>
<li>run test cases button
<ul>
<li>checkbox to run all tests on successful auto-build</li>
View
@@ -6,6 +6,9 @@
* build should preserve outputs
# TODO
+* chippy demo
+ * pan/zoom
+ * Leisure-based mouse controls -- rotate rock with arrow keys
* notebook
* use file system api
* each webpage is a whole project and gets its own directory on the file system
@@ -14,6 +17,8 @@
* use FS for autosave
* "save-as" saves the web page
* incremental compilation (automatically recompile and update all errors)
+ * function preconditions
+ * "make precondition" button
* run test cases button
* checkbox to run all tests on successful auto-build
* auto build should clear tests on a recompile
View
@@ -6,15 +6,15 @@
bootLeisure = ->
body = document.body
- if (body.getAttribute 'leisurecode')?
- pre = document.createElement 'pre'
- pre.setAttribute 'leisurecode', ''
- pre.setAttribute 'contentEditable', 'true'
- pre.innerHTML = body.innerHTML
- while body.firstChild
- body.removeChild body.firstChild
- body.appendChild pre
- body.removeAttribute 'leisurecode'
+ # if (body.getAttribute 'leisurecode')?
+ # pre = document.createElement 'pre'
+ # pre.setAttribute 'leisurecode', ''
+ # pre.setAttribute 'contentEditable', 'true'
+ # pre.innerHTML = body.innerHTML
+ # while body.firstChild
+ # body.removeChild body.firstChild
+ # body.appendChild pre
+ # body.removeAttribute 'leisurecode'
window.removeEventListener 'load', bootLeisure
for i in ['leisure', 'gaudy', 'thin', 'cthulhu' ]
style = document.createElement('link')
@@ -25,7 +25,9 @@ body.appendChild pre
loadThen ['leisure', 'prim', 'pretty', 'replCore', 'browserRepl', 'std', 'notebook', 'jquery-1.7.2.min'], ->
Repl.init()
for node in document.querySelectorAll "[leisurecode]"
+ node.setAttribute 'contentEditable', 'true'
Notebook.bindNotebook node
+ Notebook.changeTheme node, 'thin'
Notebook.evalDoc node
loadThen = (files, cont, index)->
View
@@ -9,19 +9,8 @@
Leisure = {};
bootLeisure = function bootLeisure() {
- var body, i, pre, style, _i, _len, _ref;
+ var body, i, style, _i, _len, _ref;
body = document.body;
- if ((body.getAttribute('leisurecode')) != null) {
- pre = document.createElement('pre');
- pre.setAttribute('leisurecode', '');
- pre.setAttribute('contentEditable', 'true');
- pre.innerHTML = body.innerHTML;
- while (body.firstChild) {
- body.removeChild(body.firstChild);
- }
- body.appendChild(pre);
- body.removeAttribute('leisurecode');
- }
window.removeEventListener('load', bootLeisure);
_ref = ['leisure', 'gaudy', 'thin', 'cthulhu'];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -39,7 +28,9 @@
_results = [];
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
node = _ref2[_j];
+ node.setAttribute('contentEditable', 'true');
Notebook.bindNotebook(node);
+ Notebook.changeTheme(node, 'thin');
_results.push(Notebook.evalDoc(node));
}
return _results;
View
4 build
@@ -1,5 +1,7 @@
#!/bin/sh
-node_modules/coffee-script/bin/coffee -c leisure.cs prim.cs
+node_modules/coffee-script/bin/coffee -c leisure.cs prim.cs game.cs
node_modules/coffee-script/bin/coffee -c repl.cs runRepl.cs testLeisure.cs replCore.cs browserRepl.cs pretty.cs testing.cs bootLeisure.cs notebook.cs
node runRepl -q -c -b std
node testLeisure
+#node runRepl -q -c parseAst
+node_modules/coffee-script/bin/coffee -c chippy.cs
View
@@ -1,15 +1,16 @@
window.Chippy = root = {}
-snake = null
+doc = null
+boulder = null
space = null
v = cp.v
# this ties an SVG element to a Chipmunk shape and body
# if you want to reuse SVG shapes, use the "use" element
class PolyThing
constructor: (name, @mass)->
- @svg = document.getElementById(name)
- skel = document.getElementById "#{name}-skeleton"
+ @svg = doc.getElementById(name)
+ skel = doc.getElementById "#{name}-skeleton"
bbox = skel.getBBox()
@midx = bbox.x + bbox.width / 2
@midy = bbox.y + bbox.height / 2
@@ -30,7 +31,7 @@ class PolyThing
# if you want to reuse SVG shapes, use the "use" element
class GroundThing
constructor: (name)->
- skel = document.getElementById "#{name}-skeleton"
+ skel = doc.getElementById "#{name}-skeleton"
pts = (getPoints skel, 0, 0)
@body = space.staticBody
@body.setPos v(0, 0)
@@ -46,13 +47,14 @@ s.setElasticity e
for s in @shapes
s.setFriction f
-initChippy = ->
- space = new cp.Space();
+initChippy = (document)->
+ doc = document
+ space = new cp.Space()
space.gravity = v 0, 230
- snake = new PolyThing 'boulder', 200
- snake.setElasticity 1.2
- snake.setFriction 2
- snake.setAngVel 7
+ root.boulder = boulder = new PolyThing 'boulder', 200
+ boulder.setElasticity 1.4
+ boulder.setFriction 0.3
+ boulder.setAngVel 10
ground = new GroundThing 'ground'
ground.setElasticity 0.6
ground.setFriction 1
@@ -71,10 +73,17 @@ ground.setFriction 1
if crds.length == 2
lastx += Number(crds[0])
lasty += Number(crds[1])
+ # use unshift to make the widing right
pts.unshift lastx - midx, lasty - midy
console.log ""
pts
+svgTransform = (svg, x, y)->
+ if !pt? then pt = svg.createSVGPoint()
+ pt.x = x
+ pt.y = y
+ pt.matrixTransform(svg.getCTM())
+
lastStep = Date.now()
remainder = null
resized = true
@@ -120,3 +129,5 @@ ground.setFriction 1
root.initChippy = initChippy
root.run = run
+root.svgTransform = svgTransform
+root.boulder = boulder
Oops, something went wrong.

0 comments on commit 8d97571

Please sign in to comment.