Skip to content

Instantly share code, notes, and snippets.

@andyli
Created February 26, 2011 13:16
Show Gist options
  • Select an option

  • Save andyli/845180 to your computer and use it in GitHub Desktop.

Select an option

Save andyli/845180 to your computer and use it in GitHub Desktop.
onthewings.stuffs.stuff8
/**
* 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.stuff8;
import cpp.Sys;
import hxColorToolkit.spaces.HSL;
import nme.geom.Point;
import of.Context;
import org.casalib.util.NumberUtil;
using of.Context.Functions;
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;
class Main extends BaseApp
{
var screenCap:Image;
var width:Int;
var height:Int;
var point:Array<Float>;
var velocity:Array<Float>;
var acceleration:Array<Float>;
override public function setup():Void {
setFrameRate(120);
enableAlphaBlending();
enableSmoothing();
background(255, 255, 255);
setCircleResolution(100);
screenCap = new Image();
screenCap.allocate(getWidth(), getHeight(), Constants.OF_IMAGE_COLOR);
var p = screenCap.getPixels();
for (i in 0...p.length) {
p[i] = cast 255;
}
screenCap.update();
width = getWidth();
height = getHeight();
point = [];
velocity = [];
acceleration = [];
for (i in 0...360) {
point.push(0);
velocity.push(NumberUtil.randomWithinRange(0, 1));
acceleration.push(NumberUtil.randomWithinRange(0, 0.01));
}
}
override public function draw():Void {
setColor(255, 255, 255, 255);
screenCap.draw(0, 0);
translate(width * 0.5, height * 0.5);
var rgb = new HSL(getFrameNum() * 10, 100, 50).toRGB();
setColor(cast rgb.red, cast rgb.green, cast rgb.blue, 50);
var _min = Math.POSITIVE_INFINITY;
var _max = Math.NEGATIVE_INFINITY;
for (i in 0...point.length) {
point[i] += velocity[i];
if (point[i] < _min) _min = point[i];
if (point[i] > _max) _max = point[i];
velocity[i] += acceleration[i];
}
noFill();
var ppt = point[0];
for (i in 0...point.length) {
var pt = new Point(point[i], 0);
pt.rotatePoint(new Point(), i.map(0, point.length, 0, 360));
circle(pt.x, pt.y, point[i] - ppt);
ppt = point[i];
}
var tmp = velocity;
velocity = acceleration;
acceleration = tmp;
screenCap.grabScreen(0, 0, width, height);
}
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();
}
}
public static function main():Void {
AppRunner.setupOpenGL(new AppGlutWindow(), 1680, 1050, Constants.OF_FULLSCREEN);
//AppRunner.setupOpenGL(new AppGlutWindow(), 1280, 720, 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