Commits

Anonymous committed 990ff51

scan files to generate the pjslist. add overflow:hidden for a better popup window

Comments (0)

Files changed (5)

 # store configs
 
-PJS_LIST = [
-    "example",
-    ]
 #!/usr/bin/env python
 import bottle
+import os
 from bottle import view, run, route, static_file
-from config import PJS_LIST
 from werkzeug.debug import DebuggedApplication
+
 #TODO change root to absolute dir because scirpt is run in
 #     other places
 
 @route('/')
 @view('index')
 def index():
-    return dict(pjslist=PJS_LIST)
+    # scan dir to seek pjs
+    pjslist = [name.split('.')[0] for name in os.listdir('./pjs')\
+               if not name.startswith('.')]
+    return dict(pjslist=pjslist)
 
 @route('/canvas/:iname')
 @view('canvas')
+// Processingjs first try
+int barWidth = 2;
+int [] hueArr;
+boolean needUpdate = true;
+
+void setup() {
+    size(320, 480);
+    colorMode(HSB, width, 100, 100);
+    hueArr = new int[width/barWidth];
+    // init with rainbow hue~
+    for (int ix = 0; ix < hueArr.length; ++ix) {
+        hueArr[ix] = ix * barWidth;
+    }
+}
+
+void draw() {
+    // draw to hue array
+    if (needUpdate) {
+        needUpdate = false;
+        noStroke(); 
+        for (int ix = 0; ix < hueArr.length; ++ix) {
+           fill(hueArr[ix], 100, 100);
+           rect(ix*barWidth, 0, barWidth, height);
+        }
+    }
+    // update
+}
+
+void drawOnce() {
+    
+}

templates/canvas.html

   <link rel="stylesheet" type="text/css" href="../static/default.css" />
   <script src="../static/processing-1.0.0.js"></script>
 </head>
-<body>
-  <canvas data-processing-sources="../pjs/{{ name }}.pjs" width="320" height="480"></canvas>
+<body style="overflow: hidden">
+  <canvas data-processing-sources="../pjs/{{ name }}.pjs" width="320" height="480" style="margin: auto auto"></canvas>
 </body>
 

templates/index.html

   <ul>
     % for item in pjslist:
     <li>
-    <a href="javascript:void(0)" onclick="window.open('./canvas/{{ item }}', 'skr','width=321, height=481, menubar=no, status=no, scrollbars=no') ">{{ item }}</a>
+    <a href="javascript:void(0)" onclick="window.open('./canvas/{{ item }}', 'skr','width=320, height=480, menubar=no, status=no, scrollbars=no') ">{{ item }}</a>
     </li>
     % end
   </ul>