#creativePact Day 21
#creativePact Here is yesterday’s code but now the second analog stick is also in use. I’d like to change this to make the swarm attracted to whichever analog stick position is nearest. Maybe tomorrow.
import procontroll.*; import net.java.games.input.*; Mover[] mover = new Mover[400]; ControllIO controllIO; ControllDevice joypad; ControllStick stick1; ControllStick stick2; ControllButton buttonX; ControllButton buttonC; ControllButton buttonT; ControllButton buttonS; ControllButton buttonL1; ControllButton buttonL2; ControllButton buttonL3; ControllButton buttonR1; ControllButton buttonR2; ControllButton buttonR3; ControllButton buttonSelect; ControllButton buttonStart; ControllButton buttonUp; ControllButton buttonDown; ControllButton buttonLeft; ControllButton buttonRight; void setup() { size(640, 480); smooth(); background(0); controllIO = ControllIO.getInstance(this); joypad = controllIO.getDevice("Twin USB Joystick"); stick1 = joypad.getStick(0); stick2 = joypad.getStick(1); buttonT = joypad.getButton(0); buttonC = joypad.getButton(1); buttonX = joypad.getButton(2); buttonS = joypad.getButton(3); for (int i = 0; i < mover.length; i++) { mover[i] = new Mover(); } } void draw() { background(180, 100, 180); for (int i = 0; i < mover.length; i++) { mover[i].update(); mover[i].display(); mover[i].checkEdges(); } } class Mover { PVector location; PVector velocity; PVector acceleration; float topspeed; PVector location1; PVector velocity1; PVector acceleration1; float topspeed1; float xsticka1; float ysticka1; float xsitcka2; float ysticka2; float xstickb1; float ystickb1; float xsitckb2; float ystickb2; Mover() { location = new PVector(random(width), random(height)); velocity = new PVector(0, 0); topspeed = 5; location1 = new PVector(random(width), random(height)); velocity1 = new PVector(0, 0); topspeed1 = 5; } void update() { float xsticka1 = stick2.getTotalY() + height/2; float ysticka1 = stick2.getTotalX() + width/2; float xsticka2 = constrain(xsticka1, 0, width); float ysticka2 = constrain(ysticka1, 0, height); float xstickb1 = stick1.getTotalX() + height/2; float ystickb1 = stick1.getTotalY() + width/2; float xstickb2 = constrain(xstickb1, 0, width); float ystickb2 = constrain(ystickb1, 0, height); PVector mouse = new PVector(xsticka2, ysticka2); PVector mouse1 = new PVector(xstickb2, ystickb2); PVector dir = PVector.sub(mouse, location); PVector dir1 = PVector.sub(mouse1, location1); dir.normalize(); dir1.normalize(); if (buttonT.pressed() == true) { dir.mult(0.000001); } else if (buttonC.pressed() == true) { dir.mult(1); } else if (buttonX.pressed() == true) { dir.mult(5); } else if (buttonS.pressed() == true) { dir.mult(0.8); } else { dir.mult(0.2); }; if (buttonT.pressed() == true) { dir1.mult(0.000001); } else if (buttonC.pressed() == true) { dir1.mult(1); } else if (buttonX.pressed() == true) { dir1.mult(5); } else if (buttonS.pressed() == true) { dir1.mult(0.8); } else { dir1.mult(0.2); } acceleration = dir; acceleration1 = dir1; velocity.add(acceleration); velocity.limit(topspeed); location.add(velocity); velocity1.add(acceleration1); velocity1.limit(topspeed1); location1.add(velocity1); } void display() { stroke(location.x, location.y, location.y); fill(location.x, location.y, location.y); ellipse(location.x, location.y, 2, 2); stroke(location1.x, location1.y, location1.y); fill(location1.x, location1.y, location1.y); ellipse(location1.x, location1.y, 2, 2); } void checkEdges() { if ((location.x > width) || (location.x < 0)) { velocity.x = velocity.x * -1; } if ((location.y > height) || (location.y < 0)) { velocity.y = velocity.y * -1; } if ((location1.x > width) || (location1.x < 0)) { velocity1.x = velocity1.x * -1; } if ((location1.y > height) || (location1.y < 0)) { velocity1.y = velocity1.y * -1; } } }