Created
January 18, 2011 04:36
-
-
Save andyli/783990 to your computer and use it in GitHub Desktop.
onthewings.stuffs.stuff4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Some of the renderings can be found at | |
* http://www.flickr.com/photos/andy-li/sets/72157625719497466/ | |
* | |
* | |
* Copyright (c) 2011, Andy Li http://www.onthewings.net/ | |
* All rights reserved. | |
* | |
* Redistribution and use in source and binary forms, with or without modification, | |
* are permitted provided that the following conditions are met: | |
* | |
* Redistributions of source code must retain the above copyright notice, | |
* this list of conditions and the following disclaimer. | |
* Redistributions in binary form must reproduce the above copyright notice, | |
* this list of conditions and the following disclaimer in the documentation | |
* and/or other materials provided with the distribution. | |
* The name of the author may not be used to endorse or promote products derived | |
* from this software without specific prior written permission. | |
* | |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | |
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | |
* OF THE POSSIBILITY OF SUCH DAMAGE. | |
*/ | |
package onthewings.stuffs.stuff4; | |
import cpp.Lib; | |
import cpp.Sys; | |
import nme.geom.Point; | |
import of.Context; | |
using of.Context.Functions; | |
using Lambda; | |
using DateTools; | |
using org.casalib.util.NumberUtil; | |
using nme.geom.Point; | |
class Main extends of.app.BaseApp | |
{ | |
var screenCap:Image; | |
var width:Int; | |
var height:Int; | |
var pt:Point; | |
var pts:Array<Point>; | |
override public function setup():Void { | |
setFrameRate(120); | |
enableAlphaBlending(); | |
enableSmoothing(); | |
background(0, 0, 0); | |
noFill(); | |
width = getWidth(); | |
height = getHeight(); | |
screenCap = new Image(); | |
screenCap.allocate(width, height, Constants.OF_IMAGE_COLOR); | |
var p = screenCap.getPixels(); | |
for (i in 0...p.length) { | |
p[i] = cast 0; | |
} | |
screenCap.update(); | |
pt = new Point(0, 0); | |
pts = []; | |
pts.push(pt.clone()); | |
var pt = pt.clone(); | |
while (pt.x++ < width) { | |
pt.y = sin(pt.x.map(0, width, 0, 2 * Math.PI)) * height; | |
pts.push(pt.clone()); | |
} | |
} | |
override public function draw():Void { | |
setColor(255, 255, 255, 255); | |
screenCap.draw(0, 0); | |
setColor(255, 255, 255, 5); | |
var max = 0.0; | |
var min = 0.0; | |
var ppts = pts.copy(); | |
var pt = ppts[0]; | |
for (i in 1...ppts.length) { | |
pt = ppts[i].clone(); | |
pt.y += sin(ppts[i - 1].y / pt.y); | |
if (pt.y > max) max = pt.y; | |
if (pt.y < min) min = pt.y; | |
pts[i] = pt; | |
} | |
beginShape(); | |
pt = pts[0]; | |
vertex(pt.x, height * 0.5 + pt.y); | |
vertex(pt.x, height * 0.5 + pt.y); | |
for (i in 1...pts.length) { | |
pt = pts[i]; | |
vertex(pt.x, pt.y.map(min, max, 0, height)); | |
} | |
vertex(pt.x, height * 0.5 + pt.y); | |
endShape(); | |
screenCap.grabScreen(0, 0, width, height); | |
} | |
override public function keyPressed(key:Int):Void { | |
switch(key){ | |
case Constants.OF_KEY_RETURN: | |
screenCap.saveImage(Date.now().format("%Y%m%d_") + getFrameNum() + ".png"); | |
Sys.exit(0); | |
} | |
} | |
public static function main():Void { | |
AppRunner.setupOpenGL(new AppGlutWindow(), 1440, 900, Constants.OF_FULLSCREEN); | |
//AppRunner.setupOpenGL(new AppGlutWindow(), 800, 600, Constants.OF_WINDOW); | |
AppRunner.runApp(new Main()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment