Created
May 11, 2011 18:21
-
-
Save andyli/966997 to your computer and use it in GitHub Desktop.
onthewings.stuffs.stuff14
This file contains hidden or 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.stuff14; | |
| import cpp.Sys; | |
| import hxColorToolkit.spaces.RGB; | |
| import hxColorToolkit.spaces.HSL; | |
| import nme.geom.Point; | |
| import nme.geom.Vector3D; | |
| import org.casalib.util.NumberUtil; | |
| import haxe.io.BytesData; | |
| import of.Context; | |
| using of.Context.Functions; | |
| using Std; | |
| using Math; | |
| using Lambda; | |
| using DateTools; | |
| using StringTools; | |
| using nme.geom.Point; | |
| using org.casalib.util.ArrayUtil; | |
| using org.casalib.util.NumberUtil; | |
| using org.casalib.util.GeomUtil; | |
| using org.casalib.util.ConversionUtil; | |
| using hxColorToolkit.ColorToolkit; | |
| typedef Circle = { | |
| var center:Point; | |
| var radius:Float; | |
| var color:Int; | |
| var angles:Array<Float>; | |
| var offsetRatios:Array<Float>; | |
| } | |
| class Main extends BaseApp | |
| { | |
| var screenCap:Image; | |
| var width:Int; | |
| var height:Int; | |
| var circleList:List<Circle>; | |
| override public function setup():Void { | |
| setFrameRate(25); | |
| enableAlphaBlending(); | |
| setCircleResolution(50); | |
| enableSmoothing(); | |
| background(50, 50, 50); | |
| 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(); | |
| circleList = new List(); | |
| circleList.add({ | |
| center: new Point(width*0.5, height*0.5), | |
| radius: height * .5, | |
| color: 0xFF00FF, | |
| angles: [45.0, 90], | |
| offsetRatios: [1/2, 1/3] | |
| }); | |
| } | |
| override public function draw():Void { | |
| var r = 0.0; | |
| var s = 1.0; | |
| setLineWidth(1); | |
| for (c in circleList){ | |
| translate(width*0.5, height*0.5); | |
| scale(s,s); | |
| rotate(r); | |
| translate(width*-0.5, height*-0.5); | |
| r += c.angles[0]; | |
| s -= 0.0001; | |
| var rgb = c.color.toRGB(); | |
| setColor(rgb.red.int(), rgb.green.int(), rgb.blue.int(), c.radius.map(0,height*.5,155,0).constrain(0,255).round()); | |
| fill(); | |
| circle(c.center.x, c.center.y, c.radius); | |
| setColor(rgb.red.int(), rgb.green.int(), rgb.blue.int(), c.radius.map(0,height*.5,155,0).constrain(0,255).round()); | |
| noFill(); | |
| circle(c.center.x, c.center.y, c.radius); | |
| } | |
| } | |
| override public function keyPressed(key:Int):Void { | |
| if (key == 's'.charCodeAt(0)){ | |
| screenCap.grabScreen(0, 0, width, height); | |
| screenCap.saveImage(Date.now().format("%Y%m%d_%H%M%S") + ".png"); | |
| } else if (key == 'a'.charCodeAt(0)) { | |
| setup(); | |
| } else if (key == 'c'.charCodeAt(0)) { | |
| for (c in circleList.array()) | |
| for (angle in c.angles) | |
| for (offsetRatio in c.offsetRatios) | |
| { | |
| var newCenter = c.center.clone(); | |
| var pt = Point.polar(c.radius * offsetRatio, angle.degreesToRadians()); | |
| newCenter.offset(pt.x, pt.y); | |
| var newAngles = []; | |
| for (a in c.angles) newAngles.push(a * offsetRatio); | |
| var newOffsetRatios = []; | |
| for (o in c.offsetRatios) newOffsetRatios.push((o - offsetRatio).abs()); | |
| circleList.add({ | |
| center: newCenter, | |
| radius: c.radius * offsetRatio, | |
| color: c.color.rybRotate(angle).shiftSaturation(offsetRatio.abs()), | |
| angles: newAngles, | |
| offsetRatios: newOffsetRatios | |
| }); | |
| } | |
| var circleAry = circleList.array(); | |
| circleAry.sort(function(c0,c1) return c0.radius == c1.radius ? 0 : c0.radius - c1.radius > 0 ? -1 : 1); | |
| circleList = circleAry.list(); | |
| } else if (key == "v".charCodeAt(0)) { | |
| var a = circleList.array(); | |
| a.reverse(); | |
| circleList = a.list(); | |
| } | |
| } | |
| public static function main():Void { | |
| AppRunner.setupOpenGL(new AppGlutWindow(), 1680, 1050, Constants.OF_FULLSCREEN); | |
| //AppRunner.setupOpenGL(new AppGlutWindow(), 1024, 768, 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