xxxxxxxxxx
140
var linestars = [];
var balls = [];
function preload() {
ufoimage = loadImage("ufo.png");
earth = loadImage("earth.png");
moon = loadImage("moon.png");
crash = loadImage("crash.png");
linestar = loadImage("linestar.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
ufo1 = new ufo();
ufo2 = new ufo();
ufo3 = new ufo();
}
function draw() {
background(0);
//image(crash, 510, 430, 300, 300)
image(earth, 70, 520, 520, 280)
image(moon, 350, 100, 150, 150)
for (var i = 0; i < 5; i++) {
linestars[i] = new Stars();
}
for (var i = 0; i < linestars.length; i++) {
linestars[i].display();
linestars[i].move();
}
ufo1.move();
ufo1.display();
ufo2.move();
ufo2.display();
ufo3.move();
ufo3.display();
}
function Stars() {
this.x = random(0, width);
this.y = random(0, height);
this.size = random(30, 50);
this.display = function() {
image(linestar, this.x, this.y, this.size, this.size);
}
this.move = function() {
this.x = this.x + random(-30 / this.size, -20 / this.size);
}
}
function rocket() {
}
function ufo() {
this.x = random(100, 500);
this.y = random(100, 500);
this.radius = 20
this.speed = 2;
this.direction = 2;
this.col = color(255, 10, 20);
this.move = function() {
if (overCircle(this.x - 20, this.y, this.radius + 30)) {
if (mouseIsPressed == true) {
// background(114, 100, 72, 1);
this.x = mouseX
this.y = mouseY
noFill();
stroke(255);
strokeWeight(0.3);
for (var r = this.x - 80; r <= this.x+60; r = r + 280) {
//ellipse(r, this.y + random(40, height), 50, 10);
for(var w = 60; w < 200; w = w+20) {
ellipse(this.x, this.y+ random(40,height) , 60, 10);
}
}
noStroke();
} else if (mouseIsPressed == false) {
this.x = this.x + random(-this.speed * 1, this.speed * 1);
this.y = this.y + random(-this.speed * 1, this.speed * 1);
}
} else if (overCircle(this.x, this.y, this.radius + 500)) {
this.x = this.x + random(-this.speed, this.speed);
this.y = this.y + random(-this.speed, this.speed);
}
}
this.display = function() {
imageMode(CENTER);
image(ufoimage, this.x, this.y);
}
function overCircle(x, y, radius) {
if (dist(x, y, mouseX, mouseY) < radius) {
return true;
} else {
return false;
}
}
}
function Circle()
{
this.x = random()*width;
this.y = random()*height;
this.diameter = 15;
this.color = img.get(this.x,this.y);
this.speed = 0;
this.move = function()
{
this.x += random(-this.speed, this.speed);
this.y += random(-this.speed, this.speed);
}
this.display = function()
{
fill(this.color);
strokeWeight(1);
ellipse(this.x,this.y,this.diameter,this.diameter);
};
}