def mousePressed(): pressed = world.getBody(mouseX, mouseY) if pressed == boxButton: myBox = FBox(40, 40) myBox.setPosition(width/4, 200) myBox.setRotation(random(TWO_PI)) myBox.setVelocity(0, 200) myBox.setFillColor(bodyColor) myBox.setNoStroke() world.add(myBox) elif pressed == circleButton: myCircle = FCircle(40) myCircle.setPosition(2*width/4, 200) myCircle.setRotation(random(TWO_PI)) myCircle.setVelocity(0, 200) myCircle.setFillColor(bodyColor) myCircle.setNoStroke() world.add(myCircle) elif pressed == polyButton: myPoly = FPoly() myPoly.vertex(20, 20) myPoly.vertex(-20, 20) myPoly.vertex(0, -20) myPoly.setPosition(3*width/4, 200) myPoly.setRotation(random(TWO_PI)) myPoly.setVelocity(0, 200) myPoly.setFillColor(bodyColor) myPoly.setNoStroke() world.add(myPoly)
def setup(): global world, pop, cage size(400, 400) smooth() Fisica.init(this) Fisica.setScale(10) world = FWorld() world.setEdges() world.remove(world.top) pop = createPop() pop.setPosition(width/2, height/2) pop.setBullet(True) world.add(pop) cage = createCage() cage.setPosition(width/2, height/2) cage.setRotation(PI/6) cage.setBullet(True) world.add(cage) for _ in range(10): c = FCircle(7) c.setPosition(width/2-10+random(-5, 5), height/2-10+random(-5, 5)) c.setBullet(True) c.setNoStroke() c.setFillColor(color(0xFF, 0x92, 0x03)) world.add(c) rectMode(CENTER)
def setup(): global boxButton, circleButton, polyButton, world size(400, 400) smooth() Fisica.init(this) world = FWorld() world.setEdges() world.remove(world.left) world.remove(world.right) world.remove(world.top) boxButton = FBox(40, 40) boxButton.setPosition(width/4, 100) boxButton.setStatic(True) boxButton.setFillColor(buttonColor) boxButton.setNoStroke() world.add(boxButton) circleButton = FCircle(40) circleButton.setPosition(2*width/4, 100) circleButton.setStatic(True) circleButton.setFillColor(buttonColor) circleButton.setNoStroke() world.add(circleButton) polyButton = FPoly() polyButton.vertex(20, 20) polyButton.vertex(-20, 20) polyButton.vertex(0, -20) polyButton.setPosition(3*width/4, 100) polyButton.setStatic(True) polyButton.setFillColor(buttonColor) polyButton.setNoStroke() world.add(polyButton)
def createSpider(): posX = random(mainSize/2, width-mainSize/2) posY = random(mainSize/2, height-mainSize/2) main = FCircle(mainSize) main.setPosition(posX, posY) main.setVelocity(random(-20,20), random(-20,20)) main.setFillColor(bodyColor) main.setNoStroke() main.setGroupIndex(2) world.add(main) mains.append(main) for i in range(legCount): x = legSize * cos(i*TWO_PI/3) + posX y = legSize * sin(i*TWO_PI/3) + posY leg = FCircle(mainSize/2) leg.setPosition(posX, posY) leg.setVelocity(random(-20,20), random(-20,20)) leg.setFillColor(bodyColor) leg.setNoStroke() world.add(leg) j = FDistanceJoint(main, leg) j.setLength(legSize) j.setNoStroke() j.setStroke(0) j.setFill(0) j.setDrawable(False) j.setFrequency(0.1) world.add(j)
def setup(): global world, pop, cage size(400, 400) smooth() Fisica.init(this) Fisica.setScale(10) world = FWorld() world.setEdges() world.remove(world.top) pop = createPop() pop.setPosition(width / 2, height / 2) pop.setBullet(True) world.add(pop) cage = createCage() cage.setPosition(width / 2, height / 2) cage.setRotation(PI / 6) cage.setBullet(True) world.add(cage) for _ in range(10): c = FCircle(7) c.setPosition(width / 2 - 10 + random(-5, 5), height / 2 - 10 + random(-5, 5)) c.setBullet(True) c.setNoStroke() c.setFillColor(color(0xFF, 0x92, 0x03)) world.add(c) rectMode(CENTER)
def createSpider(): posX = random(mainSize / 2, width - mainSize / 2) posY = random(mainSize / 2, height - mainSize / 2) main = FCircle(mainSize) main.setPosition(posX, posY) main.setVelocity(random(-20, 20), random(-20, 20)) main.setFillColor(bodyColor) main.setNoStroke() main.setGroupIndex(2) world.add(main) mains.append(main) for i in range(legCount): x = legSize * cos(i * TWO_PI / 3) + posX y = legSize * sin(i * TWO_PI / 3) + posY leg = FCircle(mainSize / 2) leg.setPosition(posX, posY) leg.setVelocity(random(-20, 20), random(-20, 20)) leg.setFillColor(bodyColor) leg.setNoStroke() world.add(leg) j = FDistanceJoint(main, leg) j.setLength(legSize) j.setNoStroke() j.setStroke(0) j.setFill(0) j.setDrawable(False) j.setFrequency(0.1) world.add(j)
def createPop(): b = FBox(6, 60) b.setFillColor(color(0x1F, 0x71, 0x6B)) b.setNoStroke() c = FCircle(20) c.setPosition(0, -30) c.setFillColor(color(0xFF, 0x00, 0x51)) c.setNoStroke() result = FCompound() result.addBody(b) result.addBody(c) return result