NEU: Alle Visual Codes als Code Snippets für Flash CS5:
jetzt hier downloaden .
Computerbild Oszillationsmuster
Code Actionscript 2.0
Frame-Aktion
// initialize drawing createEmptyMovieClip("holder_mc", 1); _root.bitmap = new flash.display.BitmapData(200, 200, true, 0xFFFFFFFF); holder_mc.attachBitmap(_root.bitmap, 10, "auto", true); // go through all rows and columns for (px = 0; px < 200; px = px + 1) { for (py = 0; py < 200; py = py + 1) { g = graph2d(px, py); color = (g << 16 | g << 8 | g); pixel(px, py, color); } } // enlarge bitmap-view holder_mc._xscale = 200; holder_mc._yscale = 200; function graph2d(px, py) { g = sine(px * px) + cosine(py * py); // sine + cosine, values between -2 and 2 g = stretch(g, 128, 63); // center 128, amplitude +-128 -> values between 0 und 255 return g; } function pixel(px, py, color) { _root.bitmap.setPixel(px, py, color); } function sine(x) { // sine conversion for values // between 0 and 400 (stage width) s = Math.sin(x * 2 * Math.PI / 400); return s; } function cosine(x) { // cosine conversion for values // between 0 and 400 (stage width) s = Math.cosin(x * 2 * Math.PI / 400); return s; } function stretch(value, center, amplitude) { // scales and shifts value st = int(value * amplitude + center); return st; }
Code Actionscript 3.0
// initialize drawing var drawing:MovieClip = new MovieClip(); var bitmapdata = new BitmapData(200, 200, true, 0xFFFFFFFF); var bitmap = new Bitmap(bitmapdata); bitmap.smoothing = true; drawing.addChild(bitmap); this.addChild(drawing); // go through all rows and columns for (var px = 0; px < 200; px = px + 1) { for (var py = 0; py < 200; py = py + 1) { var g = graph2d(px, py); var color = (g << 16 | g << 8 | g); pixel(px, py, color); } } // enlarge bitmap-view drawing.scaleX = 2; drawing.scaleY = 2; function graph2d(px, py) { // sine + cosine, values between -2 and 2 g = sinus(px * px) + cosinus(py * py); // center 128, amplitude +-128 -> values between 0 und 255 g = stretch(g, 128, 63); return g; } function pixel(px:int, py:int, color:int) { bitmapdata.setPixel(px, py, color); } function sinus(x:int) { // sine conversion for values // between 0 and 400 (stage width) var s = Math.sin(x * 2 * Math.PI/ 400); return s; } function cosinus(x:int) { // cosine conversion for values // between 0 and 400 (stage width) var s = Math.cos(x * 2 * Math.PI/ 400); return s; } function stretch(value:Number, center:int, amplitude:int) { // scales and shifts value var st = int(value * amplitude + center); return st; }
Infos
Dieses Beispiel zeigt ein oszillierendes Muster von Grauwerten. Die Funktion graph2d berechnet eine Kombination von Sinus, Cosinus und Quadrat der zwei Ausgangswerte px und py und stellt das Ergebnis als eine Art Höhenkurve oder Heatmap dar.
Download
Right click: Flashfile AS 2.0 | Flashfile AS 3.0 | SWF-File