We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › How does this work
Page Index Toggle Pages: 1
How does this work? (Read 665 times)
How does this work?
May 6th, 2009, 4:19pm
 
I want to combine these two sketches together so the file called stars sits behind all the objects but on the background on the file called in space- how would i do this?

Stars:
void setup(){
 size(900,900);
 smooth();
 noLoop();
}
void draw(){
 background(0);
 for (int i=50; i<500; i++){
   drawX(int((#FCFF58)),int(random(10)),int(random(width))
   ,int(random(height)),10);
 }
}
void drawX(int gray, int weight, int x, int y, int dsize){
  stroke(gray);
  strokeWeight(weight);
  line(x,y,x+dsize,y+dsize);
  line(x+dsize,y,x,y+dsize);
 
}

In Space
float y=0.0;
PImage img;
PImage b;

void setup(){ size(900,800);
 img=loadImage("flag2.png");
  b=loadImage("Spaceship3.png");
 smooth ();
 
}

void draw () {
 background(0);
   background(0);

 
 fill(#FA2014);//planet

noStroke();
ellipse(y, 45, 100, 100);
noFill();

fill(#1242FA);
noStroke();
ellipse(y,200,170,170);
noFill();
 y=y+ 1;
// if (y>900)//y>height
//   y=0.0;
if (y>900){
  y=90;

 }

fill(255);//moon
noStroke();
ellipse(450,900,1000,900);
noFill();

 image(img,100,450,80,150);//Flag
 println(img.width);// prints the image width
 
  image(b,520,40,170,130);//spaceship
 println(b.width);// prints the image width

fill(#793937);
stroke(#793937);
strokeWeight(12);//ears
point(440,210); //top point
point(450,240); //left point
point(430,240); //right corner
point(440,270); //bottom point

line(440,210,450,240);//ears
line(440,210,430,240);
line(430,240,440,270);
line(450,240,440,270);

point(480,210); // ears-top point
point(470,240); //left point
point(490,240); //right corner
point(480,270); //bottom point

line(480,210,470,240);//ears
line(480,210,490,240);
line(490,240,480,270);
line(470,240,480,270);
noStroke();

rect(470,475,30,40); //legs
rect(420,475,30,40); //legs

noStroke();
fill(#793937);
stroke(#793937);
strokeWeight(10);
ellipse(460,300,73,80); //head
ellipse(460,415,109,150); //body
noFill();


fill(#672A2A);
ellipse(460,415,95,110); //inner body
noFill();
fill(#793937);
stroke(0);
strokeWeight(1);
arc(475, 311, 30, 30, PI/2, PI);//mouth
arc(445, 311, 30, 30, 0, PI/2);//mouth
noFill();


fill(#0A0000);
ellipse(445,290,10,7); //left eye
ellipse(480,290,10,7); //right eye

noFill();

fill(200);
ellipse(445,290,4,4); //left eye
ellipse(480,290,4,4); //right eye
noFill();

fill(255);
point(460,310); //middle of nose
point(400,310); //left top point
point(400,320); //left middle point
point(400,330); //left bottom point
stroke(255);
line(460,310,400,310);
line(460,310,400,320);
line(460,310,400,330);

point(460,310); //middle of nose
point(523,310); //left top point
point(523,320); //left middle point
point(523,330); //left bottom point

line(460,310,523,310);
line(460,310,523,320);
line(460,310,523,330);

fill(0);
noStroke();
ellipse(460,310,9,9); //nose

noFill();
noStroke();
stroke(0);
fill(255);
rect(456,322,3.5,5);//teeth
rect(461,322,3.5,5); //teeth

fill(#793937);
triangle(403,436,403,401,449,420);//arms
triangle(516,436,520,401,474,420);//arms

fill(255,100);
ellipse(460,273,177,157);

line(mouseX-5,mouseY,mouseX+5,mouseY);
line(mouseX,mouseY-5,mouseX,mouseY+5);
println("x "+mouseX+" :y "+mouseY);
}

Thanks
Re: How does this work?
Reply #1 - May 6th, 2009, 6:50pm
 
Don't worry i found a better way of doing stars!

Grin
Page Index Toggle Pages: 1