Drkcore

24 08 2010 Flask Processing.js Tweet

Flaskでprocessing.jsを使う

staticディレクトリにprocessing.jsを置いて

from flask import Flask

app = Flask(__name__)

@app.route("/")
def processing():
    response = """
<html>
<head>
<title>Processing Sample</title>
<style  type="text/css">
body {margin:0; padding:0;}
</style>
<script type="text/javascript" src="static/processing-0.9.7.js"></script>
<script type="text/javascript">
window.onload = function() {
  var canvas = document.getElementsByTagName('canvas')[0];
  var codeElm = document.getElementById('processing-code');
  var code = codeElm.textContent || codeElm.innerText;
  Processing(canvas, code);
};
</script>
<script id="processing-code" type="application/processing">
void setup()
{
  size(window.innerWidth, window.innerHeight);
  background(102);
  smooth();
}

void draw() {
if (mousePressed == true) {
    variableEllipse(mouseX, mouseY, pmouseX, pmouseY);
    }
}

void variableEllipse(int x, int y, int px, int py)
{
  float speed = abs(x-px) + abs(y-py);
  stroke(speed);
  fill(random(0,255),random(0,255),random(0,255))
  ellipse(x, y, speed, speed);

}
</script>
</head>
<body>
<div>
<canvas width="400" height="400"></canvas>
</div>
</body>
"""
    return response

if __name__ == "__main__":
    app.run()

processing.js

参考

  • ブラウザでお絵描きプログラミング!
  • processing - Drkcore

ProductName Built with Processing[Ver. 1.x対応版] -デザイン/アートのためのプログラミング入門
田中 孝太郎,前川 峻志
ビー・エヌ・エヌ新社 / ¥ 2,940 ()
在庫あり。

About

  • もう5年目(wishlistありマス♡)
  • 最近はPythonとDeepLearning
  • 日本酒自粛中
  • ドラムンベースからミニマルまで
  • ポケモンGOゆるめ

Tag

Python Deep Learning javascript chemoinformatics Emacs sake and more...

Ad

© kzfm 2003-2021