Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Final project code - Atmanna (Wish)
import processing.serial.*;
import cc.arduino.*;
Arduino arduino; //creates arduino object
int sensor = 0;
int read;
int numFrames = 11;
int currentFrame = 0;
PImage[] dandi = new PImage[numFrames];
boolean drawBase = true;
boolean drawFinal = false;
int blowCounter = 0;
int startTime;
float smoothedRead=0;
BalloonArray balloons = new BalloonArray();
Balloon newBalloon;
boolean mouseDown = false;
boolean inflate = false;
PImage seedimg;
PImage bg;
PImage dand;
PFont font;
void setup() {
size(800, 800);
font = createFont("LoveYaLikeASister.ttf", 40);
arduino = new Arduino(this, Arduino.list()[1], 57600); //sets up arduino
arduino.pinMode(sensor, Arduino.INPUT);//setup pins to be input (A0 =0?)
seedimg = loadImage("seed.png");
bg = loadImage("blue_sky_grass.jpg");
for (int i = 0; i < dandi.length; i++) {
dandi[i] = loadImage("dandelion"+i+".png");
}
println(dandi.length);
}
void draw () {
background(bg);
imageMode(CENTER);
image(dandi[10], width/2, height/2+100);
read=arduino.analogRead(sensor);
smoothedRead+=(read-smoothedRead)*.01;
println(smoothedRead);
if (inflate)
{
newBalloon.render(); // Only grow the balloon, ignore the floating
}
balloons.run();
textFont(font);
text("Atmanna (Wish)", 30, 50);
if (drawBase == true) {
image(dandi[0], width/2, height/2+100);
}
if (drawFinal == true) {
image(dandi[10], width/2, height/2+100);
}
if (smoothedRead > 170 ) {
drawBase = false;
playAnim();
blowCounter += 1;
if (blowCounter == 10) {
drawFinal = true;
}
}
}
void keyReleased() {
if (key == 's') {
blowCounter = 0;
setup();
}
}
void playAnim() {
//if (read > 200) {
for (int i = 0; i < dandi.length; i++) {
//if (blowCounter < 11) {
image(dandi[i], width/2, height/2+100);
for (int x = 0; x < random(0, 3); x++) {
newBalloon = new Balloon(width/2, height/2+100);
balloons.add(newBalloon);
}
}
}
class Balloon //Create balloon object
{
float x = width/2;
float y = height/2;
float xv = -3+random(6);
float yv = -random(4);
float maxYV = 20;
float floating = 0.05; //Float rate
float friction = 1;
float radius = 0;
color c = color(random(255), random(255), random(255), 80);
Balloon() {
}
Balloon(float xp, float yp)
{
x = xp;
y = yp;
}
Balloon(float xp, float yp, float xvel, float yvel)
{
this(xp, yp);
xv = xvel;
yv = yvel;
}
public void update()
{
if ((yv < maxYV))
{
yv -= floating*.2;
}
yv *= friction;
y += yv;
x += xv;
/* If you want a ceiling, uncomment this
if (y <= 0 + radius) {
xv = 0;
yv = 0;
y = 0 + radius;
}
*/
}
void render()
{
image(seedimg, x, y);
}
void run()
{
update();
render();
}
}
class BalloonArray
{
ArrayList Balloons = new ArrayList();
BalloonArray() {
}
void add(Balloon b)
{
Balloons.add(b);
}
void removeAll()
{
Balloons.clear();
}
void run()
{
for (int i = 0; i < Balloons.size (); i++)
{
Balloon b = (Balloon)Balloons.get(i);
b.run();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment