Chipmunk | R Documentation |
Chipmunk class
Chipmunk class
new()
Initialize the simulation space
Chipmunk$new(gravity = cpv(0, -100), time_step = 0.01)
gravity
vector object indication direction and strength
of gravity. Default: cpv(0, -100)
time_step
simulation step size. smaller is more accurate. Default: 0.01 Add a shape of the given type
add_shape()
Chipmunk$add_shape(type, shape, friction, elasticity)
type
one of segment, circle, box, polygon and static variants
shape
the cmShape ExternalPointer
friction
friction along segment. range [0, 1]
elasticity
Range [0, 1] Add a body of the given type
add_body()
Chipmunk$add_body(type, body, x, y, vx, vy, angle, angular_velocity)
type
character name of type. must be a dynamic type
body
body to add. type = cpBody
x, y
initial body location
vx, vy
initial body velocity
angle
orientation angle in degrees
angular_velocity
default: 0 degrees/second Add a static segment
add_static_segment()
Chipmunk$add_static_segment(x1, y1, x2, y2, friction = 1, elasticity = 0)
x1, y1, x2, y2
segment end points
friction
friction along segment. default 1. range [0, 1]
elasticity
default: 0 (no bounce). Range [0, 1]
get_static_segments()
Get the data.frame of all current segments Add a circular body to the space
Chipmunk$get_static_segments()
add_circle()
Chipmunk$add_circle( x, y, vx = 0, vy = 0, radius = 1, angular_velocity = 0, mass = 1, friction = 0.7, elasticity = 0 )
x, y
initial body location
vx, vy
initial body velocity
radius
radius of body. default: 1
angular_velocity
default: 0 degrees/second
mass
mass of body. default: 1
friction
default: 0.7
elasticity
default: 0 (no bounce). Valid range [0, 1]
get_circles()
Get the location of all the circles Add a box body to the space
Chipmunk$get_circles()
add_box()
Chipmunk$add_box( x, y, vx = 0, vy = 0, width = 1.73, height = 1, angle = 0, radius = 0.05, angular_velocity = 0, mass = 1, friction = 0.7, elasticity = 0 )
x, y
initial body location
vx, vy
initial body velocity
width, height
body width and height
angle
rotation angle in degrees. default 0
radius
radius of rounded corner
angular_velocity
default: 0 degrees/second
mass
mass of body. default: 1
friction
default: 0.7
elasticity
default: 0 (no bounce). Valid range [0, 1]
get_boxes()
Get the location of all the boxes
Chipmunk$get_boxes()
a data.frame with idx, width, height and rotation angle (radians)
get_boxes_as_polygons()
Get the location of all the boxes as a list of corner vertices Add a convex hull polygon to the space
Chipmunk$get_boxes_as_polygons()
add_polygon()
Chipmunk$add_polygon( xs, ys, angle = 0, x = 0, y = 0, vx = 0, vy = 0, radius = 0.05, angular_velocity = 0, mass = 1, friction = 0.7, elasticity = 0 )
xs, ys
polygon vertices
angle
initial rotation angle in degrees. default 0
x, y
initial body location
vx, vy
initial body velocity
radius
radius of rounded corners
angular_velocity
default: 0 degrees/second
mass
mass of body. default: 1
friction
default: 0.7
elasticity
default: 0 (no bounce). Valid range [0, 1]
get_polygons()
Get the location of all the polygons
Chipmunk$get_polygons()
get_bodies()
Advanced: Get the list of Chipmunk cpBody
objects
Chipmunk$get_bodies()
get_body_states()
Advanced: Get state of cpBody
objects as data.frame
Chipmunk$get_body_states(type)
type
cpbody type one of c('segment', 'circle', 'box', 'polygon')
Advance the simulation by N timesteps
advance()
Chipmunk$advance(N = 1)
N
number of time steps to advance
clone()
The objects of this class are cloneable with this method.
Chipmunk$clone(deep = FALSE)
deep
Whether to make a deep clone.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.