Showing posts with label abuzaineh. Show all posts
Showing posts with label abuzaineh. Show all posts

Tuesday, May 8, 2012

take the Sound File and create a new sentence from those words.

//Sound File preamble.wav and create a new sentence from those words.
 //The sentence you are to create is:
//We order the common people to perfect liberty.
 //The entire text of the Preamble is:
 //We the People of the United States, in Order to form a more perfect Union, establish Justice, insure
//domestic Tranquility, provide for the common defence, promote the general Welfare, and secure the
//Blessings of Liberty to ourselves and our Posterity, do ordain and establish this Constitution for the United
 //States of America.
http://www.cs.uic.edu/~i101/SoundFiles/preamble.wav




public class Lab14Babuze2
{

public static void main (String args[])
{
System.out.println("Begin Java Execution");
System.out.println("");


// put your Java Program here
String filename = FileChooser.pickAFile();
Sound s1 = new Sound (filename);

Sound s2 = crop (s1, 0, 15730);
Sound s3 = crop (s1, 55845, 65043);
Sound s4 = crop (s1, 15730, 17407);
Sound s5 = crop (s1, 189873, 193815);
Sound s6 = crop (s1, 17407, 26726);
Sound s7 = crop (s1, 63729, 66357);
Sound s8 = crop (s1, 77526, 85410);
Sound s9 = crop (s1, 270027,276597);


// crop the sounds
Sound s10 = join (s2, s3);
Sound s11 = join (s10, s4);
Sound s12 = join (s11, s5);
Sound s13 = join (s12, s6);
Sound s14 = join (s13, s7);
Sound s15 = join (s14, s8);
Sound s16 = join (s15, s9);



// Play the sounds using the "play command"
//s.play();

//esplore the sound in order to get the values
s16.explore();

System.out.println("");
System.out.println("End Java Execution");
}

// Start a method
public static Sound crop (Sound s1, int startIndex, int endIndex)
{
SoundSample[] ssarr1 = s1.getSamples();

// set length3 to the length of the shorter sound
int length3 = endIndex - startIndex ;
Sound s3 = new Sound (length3);
SoundSample[] ssarr3 = s3.getSamples();

int pos;

// copy over s1 into the beginning of s3
for ( pos = startIndex ; pos < endIndex ; pos++ )
{
int amplitude1 = ssarr1[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[ pos - startIndex ].setValue (amplitude1);
}

return s3;
}


public static Sound join (Sound s1, Sound s2)
{
SoundSample[] ssarr1 = s1.getSamples();
SoundSample[] ssarr2 = s2.getSamples();

// set length3 to the length of the shorter sound
int length3 = ssarr1.length + ssarr2.length ;
Sound s3 = new Sound (length3);
SoundSample[] ssarr3 = s3.getSamples();

int pos;

// copy over s1 into the beginning of s3
for ( pos = 0 ; pos < ssarr1.length ; pos++ )
{
int amplitude1 = ssarr1[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[pos].setValue (amplitude1);
}

// copy over s2 into the end of s3
for ( pos = 0 ; pos < ssarr2.length ; pos++ )
{
int amplitude2 = ssarr2[pos].getValue();

// store the new amplitude value into sounnd s3
ssarr3[ ssarr1.length + pos ].setValue (amplitude2);
}

return s3;
}

} // end of Template class

A Turtle Drawing in java

//use the Turtle class to draw a large multifaceted geometrical shape onto a picture. These modifications are
 //to add "something" to the image. Normally this would be to draw something in the foreground of an image
//that is just a scene.
//*** a specific image was used for this project.



import java.awt.Color;

  public class proj1

{


public static void main(String[] args)

{

// file chooser to pick an image.

String filename = FileChooser.pickAFile();
Picture p = new Picture(filename);

//creat turtles.

Turtle t = new Turtle(p);
Turtle t1 = new Turtle(p);

// set pen width for both turtles.

t.setPenWidth(2);
p.show();
t1.setPenWidth(3);
t1.penUp();
t1.turnLeft();
t1.forward(400);
t1.turn(-90);
t1.forward(265);
t1.penDown();

// locating the turtles usind penUp.

t.penUp();
t.turnRight();
t.forward(230);
t.turn(-90);
t.forward(22);
t.penDown();



// call a method to draw a rectangle
t1.penUp();
t1.turn(-90);
t1.forward(300);
t1.turn(-90);
t1.forward(300);
t1.turn(180);
t1.penDown();
drawRectangle (t1,100,500);



// Drawing a flag for the ship.
t1.turnRight();
t1.forward(100);
t1.turn(90);
t1.forward(300);
t1.turn(135);
t1.forward(80);
t1.turnRight();
t1.forward(80);
t1.penUp();
t1.turn(45);
t1.forward(300);

t1.penDown();

int i1=0;
while (i1<10)
{


// draw a star
t1.turn(36);
t1.forward(130);
t1.turn(144);
t1.forward(130);
t1.turn(144);
t1.forward(130);
t1.turn(144);
t1.forward(130);
t1.turn(144);
t1.forward(130);


i1=i1+1;
} // end while loop.





int i2 = 1;
int len;

while(i2 < 8)
{
len = i2 * 25 ;

// Call a method
drawHexagon (t, len);

t.penUp();
t.turn(-90);
t.forward(20);
t.turn(-90);
t.forward(15);
t.turn(180);
t.penDown();

i2=i2+1;
} // End of while loop


}

public static void drawHexagon ( Turtle t, int size)
{
int i;
i = 1;
// Meathod to draw a Hexagon.
while (i <= 6)
{

t.forward(size);
t.turn(360/6);

i=i+1;
}

}


public static void drawRectangle(Turtle t1,int sides, int length )
{

int i = 1;
while(i <= 4)
{
t1.forward(sides);
t1.turn(90);
t1.forward(length);
t1.turn(90);

i=i+1;
} // End of while Loop

}
}