joinShapes()

Purpose

Join two shapes drawn using drawShape() together

Description

Create a new shape by combining two other shapes

Syntax

newShape = joinShapes( shape1, shape2 )

Arguments

newShape Handle which stores the newly created shape

shape1 Handle which stores the first shape to join

shape2 Handle which stores the second shape to join

Example

w = gwidth()
h = gheight()
radius = 100

shape1 = createCircle( w / 3, h / 2, radius, 360 )
shape2 = createCircle( w - w / 3, h / 2, radius, 360 )
shape3 = 0

join = false
dist = 0

loop
    clear( grey )
    j = controls( 0 )

    if !join then
        shape1Location = getShapeLocation( shape1 )
        shape2Location = getShapeLocation( shape2 )
        dist = distance( shape1Location, shape2Location )
    endif

    if dist < radius * 2 and !join then
        shape3 = joinShapes( shape1, shape2 )
        deleteShape( shape1 )
        deleteShape( shape2 )
        join = true
    endif

    if join then
        moveShape( shape3, { j.lx, -j.ly } * 6 )
        drawShape( shape3 )
    else
        moveShape( shape1, { j.lx, -j.ly } * 6 )
        drawShape( shape1 )
        drawShape( shape2 )
    endif

    update()
repeat

Associated Commands

createLine(), createLineStrip(), createCurve(), createCircle(), createPoly(), createTriangle(), createStar(), createBox(), copyShape(), deleteShape(), drawShape(), moveShape(), getShapeBounds(), getShapeLocation(), setShapeLocation(), getShapeRotation(), setShapeRotation(), rotateShape(), getShapeScale(), setShapeScale(), scaleShape(), getShapeTint(), setShapeTint(), numVerts(), getVertex(), setVertex(), getVertexColour(), setVertexColour(), getVertexLineThickness(), setVertexLineStyle(), setShapeColour(), setShapeLineStyle(), setShapeScaleModeLocal()