当前位置: 首页>>代码示例>>Python>>正文


Python Graphics.drawLine方法代码示例

本文整理汇总了Python中Tools.Graphics.Graphics.drawLine方法的典型用法代码示例。如果您正苦于以下问题:Python Graphics.drawLine方法的具体用法?Python Graphics.drawLine怎么用?Python Graphics.drawLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Tools.Graphics.Graphics的用法示例。


在下文中一共展示了Graphics.drawLine方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: VuBarVertiPir

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class VuBarVertiPir(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.graphics.fill(BLUE)
        self.p = pyaudio.PyAudio()
        self.stream = self.p.open(format=audio_params[0],
                                  channels=audio_params[1],
                                  rate=audio_params[2],
                                  input=audio_params[3],
                                  output=audio_params[4],
                                  frames_per_buffer=audio_params[5])
        self.color = BLUE
        self.max = 0

    def getaudio(self):
        try:
            raw = self.stream.read(audio_params[5])
        except IOError as e:
            if e[1] != pyaudio.paInputOverflowed:
                raise
            else:
                print("Warning: audio input buffer overflow")
            raw = '\x00' * self.audio_params[5]
        return np.array(np.frombuffer(raw, np.int16), dtype=np.float64)

    def generate(self):
        self.graphics.fill(BLACK)
        audio = self.getaudio()
        self.color = interp_color(rms(audio/10000))
        self.color = color_convert(self.color)
        for i in range(0, matrix_height):
            rmsed = translate(rms(audio), 0, ((2**16)/2), 0, matrix_width*i)
            self.graphics.drawLine(0, i, rmsed, i, self.color)
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:36,代码来源:VuOther.py

示例2: VUmetertwo

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class VUmetertwo(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.controller = AudioController(channel=1, rate=256000, period=64)
        self.color = BLUE
        self.inputlength = matrix_height
        self.inputs = []
        self.offset = 13
        self.max = 1250
        self.lim = self.max
        self.rate = 10

    def getaverageof(self, number):
        averages = []
        for i in range(0, number):
            data = self.controller.getinput()
            while(data is None):
                data = self.controller.getinput()
            averages.append(data)
        sums = 0
        for num in averages:
            sums += num
        return int(sums / len(averages))

    def getinputs(self):
        self.inputs = []
        sums = 0
        for input in range(0, self.inputlength):
            data = self.getaverageof(3)
            self.inputs.append(data)
            sums += data
        return sums / len(self.inputs)

    def generate(self):
        average = self.getinputs()
        self.graphics.fill(BLACK)
        for i, line in enumerate(self.inputs):
            if line > self.max:
                self.max = line
            else:
                if self.max <= self.lim:
                    self.max = self.lim
                else:
                    self.max -= int((self.max - self.lim) / self.rate)
            length = int(translate(average, 0, self.max, 0, matrix_height))
            data = int(translate(line, 0, average, 0, length))
            if data > 0xff:
                self.data = 0xff
            if data > self.max:
                self.max = data
            self.graphics.drawLine(0, i, data - self.offset, i, self.color)
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:54,代码来源:Vumeter.py

示例3: VUmeterThree

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class VUmeterThree(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.controller = AudioController(channel=1, rate=16000, period=64)
        self.max = 1

    def generate(self):
        self.graphics.fill(BLACK)
        data = getaverageof(10, self.controller)
        data = int(translate(data, 0, 700, 0, 8))
        for i in range(0, 17):
            self.graphics.drawLine(0, i, data - 10, 0, BLUE)
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:15,代码来源:Vumeter.py

示例4: VUmeterone

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class VUmeterone(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.controller = AudioController(channel=1, rate=8000, period=128)
        self.average = []
        self.averaged = 1
        self.averagelength = 10

    def generate(self):
        data = getaverageof(10, self.controller)
        if data:
            data = int(translate(data, 0, 700, 0, 8))
            self.graphics.fill(BLACK)
            self.graphics.drawLine(0, 0, data - 10, 0, BLUE)
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:17,代码来源:Vumeter.py

示例5: GraphicsLineTest

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class GraphicsLineTest(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.color = YELLOW
        self.pos = 0, 0

    def generate(self):
        self.graphics.fill(BLACK)
        x, y = self.pos
        self.graphics.drawLine(matrix_width - x, matrix_height - y,
                               x, y, self.color)
        if x >= matrix_height:
            x = 0
            y = 0
        self.pos = x + 1, y
        return self.graphics.getSurface()
开发者ID:ozel,项目名称:py-artnet,代码行数:18,代码来源:GraphicsTests.py

示例6: VisualizerTwo

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class VisualizerTwo(object):
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.graphics.fill(BLUE)
        self.color = BLUE
        
        self.timer = Timer(0)
        
        self.chunk = 1024
        self.scale = 55
        self.exponent = 2
        self.samplerate = 44100	
        self.audio_params = (pyaudio.paInt16, 1, self.samplerate, True, self.chunk)
        self.p = pyaudio.PyAudio()
        self.stream = self.p.open(format=self.audio_params[0],
                                  channels=self.audio_params[1],
                                  rate=self.audio_params[2],
                                  input=self.audio_params[3],
                                  frames_per_buffer=self.audio_params[4])
        self.data = self.stream.read(self.chunk)

    def calculate_levels(self, data, chunk, samplerate, points=6, maxi=0):
        # Use FFT to calculate volume for each frequency
        MAX=maxi
         
        # Convert raw sound data to Numpy array
        fmt = "%dH"%(len(data)/2)
        data2 = struct.unpack(fmt, data)
        data2 = numpy.array(data2, dtype='h')
         
        # Apply FFT
        fourier = numpy.fft.fft(data2)
        ffty = numpy.abs(fourier[0:len(fourier)/2])/1000
        ffty1=ffty[:len(ffty)/2]
        ffty2=ffty[len(ffty)/2::]+2
        ffty2=ffty2[::-1]
        ffty=ffty1+ffty2
        ffty=numpy.log(ffty)-2
        fourier = list(ffty)[4:-4]
        fourier = fourier[:len(fourier)/2]
        size = len(fourier)
         
        # Add up for 6 lights
        levels = [sum(fourier[i:(i+size/points)]) for i in xrange(0, size, size/points)][:points]
        return levels 

    def getaudio(self):
        try:
            raw = self.stream.read(self.audio_params[5])
        except IOError as e:
            if e[1] != pyaudio.paInputOverflowed:
                raise
            else:
                print("Warning: audio input buffer overflow")
            raw = '\x00' * self.audio_params[5]
        return np.array(np.frombuffer(raw, np.int16), dtype=np.float64)

    def generate(self):
        self.graphics.fill(BLACK)
        if self.stream.get_read_available():
            self.data = self.stream.read(self.chunk)
        levels = self.calculate_levels(self.data, self.chunk, self.samplerate, matrix_height)
        for i, level in enumerate(levels):
            self.color = color_convert(interp_color(level/max(levels)))
            level = max(min(level/self.scale, i), 0.0)
            level = level**self.exponent
            level = int(level*0xff)
            self.graphics.drawLine(0, i, level, i, self.color)
        return self.graphics.getSurface()

    def __del__(self):
        print("Closing Stream")
        self.stream.close()
        self.p.terminate()
开发者ID:ozel,项目名称:py-artnet,代码行数:76,代码来源:VuOther.py

示例7: Visualizer

# 需要导入模块: from Tools.Graphics import Graphics [as 别名]
# 或者: from Tools.Graphics.Graphics import drawLine [as 别名]
class Visualizer(object):
    """
    testing with this is cool:
    https://www.youtube.com/watch?v=82Q6DRqf9H4
    https://youtu.be/XzjmPo6qr_0?list=RD05IZxpCWSao
    https://youtu.be/UUIQox072QA?list=RD05IZxpCWSao
    https://youtu.be/JTNXgzSpiTU?list=RD05IZxpCWSao
    https://youtu.be/S5xOj3JGU0c?list=RD05IZxpCWSao
    https://youtu.be/7Ul7uBoewdM?list=RD05IZxpCWSao
    https://youtu.be/B1DDpyt8qyg?list=RD05IZxpCWSao
    https://youtu.be/VwME67reIYk?list=RD05IZxpCWSao
    https://youtu.be/hn_T2rMPL4c?list=RD05IZxpCWSao
    https://youtu.be/U20HZoCnRGA
    https://youtu.be/eRE0dfOfVYE
    """
    def __init__(self):
        self.graphics = Graphics(matrix_width, matrix_height)
        self.graphics.fill(BLUE)
        self.color = BLUE
        
        self.timer = Timer(0)
        
        self.chunk = 1024
        self.scale = 55
        self.exponent = 2
        self.samplerate = 44100	
        self.audio_params = (pyaudio.paInt16, 1, self.samplerate, True, self.chunk)
        self.p = pyaudio.PyAudio()
        self.stream = self.p.open(format=self.audio_params[0],
                                  channels=self.audio_params[1],
                                  rate=self.audio_params[2],
                                  input=self.audio_params[3],
                                  frames_per_buffer=self.audio_params[4])
        self.data = self.stream.read(self.chunk)

    def calculate_levels(self, data, chunk, samplerate, points=6, maxi=0):
        # Use FFT to calculate volume for each frequency
        MAX=maxi
         
        # Convert raw sound data to Numpy array
        fmt = "%dH"%(len(data)/2)
        data2 = struct.unpack(fmt, data)
        data2 = numpy.array(data2, dtype='h')
         
        # Apply FFT
        fourier = numpy.fft.fft(data2)
        ffty = numpy.abs(fourier[0:len(fourier)/2])/1000
        ffty1=ffty[:len(ffty)/2]
        ffty2=ffty[len(ffty)/2::]+2
        ffty2=ffty2[::-1]
        ffty=ffty1+ffty2
        ffty=numpy.log(ffty)-2
        fourier = list(ffty)[4:-4]
        fourier = fourier[:len(fourier)/2]
        size = len(fourier)
         
        # Add up for 6 lights
        levels = [sum(fourier[i:(i+size/points)]) for i in xrange(0, size, size/points)][:points]
        return levels 

    def getaudio(self):
        try:
            raw = self.stream.read(self.audio_params[5])
        except IOError as e:
            if e[1] != pyaudio.paInputOverflowed:
                raise
            else:
                print("Warning: audio input buffer overflow")
            raw = '\x00' * self.audio_params[5]
        return np.array(np.frombuffer(raw, np.int16), dtype=np.float64)

    def generate(self):
        self.graphics.fill(BLACK)
        self.data = self.stream.read(self.chunk)
        levels = self.calculate_levels(self.data, self.chunk, self.samplerate, matrix_height)
        for i, level in enumerate(levels):
            self.color = color_convert(interp_color(level/max(levels)))
            level = max(min(level/self.scale, 1.0), 0.0)
            level = level**self.exponent
            level = int(level*0xff)
            self.graphics.drawLine(0, i, level, i, self.color)
        return self.graphics.getSurface()

    def __del__(self):
        print("Closing Stream")
        self.stream.close()
        self.p.terminate()
开发者ID:ozel,项目名称:py-artnet,代码行数:89,代码来源:VuOther.py


注:本文中的Tools.Graphics.Graphics.drawLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。