Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
279 lines (216 sloc) 5.14 KB
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Fly high! </title>
<link rel="stylesheet" href="style.css" type="text/css" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" type="text/javascript"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript"></script>
</head>
<body>
<script src="processing-1.3.6.min.js"></script>
<script src="init_processing.js" type="text/javascript"></script>
<div id="header">
<canvas width="100%" height="100%" id="particle">
</canvas>
<div class="logo">
</div>
</div>
<script type="application/processing">
/* @pjs transparent=true; */
PFont droidSans;
ParticleSystem ps_clouds;
int frame;
PImage fly = new PImage;
PImage[] clouds = new PImage[5];
float gx = 0;
float gy = 0;
// Setup the Processing Canvas
void setup(){
size($('canvas').width(), $('canvas').height());
fly = loadImage("appengine.png");
//fly = loadImage("super.jpg");
clouds[0]= loadImage("cloud1.png");
clouds[1]= loadImage("cloud2.png");
clouds[2]= loadImage("cloud1.png");
clouds[3]= loadImage("cloud2.png");
clouds[4]= loadImage("cloud1.png");
frameRate(25);
droidSans = createFont("Droid Sans",32);
textFont(droidSans);
ps_clouds = new ParticleSystem(clouds, true);
smooth();
}
// Main draw loop
void draw(){
if($("#particle").is(":visible")) {
size($('canvas').width(), 250);
// Transparent canvas
background(0, 0, 0, 0);
ps_clouds.run();
if (ps_clouds.particles.isEmpty()) {
ps_clouds = new ParticleSystem(clouds, true);
}
image(fly, gx, gy);
frame++;
}
}
// A simple Particle class
class Particle {
Vector3D loc;
Vector3D vel;
Vector3D acc;
PImage img;
var left = false;
float r;
float timer;
// Constructor
Particle(Vector3D l, PImage p_image, var is_left, var is_cloud) {
acc = new Vector3D(0.05,0,0);
if (is_cloud){
the_vel = random(0, 2);
}
else {
the_vel = random(1, 3);
}
vel = new Vector3D(the_vel, 0, 1);
loc = l.copy();
r = 10.0;
timer = 1550.0;
img = p_image;
left = is_left;
}
void run() {
update();
render();
}
// Method to update location
void update() {
if (left){
loc.sub(vel);
}
else {
loc.add(vel);
}
timer -= 1.0;
}
// Method to display
void render() {
image(img, loc.x,loc.y);
}
// Is the particle still useful?
boolean dead() {
if (timer <= 0.0) {
return true;
} else {
return false;
}
}
}
class ParticleSystem {
ArrayList particles; // An arraylist for all the particles
Vector3D origin; // An origin point for where particles are birthed
ParticleSystem(PImage[] p_images, var is_clouds) {
particles = new ArrayList();
var lefty;
if (lefty) {
origin = new Vector3D(0, 0, 0);
}
else {
origin = new Vector3D(width, 0, 0);
}
for (int i = 0; i < p_images.length; i++) {
var dice = random(-20, 20);
var topped;
if (is_clouds) {
topped = random(-10, 40);
}
else {
topped = random(-10, 150);
}
if (dice > 0) {
origin = new Vector3D(width+random(0,50), topped, 1);
lefty = true;
}
else {
origin = new Vector3D(random(-200,0), topped, 1);
lefty = false;
}
particles.add(new Particle(origin, p_images[i], lefty, is_clouds));
}
}
void run() {
// Cycle through the ArrayList backwards b/c we are deleting
for (int i = particles.size()-1; i >= 0; i--) {
Particle p = (Particle) particles.get(i);
p.run();
if (p.dead()) {
particles.remove(i);
}
}
}
void addParticle(PImage a_image, Vector3D vel) {
particles.add(new Particle(origin, vel, a_image));
}
// A method to test if the particle system still has particles
boolean dead() {
if (particles.isEmpty()) {
return true;
} else {
return false;
}
}
}
public class Vector3D {
public float x;
public float y;
public float z;
Vector3D(float x_, float y_, float z_) {
x = x_; y = y_; z = z_;
}
Vector3D(float x_, float y_) {
x = x_; y = y_; z = 0f;
}
Vector3D() {
x = 0f; y = 0f; z = 0f;
}
public Vector3D copy() {
return new Vector3D(x,y,z);
}
public Vector3D copy(Vector3D v) {
return new Vector3D(v.x, v.y,v.z);
}
public void add(Vector3D v) {
x += v.x;
y += v.y;
z += v.z;
}
public void sub(Vector3D v) {
x -= v.x;
y -= v.y;
z -= v.z;
}
public Vector3D add(Vector3D v1, Vector3D v2) {
Vector3D v = new Vector3D(v1.x + v2.x,v1.y + v2.y, v1.z + v2.z);
return v;
}
}
void keyPressed() {
if (keyCode == RIGHT) {
gx += 2;
}
else if (keyCode == LEFT) {
gx -= 2;
}
else if (keyCode == UP) {
gy -= 2;
}
else if (keyCode == DOWN) {
gy += 2;
}
}
</script>
<div id="main">
</div>
</body>
</html>