summaryrefslogtreecommitdiffstats
path: root/examples/script/context2d/scripts/plasma.js
diff options
context:
space:
mode:
authorAlexis Menard <alexis.menard@nokia.com>2009-04-17 14:06:06 (GMT)
committerAlexis Menard <alexis.menard@nokia.com>2009-04-17 14:06:06 (GMT)
commitf15b8a83e2e51955776a3f07cb85ebfc342dd8ef (patch)
treec5dc684986051654898db11ce73e03b9fec8db99 /examples/script/context2d/scripts/plasma.js
downloadQt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.zip
Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.gz
Qt-f15b8a83e2e51955776a3f07cb85ebfc342dd8ef.tar.bz2
Initial import of statemachine branch from the old kinetic repository
Diffstat (limited to 'examples/script/context2d/scripts/plasma.js')
-rw-r--r--examples/script/context2d/scripts/plasma.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/examples/script/context2d/scripts/plasma.js b/examples/script/context2d/scripts/plasma.js
new file mode 100644
index 0000000..1aa9294
--- /dev/null
+++ b/examples/script/context2d/scripts/plasma.js
@@ -0,0 +1,58 @@
+var counter = 0;
+
+var PIXEL_SIZE = 4;
+
+var temp_1 = 0;
+
+function init()
+{
+ setInterval('render()',50);
+}
+
+function dist(a, b, c, d)
+{
+ return Math.sqrt((a - c) * (a - c) + (b - d) * (b - d));
+}
+
+
+function render()
+{
+ var canvas = document.getElementById('tutorial');
+ canvas.resize(128, 128);
+ var ctx = canvas.getContext('2d');
+ ctx.save();
+
+ var time = counter * 5;
+
+
+ for( y = 0; y < 128; y+=PIXEL_SIZE) {
+ for( x = 0 ; x < 128; x+=PIXEL_SIZE) {
+
+
+ var temp_val = Math.floor(Math.sin(dist(x + time, y, 128.0, 128.0) / 8.0)
+ + Math.sin(dist(x, y, 64.0, 64.0) / 8.0)
+ + Math.sin(dist(x, y + time / 7, 192.0, 64) / 7.0)
+ + Math.sin(dist(x, y, 192.0, 100.0) / 8.0));
+
+
+
+
+ var temp_col = Math.floor((2 + temp_val) * 50);
+
+ var rand_red = temp_col * 3;
+ var rand_green = temp_col ;
+ var rand_blue = 128 - temp_col;
+
+ ctx.fillStyle = "rgb("+rand_red+","+rand_green+","+rand_blue+")";
+
+ ctx.fillRect(x,y,PIXEL_SIZE,PIXEL_SIZE);
+ }
+ }
+
+
+ ctx.restore();
+ counter++;
+
+}
+
+init();