Skip to content

Instantly share code, notes, and snippets.

@lindemann09
Last active October 4, 2017 12:50
Show Gist options
  • Save lindemann09/3bdfebd31df169080389fc6c01b9ac9c to your computer and use it in GitHub Desktop.
Save lindemann09/3bdfebd31df169080389fc6c01b9ac9c to your computer and use it in GitHub Desktop.
vertex_representation_of_shape_contour
import expyriment
from expyriment.misc import geometry
import math as _math
def _contour_of_edge(node_A, node_B, node_C, line_width):
# using nodes in cartesian coordinates
BA = (node_B[0] - node_A[0], node_B[1] - node_A[1]) # vector B-A
BC = (node_B[0] - node_C[0], node_B[1] - node_C[1])
phi_BC = _math.atan2(BC[1], BC[0]) # polar coordinate phi (angle) from cartesian
phi_sum = _math.atan2(BA[1]+BC[1], BA[0]+BC[0])
rho = line_width/_math.sin(phi_BC - phi_sum)
V = (0.5*rho*_math.cos(phi_sum), 0.5*rho*_math.sin(phi_sum)) # polar to cartesian
p1 = (node_B[0] + V[0], node_B[1] + V[1])
p2 = (node_B[0] - V[0], node_B[1] - V[1])
return (p1, p2)
def vertex_representation_of_shape_contour(points_xy, line_width):
# vertex representation of shape contores #TODO
l = len(points_xy)
outer_array = []
inner_array = []
for b in range(l):
a = b-1
if a<0:
a = l-1
c = b+1
if c>l-1:
c=0
p1, p2 = _contour_of_edge(points_xy[a], points_xy[b], points_xy[c], line_width)
outer_array.append(p1)
inner_array.append(p2)
outer_array.append(outer_array[0])
inner_array.append(inner_array[0])
return outer_array + list(reversed(inner_array))
line_width = 8
points =[ (100, 0),
(00, 200),
(50, -200 )]
expyriment.control.set_develop_mode()
exp = expyriment.control.initialize()
expyriment.control.start(skip_ready_screen=True)
s = expyriment.stimuli.Shape(colour=(255,255,255), line_width=line_width)
s.add_vertices(geometry.points_to_vertices( points ))
s.present()
exp.keyboard.wait()
s = expyriment.stimuli.Shape(colour=(255,255,255), line_width=1)
v = vertex_representation_of_shape_contour(points, line_width)
s.add_vertices(geometry.points_to_vertices( v ))
s.present()
exp.keyboard.wait()
s = expyriment.stimuli.Shape(colour=(255,255,255), line_width=0)
v = vertex_representation_of_shape_contour(points, line_width)
s.add_vertices(geometry.points_to_vertices( v ))
s.present()
exp.keyboard.wait()
expyriment.control.end()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment