MCPcopy Create free account
hub / github.com/brain-workshop/brainworkshop / spawn

Method spawn

brainworkshop.py:2535–2627  ·  view source on GitHub ↗
(self, position=0, color=1, vis=0, number=-1, operation='none', variable = 0)

Source from the content-addressed store, hash-verified

2533 self.images = [self.image_set[i] for i in indices]
2534
2535 def spawn(self, position=0, color=1, vis=0, number=-1, operation='none', variable = 0):
2536 self.position = position
2537 self.color = get_color(color)
2538 self.vis = vis
2539
2540 self.center_x = field.center_x + (field.size // 3)*((position+1)%3 - 1) + (field.size // 3 - self.size)//2
2541 self.center_y = field.center_y + (field.size // 3)*((position//3+1)%3 - 1) + (field.size // 3 - self.size)//2
2542
2543 if self.vis == 0:
2544 if cfg.OLD_STYLE_SQUARES:
2545 lx = self.center_x - self.size // 2 + 2
2546 rx = self.center_x + self.size // 2 - 2
2547 by = self.center_y - self.size // 2 + 2
2548 ty = self.center_y + self.size // 2 - 2
2549 cr = self.size // 5
2550
2551 if cfg.OLD_STYLE_SHARP_CORNERS:
2552 self.square = batch.add(4, pyglet.gl.GL_POLYGON, None, ('v2i', (
2553 lx, by,
2554 rx, by,
2555 rx, ty,
2556 lx, ty,)),
2557 ('c4B', self.color * 4))
2558 else:
2559 #rounded corners: bottom-left, bottom-right, top-right, top-left
2560 x = ([lx + int(cr*(1-math.cos(math.radians(i)))) for i in range(0, 91, 10)] +
2561 [rx - int(cr*(1-math.sin(math.radians(i)))) for i in range(0, 91, 10)] +
2562 [rx - int(cr*(1-math.sin(math.radians(i)))) for i in range(90, -1, -10)] +
2563 [lx + int(cr*(1-math.cos(math.radians(i)))) for i in range(90, -1, -10)])
2564
2565 y = ([by + int(cr*(1-math.sin(math.radians(i)))) for i in range(0, 91, 10) + range(90, -1, -10)] +
2566 [ty - int(cr*(1-math.sin(math.radians(i)))) for i in range(0, 91, 10) + range(90, -1, -10)])
2567 xy = []
2568 for a,b in zip(x,y): xy.extend((a, b))
2569
2570 self.square = batch.add(40, pyglet.gl.GL_POLYGON, None,
2571 ('v2i', xy), ('c4B', self.color * 40))
2572
2573 else:
2574 # use sprite squares
2575 self.square = self.spr_square[color-1]
2576 self.square.opacity = 255
2577 self.square.x = self.center_x - field.size // 6
2578 self.square.y = self.center_y - field.size // 6
2579 self.square.scale = 1.0 * self.size / self.spr_square_size
2580 self.square_size_scaled = self.square.width
2581 self.square.batch = batch
2582
2583 # initiate square animation
2584 self.age = 0.0
2585 pyglet.clock.schedule_interval(self.animate_square, 1/60.)
2586
2587 elif 'arithmetic' in mode.modalities[mode.mode]: # display a number
2588 self.label.text = str(number)
2589 self.label.x = self.center_x
2590 self.label.y = self.center_y + 4
2591 self.label.color = self.color
2592 elif 'visvis' in mode.modalities[mode.mode]: # display a letter

Callers 1

generate_stimulusFunction · 0.80

Calls 1

get_colorFunction · 0.85

Tested by

no test coverage detected