Created
January 25, 2013 23:32
-
-
Save schonstal/4638869 to your computer and use it in GitHub Desktop.
hue thing
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
//In create | |
palette = new FlxSprite(); | |
palette.loadGraphic(Assets.CMY); | |
for(var x:int = 0; x < palette.width; x++) { | |
for(var y:int = 0; y < palette.height; y++) { | |
var pixel:uint = palette.pixels.getPixel32(x, y); | |
if(colors.indexOf(pixel) < 0) { | |
colors.push(palette.pixels.getPixel32(x, y)); | |
} | |
} | |
} | |
FlxG.log(colors.length); | |
for each(var color:uint in colors) { | |
shiftedHSB.push(FlxU.getHSB(color)); | |
} | |
//In update | |
for (var i:int = 0; i < shiftedHSB.length; i++) { | |
shiftedHSB[i][0] += FlxG.elapsed * HUE_RATE | |
if(shiftedHSB[i][0] >= 360) { | |
shiftedHSB[i][0] = 0; | |
} | |
shiftedColors[i] = FlxU.makeColorFromHSB(shiftedHSB[i][0], shiftedHSB[i][1], shiftedHSB[i][2]); | |
} | |
//In draw | |
for(var row:uint = 0; row < camera.height; row++) { | |
for(var column:uint = 0; column < camera.width; column++) { | |
colorIndex = colors.indexOf(camera.buffer.getPixel32(column,row)); | |
if(colorIndex > -1) { | |
camera.buffer.setPixel32(column,row,shiftedColors[colorIndex]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment