Created
April 8, 2013 10:57
-
-
Save eni23/5335937 to your computer and use it in GitHub Desktop.
rainbow maker jeah
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
rainbow_maker={ | |
num:25, | |
act_num:0, | |
center:128, | |
width:127, | |
phase:0, | |
factor_red: 30, | |
factor_green:6, | |
factor_blue:2, | |
freq:false, | |
RGB2Color: function(r,g,b){ | |
return '#' + this.byte2Hex(r) + this.byte2Hex(g) + this.byte2Hex(b); | |
}, | |
byte2Hex: function(n){ | |
var nybHexString = "0123456789ABCDEF"; | |
return String(nybHexString.substr((n >> 4) & 0x0F,1)) + nybHexString.substr(n & 0x0F,1); | |
}, | |
next: function(){ | |
if (!this.freq) { this.freq = Math.PI*2/this.num; } | |
var i=this.act_num; | |
var red = Math.sin(this.freq*i+this.factor_red+this.phase) * this.width + this.center; | |
var green = Math.sin(this.freq*i+this.factor_green+this.phase) * this.width + this.center; | |
var blue = Math.sin(this.freq*i+this.factor_blue+this.phase) * this.width + this.center; | |
this.act_num++; | |
return this.RGB2Color(red,green,blue); | |
} | |
} |
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
#!/usr/bin/env python | |
import math | |
class rainbowmaker: | |
def __init__(self): | |
self.num=25 | |
self.act_num=0 | |
self.center=127 | |
self.width=128 | |
self.phase=0 | |
self.factor_red=30 | |
self.factor_green=6 | |
self.factor_blue=2 | |
self.freq=False | |
def rgb2color(self,r,g,b): | |
return "#" + str(hex(r))[2:] + str(hex(g))[2:] + str(hex(b))[2:] | |
def next(self): | |
if self.freq is False: | |
self.freq=math.pi*2/self.num | |
i=self.act_num | |
red=math.sin(self.freq*i+self.factor_red+self.phase) * self.width + self.center | |
green=math.sin(self.freq*i+self.factor_green+self.phase) * self.width + self.center | |
blue=math.sin(self.freq*i+self.factor_blue+self.phase) * self.width + self.center | |
self.act_num=self.act_num+1 | |
return int(red),int(green),int(blue) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment