_wait_objects_n ) ( * ) 91 92 def start ( self ) : 93 if _kernel32. _wait_objects_array = \ĩ0 ( HANDLE * self. _wait_objects_array = None 86 return 87 88 self. ![]() _recreate_wait_objects_array ( ) 81 82 def _recreate_wait_objects_array ( self ) : 83 if not self. _wait_objects ) : 77 if object = _object : 78 del self. _recreate_wait_objects_array ( ) 74 75 def remove_wait_object ( self, object ) : 76 for i, ( _object, _ ) in enumerate ( self. _timer_proc ) 70 71 def add_wait_object ( self, object, func ) : 72 self. _recreate_wait_objects_array ( ) 66 67 self. _next_idle_time = None 53 54 # Force immediate creation of an event queue on this thread - note 55 # that since event loop is created on pyglet.app import, whatever 56 # imports pyglet.app _must_ own the main run loop. 33 # - 34 # $Id:$ 35 36 _docformat_ = ' restructuredtext ' 37 _version_ = ' $Id: $ ' 38 39 import ctypes 40 41 from pyglet import app 42 from base import PlatformEventLoop 43 44 from 32 import _kernel32, _user32, types, constants 45 from import * 46 from import * 47 48 class Win32EventLoop ( PlatformEventLoop ) : 49 def _init_ ( self ) : 50 super ( Win32EventLoop, self ). IN NO EVENT SHALL THE 25 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES 28 # LOSS OF USE, DATA, OR PROFITS OR BUSINESS INTERRUPTION) HOWEVER 29 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 31 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 # POSSIBILITY OF SUCH DAMAGE. 20 # 21 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 # * Neither the name of pyglet nor the names of its 17 # contributors may be used to endorse or promote products 18 # derived from this software without specific prior written 19 # permission. 12 # * Redistributions in binary form must reproduce the above copyright 13 # notice, this list of conditions and the following disclaimer in 14 # the documentation and/or other materials provided with the 15 # distribution. 5 # 6 # Redistribution and use in source and binary forms, with or without 7 # modification, are permitted provided that the following conditions 8 # are met: 9 # 10 # * Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. Raw file 1 # - 2 # pyglet 3 # Copyright (c) 2006-2008 Alex Holkner 4 # All rights reserved. # don't need the below any more as _tex_data points to _array_normed memory Self._array_normed = self.cmap(self.norm(self.array), bytes=True) Self.image = (array.shape, array.shape, "RGBA", self._tex_data) Self.pitch = array.shape * format_size * bytes_per_channel Self._tex_data = (pyglet.gl.GLubyte * self._array_normed.size).from_buffer(self._array_normed) # self._tex_data = (pyglet.gl.GLubyte * self._array_normed_data.size)( *self._array_normed_data ) # we have removed it by setting the _tex_data array to share the buffer Self._array_normed = np.zeros(array.shape (4,), dtype=np.uint8) """Dynamic pyglet image of a 2d numpy array using matplotlib colormaps."""ĭef _init_(self, array, cmap=cmaps.viridis, norm=None, rescale=True): ) my_arr = np.random.random((nx, ny)) arr_img = ArrayImage(my_arr) def on_draw():Īrr_(x, y) import numpy as np import matplotlib.cm as cmaps from lors import Normalize import pyglet import pyglet.gl class ArrayImage: Pitch = dimensions * format_size * bytes_per_channel # create an image # pitch is 'texture width * number of channels per element * per channel size in bytes' return ( With the hint from Bago I got this to code to work :) And indeed nfirvine suggestion is reasonable, since I only want to display the matrix in greyscale. I can't find the mistake in the first code example :( If I save and load the array instead it works (but it is horrobly slower): ![]() Self.image = (X,Y, 'RGB', self.img_data, pitch = -X*3) Self.img_data = self.create(X,Y).data._str_() I want to display the array in greyscale, but pyglet displays it with colours see the image: ![]() I have found a very similar topic ( how to display a numpy array with pyglet?) that I used. I have problems with displaying a numpy array with pyglet.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |