Skip to content

Instantly share code, notes, and snippets.

@andyli
Created January 3, 2011 00:05
Show Gist options
  • Save andyli/762950 to your computer and use it in GitHub Desktop.
Save andyli/762950 to your computer and use it in GitHub Desktop.
onthewings.stuffs.stuff2
/**
* 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.stuff2;
import cpp.Lib;
import cpp.Sys;
import nme.geom.Point;
import hxColorToolkit.spaces.HSL;
import of.Context;
using of.Context.Functions;
using DateTools;
using StringTools;
using org.casalib.util.GeomUtil;
using org.casalib.util.NumberUtil;
using org.casalib.util.ConversionUtil;
using nme.geom.Point;
using hxColorToolkit.ColorToolkit;
class Main extends of.app.BaseApp
{
var screenCap:Image;
var width:Int;
var height:Int;
var currentPt:Point;
var currentAngle:Float;
var currentAngle2:Float;
var radius:Float;
var radiusEnd:Float;
var radiusInit:Float;
var currentColor:HSL;
override public function setup():Void {
setFrameRate(120);
enableAlphaBlending();
enableSmoothing();
background(0, 0, 0);
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();
radiusInit = radius = height * 0.45;
currentPt = new Point(0, 1);
currentAngle = currentAngle2 = 0;
radiusEnd = 0;
currentColor = new HSL(0, 100, 50);
}
override public function draw():Void {
setColor(255, 255, 255, 255);
screenCap.draw(0, 0);
for (i in 0...10000){
var prevPt = currentPt;
var currentAngleRad = currentAngle.degreesToRadians();
var currentAngle2Rad = currentAngle2.degreesToRadians();
currentPt = new Point(radius * cos(currentAngle2Rad) * tan(currentAngle2Rad));
currentPt.rotatePoint(new Point(), currentAngle);
currentAngle += tan(currentAngle2Rad);
currentAngle2 += 1;
var alpha = Math.round(radius.map(radiusInit, radiusEnd, 0, 15));
currentColor.hue = cos(currentAngle2Rad) * 360;
currentColor.lightness = tan(currentAngleRad) * 100;
var rgb = currentColor.getColor().toRGB();
setColor(cast rgb.red, cast rgb.green, cast rgb.blue, alpha);
line(width * 0.5 + prevPt.x, height * 0.5 + prevPt.y, width * 0.5 + currentPt.x, height * 0.5 + currentPt.y);
radius -= 0.0001;
if (radius <= radiusEnd) {
screenCap.grabScreen(0, 0, width, height);
screenCap.saveImage(Date.now().format("%Y%m%d_%H%M%S") + ".png");
Sys.exit(0);
}
}
screenCap.grabScreen(0, 0, width, height);
}
public static function main():Void {
AppRunner.setupOpenGL(new AppGlutWindow(), 1440, 900, Constants.OF_FULLSCREEN);
AppRunner.runApp(new Main());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment