Hello, could anyone run these snippets?
*TEST 1*
import pyglet
from pyglet.gl import GL_TRIANGLES
from itertools import chain
C = 0.707
def octagon (x, y, r, c, b, g):
""" Returns a vertex list of regular octagon with center at (x, y) and
corners
distanced r away. Paints center and corners. Adds to batch b in group
g. """
i = list(chain.from_iterable( (0, x+1, x+2) for x in range(8) ) )
i.extend( (0, 1, 8) )
p = x, y
p += x-r, y, x+int(-C*r), y+int( C*r), x, y+r, x+int( C*r), y+int( C*r)
p += x+r, y, x+int( C*r), y+int(-C*r), x, y-r, x+int(-C*r), y+int(-C*r)
return b.add_indexed(9, GL_TRIANGLES, g, i, ('v2i', p), ('c3B', c))
WIN = 900, 900, 'TEST'
CENTER = WIN[0] // 2, WIN[1] // 2
RADIUS = 100
SPEED = 0.1 # in seconds
WHITE = (255, 255, 255) # for center
RED = (255, 0, 0) # for points
# Variables
win = pyglet.window.Window(*WIN)
batch = pyglet.graphics.Batch()
def on_step(dt):
global batch
batch = pyglet.graphics.Batch()
octagon(CENTER[0], CENTER[1], RADIUS, WHITE+RED*8, batch, None)
@win.event
def on_draw():
win.clear()
batch.draw()
pyglet.clock.schedule_interval(on_step, SPEED)
pyglet.app.run()
*TEST 2*
import pyglet
from random import randrange
from pyglet.gl import GL_TRIANGLES
from itertools import chain
C = 0.707
def octagon (x, y, r, c, b, g):
""" Returns a vertex list of regular octagon with center at (x, y) and
corners
distanced r away. Paints center and corners. Adds to batch b in group
g. """
i = list(chain.from_iterable( (0, x+1, x+2) for x in range(8) ) )
i.extend( (0, 1, 8) )
p = x, y
p += x-r, y, x+int(-C*r), y+int( C*r), x, y+r, x+int( C*r), y+int( C*r)
p += x+r, y, x+int( C*r), y+int(-C*r), x, y-r, x+int(-C*r), y+int(-C*r)
return b.add_indexed(9, GL_TRIANGLES, g, i, ('v2i', p), ('c3B', c))
WIN = 900, 900, 'TEST'
RADIUS = 60
WHITE = (255, 255, 255) # for center
RED = (255, 0, 0) # for corners
win = pyglet.window.Window(*WIN)
batch = pyglet.graphics.Batch()
def on_step(dt):
x = randrange(RADIUS, WIN[0] - RADIUS)
y = randrange(RADIUS, WIN[1] - RADIUS)
octagon(x, y, RADIUS, WHITE+RED*8, batch, None)
@win.event
def on_draw():
win.clear()
batch.draw()
pyglet.clock.schedule_interval(on_step, 1)
pyglet.app.run()
I posted this question on Stack Overflow
<http://stackoverflow.com/questions/30306527/incorrectly-drawn-octagon-random-new-test-added>
too. The code seems to be correct but on the shape is incorrectly drawn. Is
this reproducable on your machine? What causes this behaviour?
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.