PROGRAM: 1
DATE: ......................
ROTATING AN IMAGE
AIM:
To write a program to rotate an image.
ALGORITHM:
Step-1: Import the Packages.
Step-2: Declare the variables and assign values to them.
Step-3: Draw the lines.
Step-4: assign values to the matrices with the trigonometric values of r (where
r=30*3.14/180)
Step-5: For loop is used to get the values for the P1 matrix.
Step-6: The Values for the reflected coordinates are determined from the P1 Matrix.
Step-7: Draw the lines.
Step-8: Stop the process
PROGRAM:
import java.math.*;
import java.util.*;
import java.awt.*;
import java.applet.*;
public class rotation extends Applet
{
public void paint(Graphics g)
{
int i,j,k;
double r=30*3.14/180;
int x1,y1,x2,y2,x3,y3,x11,y11,x22,y22,x33,y33;
x1=150;
y1=200;
x2=250;
y2=250;
x3=230;
y3=270;
g.drawLine(x1,y1,x2,y2);
g.drawLine(x2,y2,x3,y3);
g.drawLine(x1,y1,x3,y3);
double p1[][]=new double[3][3];
int p[][]=new int[3][3];
double t[][]=new double[3][3];
t[0][0]=t[1][1]=Math.cos(r);
t[0][1]=-(Math.sin(r));
t[1][0]=Math.sin(r);
t[2][2]=1;
t[0][2]=t[1][2]=t[2][0]=t[2][1]=0;
p[0][0]=x1;
p[0][1]=x2;
p[0][2]=x3;
p[1][0]=y1;
p[1][1]=y2;
p[1][2]=y3;
p[2][0]=p[2][1]=p[2][2]=1;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
p1[i][j]=0;
for(k=0;k<3;k++)
{
p1[i][j]=p1[i][j]+t[i][k]*p[k][j];
}
}
System.out.println();
}
x11=(int)p1[0][0];
x22=(int)p1[0][1];
x33=(int)p1[0][2];
y11=(int)p1[1][0];
y22=(int)p1[1][1];
y33=(int)p1[1][2];
g.drawLine(x11,y11,x22,y22);
g.drawLine(x22,y22,x33,y33);
g.drawLine(x11,y11,x33,y33);
}
}
/*<applet code = "rotation.class" width="800" height="800"> </applet>*/
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 2
DATE: ......................
DROPPING WORDS ONE BY ONE
AIM:
To write a program to drop each word of a sentence one by one from the top.
ALGORITHM:
Step-1: Import the Packages.
Step-2: Declare the variables and get the input from the user.
Step-3: Compile a pattern
Step-4: Match the compiled pattern
Step-5: Using a while loop find the matched pattern and if the matched pattern is
found then print them by grouping it.
Step-6: Create an exception to catch the error.
PROGRAM:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.io.*;
public class test
{
public static void main(String[]args)
{
try
{
String s1;
DataInputStream in=new DataInputStream(System.in);
System.out.println("\nEnter the value of String S1:");
s1=in.readLine();
Pattern p = Pattern.compile("[a-zA-Z]+");
Matcher m1=p.matcher(s1);
System.out.println("Words from the String\""+s1+"\":");
while(m1.find())
{
System.out.println(m1.group());
}}
catch(Exception e)
{
System.out.println(""+e.toString());
}}}
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 3
DATE: ......................
DDA ALGORITHM
AIM:
To write a program to drop a line using the DDA Algorithm.
ALGORITHM:
Step-1: Import the packages.
Step-2: Declare x1,y1,x2,y2,dx,dy,x,y,k,steps as double variables.
Step-3: Get input from the user.
Step-4: Calculate the dx and dy.
Step-5: If Abs (dx) > Abs (dy)
Then steps = Abs (dx)
Else
Step-6: xc=(dx/steps);
yc=(dy/steps);
Step8: In for loop,
assign x=x+xc;
assign y=y+yc;
Implement fill Oval.
PROGRAM:
import java.applet.*;
import java.awt.*;
import java.util.*;
public class Dda extends Applet
{
double x1,y1,x2,y2;
double dx,dy,steps,x,y,k;
Scanner sc =new Scanner(System.in);
double xc,yc;
public Dda()
{
System.out.println("Enter x1 y1");
x1 = sc.nextDouble();
y1 = sc.nextDouble();
System.out.println("Enter x2 y2");
x2 = sc.nextDouble();
y2 = sc.nextDouble();
}
public void paint(Graphics g)
{
try{
dx=x2-x1;
dy=y2-y1;
if(Math.abs(dx)>Math.abs(dy))
steps=Math.abs(dx);
else
steps=Math.abs(dy);
xc=(dx/steps);
yc=(dy/steps);
for(k=1;k<=steps;k++)
{
x=x+xc;
y=y+yc;
g.fillOval((int)x,(int)y,5,5);
}
}catch(Exception e){}
}
}
/*<applet code = "Dda.class" width="1000" height="1000"></Applet>*/
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 4
DATE: ......................
MOVING A CAR
AIM:
To write a program to move a car with sound effects.
ALGORITHM:
Step-1: Import the packages.
Step-2: Declare necessary variables.
Step-3: Define a function called Sleep with try, catch exception.
Step-4: Define Variables x and y under the function called init.
Step-5: Declare a function called paint. Under this function implement the
following :
1.
Set the background color
2.
Set Color to c1 and c2.
3.
To draw the body of the car use fillRoundRect.
4.
To draw the driver use fillArc.
5.
To draw the window use fillRect.
6.
To draw the wheel use fillOval.
7.
Use set color to define the colors for the appropriate shapes
drawn above.
Step-6: update x by x = x+10
Step-7: If x+100 < width
Then repaint.
Step-8: Else
Call repaint
Update x = 20 and y = y+30
Step-9: Stop the process.
PROGRAM:
import java.applet.*;
import java.awt.*;
import java.lang.*;
/*<applet code="move"height=800 width=700>
</applet>*/
public class move extends Applet
{
int x;int y;int w;
void sleep()
{
try
{
Thread.sleep(30);
}
catch(Exception ex)
{
}
}
public void init()
{
y=30;
x=20;
}
public void paint(Graphics g)
{
setBackground(Color.cyan);
w=getWidth();
Color c1 = new Color(20,160,200);
Color c2 = new Color(200,60,200);
g.setColor(c1);
g.drawLine(0,y+75,w,y+75);
g.setColor(c2);
g.fillRoundRect(x,y+20,100,40,5,5);
g.fillArc(x+90,y+20,20,40,270,180);
g.setColor(c1);
g.fillRoundRect(x+10,y,70,25,10,10);
g.setColor(Color.white);
g.fillRect(x+20,y+5,20,25);
g.fillRect(x+50,y+5,20,25);
g.setColor(Color.black);
g.fillRoundRect(x+55,y+10,10,20,10,10);
g.fillOval(x+10,y+50,25,25);
g.fillOval(x+60,y+50,25,25);
g.setColor(Color.white);
g.fillOval(x+15,y+55,10,10);
g.fillOval(x+65,y+55,10,10);
x=x+10;sleep();
if(x+100<w) { repaint();}
else
{
repaint();x=20;y+=30;
}
}
}
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 5
DATE: ......................
BOUNCING A BALL
AIM:
To write a program to bounce a ball and move it with sound effect.
ALGORITHM:
Step-1: Import the packages.
Step-2: Declare variables and get the functions in text style.
Step-3: Draw the ball inside the function called init.
Step-4: Draw a circle and give movement using the different coordinates to
bounce it.
Step-5: Stop the process.
PROGRAM:
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
/*<applet code="bounce.class" height=900 width=900></applet>*/
class Ball
{
int x,y,radius,dx,dy;
Color BallColor;
public Ball(int x, int y,int radius, int dx,int dy,Color bColor)
{
this.x=x;
this.y=y;
this.radius=radius;
this.dx=dx;
this.dy=dy;
BallColor=bColor;
}
}
public class bounce extends Applet implements Runnable
{
Ball redBall;
public void init()
{
redBall=new Ball(250,80,50,2,4,Color.red);
Thread t=new Thread(this);
t.start();
}
public void paint(Graphics g)
{
g.setColor(redBall.BallColor);
setBackground(Color.green);
g.setColor(redBall.BallColor);
g.fillOval(redBall.x, redBall.y, redBall.radius, redBall.radius);
g.drawLine(150,400,50,500);
g.drawLine(150,400,450,400);
g.drawLine(50,500,350,500);
g.drawLine(450,400,350,500);
g.drawRect(50,500,20,100);
g.drawRect(330,500,20,100);
g.drawLine(450,400,450,500);
g.drawLine(430,500,450,500);
g.drawLine(430,500,430,420);
}
public void run()
{
while(true)
{
try
{
displacementOperation(redBall);
Thread.sleep(20);
repaint();
}
catch(Exception e)
{
}
}
}
public void displacementOperation(Ball ball)
{
if(ball.y>=400||ball.y<=0)
{
ball.dy=-ball.dy;
}
ball.y=ball.y+ball.dy;
}
}
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 6
DATE: ......................
INSIDE OR OUTSIDE OR ON A POLYGON
AIM:
To write a program to test whether a given pixel is inside or outside or on a
polygon.
ALGORITHM:
Step-1: Import the packages.
Step-2: Declare the variables and get the window coordinates
Step-3: create a function to get the coordinates values of the line x and y and
movement of clipping before and after clippings.
Step-4: Use looping statements to draw lines using pixel points until it reaches
the extract points.
Step-5: Stop the process.
PROGRAM:
import java.util.Date;
import java.util.Scanner;
public class Polygon
{
public static void main(String args[])
{
int desirednumber=1;
System.out.println("Program to check if a given point lies inside or outside of any
polygon");
Scanner a=new Scanner(System.in);
System.out.println("Enter the number of sides of the polygon");
int side=a.nextInt();
if(side<=2)
{
System.out.println("You have not formed a polygon.So using this program is of no
meaning.Run it again with a valid number of sides");
}
else
{
double x[]=new double[side];
double y[]=new double[side];
double lengthtopoint[]=new double[side];
double sidelength[]=new double[side];
double angles[]=new double[side];
for(int u=0;u<=desirednumber;u++)
{
System.out.println("\nEnter the"+(u+1)+"coordinate for which you need to check");
System.out.println("Xcheck=");
double xcheck=a.nextDouble();
System.out.println("Ycheck=");
double ycheck=a.nextDouble();
for(int i=0;i<side;i++)
{
System.out.println("Enter x for vertex "+i);
x[i]=a.nextDouble();
System.out.println("Enter y for vertex "+i);
y[i]=a.nextDouble();
lengthtopoint[i]=Math.sqrt(((x[i]-xcheck)*(x[i]-xcheck))+((y[i]-ycheck)*(y[i]-ycheck)));
System.out.println("List of all coordinates");
for(int j=0;j<side;j++)
{
System.out.println("Coordinates of vertex "+j+"="+x[j]+","+y[j]);
}
for(int k=0;k<side-1;k++)
{
sidelength[k]=Math.sqrt(((x[k+1]-x[k])*(x[k+1]-x[k]))+((y[k+1]-y[k])*(y[k+1]-y[k])));
}
sidelength[side-1]=Math.sqrt(((x[0]-x[side-1])*(x[0]-x[side-1]))+((y[0]-y[side-1])*(y[0]-
y[side-1])));
for(int l=0;l<side-1;l++)
{
angles[1]=((180/(Math.PI)))*Math.acos(((lengthtopoint[1]*lengthtopoint[1])+
(lengthtopoint[1+1]*lengthtopoint[1+1])-(sidelength[1]*sidelength[1]))/
(2*lengthtopoint[1]*lengthtopoint[1+1]));
}
angles[side-1]=((180/(Math.PI)))*Math.acos(((lengthtopoint[side-
1]*lengthtopoint[side-1])+(lengthtopoint[0]*lengthtopoint[0])-(sidelength[side-
1]*sidelength[side-1]))/(2*lengthtopoint[side-1]*lengthtopoint[0]));
double sum=0;
for(int m=0;m<side;m++)
{
sum=sum+angles[m];
}
System.out.println("The sum of all the angles is "+sum);
if(sum==360)
{
System.out.println("The point"+(xcheck)+","+(ycheck)+"lies inside the polygon");
}
else if(sum<360)
System.out.println("The point"+(xcheck)+","+(ycheck)+"lies outside the polygon");
}
}
}
}
}
OUTPUT:
RESULT:
Thus, the above program has been verified and executed successfully.
PROGRAM: 7
DATE: ......................
CREATION OF SUN FLOWER
AIM:
To Create a Sunflower using GIMP.
ALGORITHM:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size.
Step 3: Create a Layer
Step 4: Draw an ellipse by setting the ellipse select tool from the toolbox.
Step 5: Fill the required color using bucket fill tool.
Step 6: Right click on the layer created and select merge down.
Step 7: Right click on the layer copy and select duplicate layer.
Step 8: Press Shift + R to Rotate.
Step 9: Keep the cursor in the Centre position of ellipse and then adjust the
angle of rotation.
Step 10: Repeat the steps for more petals.
OUTPUT:
RESULT:
The program is done and the output is obtained.
PROGRAM : 8 ANIMATED PLANE FLYING IN THE CLOUD
DATE:.......................
Aim:
To create an animated plane flying in the clouds using GIMP
Algorithm:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size.
Step 3: Open an image with cloud background
Step 4: Click Filters -> Animation -> Rippling to set number of Frames.
Step 5: Select the Selection Tool to draw a plane and copy the plane and
make invisible to frame 1 alone and paste it.
Step 6: Again Copy the plane and make visible to all frames except frame
2and paste the plane in frame 2.
Step 7: Repeat the Process to all frames.
Step 8: Click Filter - > Animation - > Playback.
Step 9: Run the Process.
Output:
Result:
The program is done and the output is obtained.
PROGRAM : 9 PLASTIC SURGERY FOR NOSE
DATE:.................
.
Aim:
To Create Plastic Surgery for the Nose using GIMP.
Algorithm:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size.
Step 3: Select the Nose by selecting the free select tool from the toolbox.
Step 4: Select Shift+T to modify the nose by scaling the width and height of
the nose.
Step 5: Move the nose using move tool from the toolbox.
Step 6: Smudge the nose using smudge tool from the toolbox.
Step 7: Compare the original image with modified image.
Step 8: Save the modified image.
Step 9: Stop the Process.
Output:
Result:
The program is done and the output is obtained.
PROGRAM : 10 SEE THROUGH THE TEXT
DATE:....................
.
Aim:
To Create See through the Text using GIMP.
Algorithm:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size.
Step 3: Fill the color at the background by using bucket tool.
Step 4: Select the text tool and type the content change the font color and
size by selecting the text.
Step 5: By using Fuzzy tool, select the word by pressing the shift key.
Step 6: Drag the text layer and keep it below the image layer
Step 7: Right click on the image layer and select add layer mask ->
selection - > click on add, see through the text has been created.
Output:
Result:
The program is done and the output is obtained.
PROGRAM : 11 WEB PAGE CREATION
DATE:......................
Aim:
To Create a Webpage using GIMP.
Algorithm:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size and make a
square image to the selected area.
Step 3: Again select the selection tool and insert another image in the right
side.
Step 4: Select text tool and type the content, change the font color and size
by selecting the text.
Step 5: Select the Selection Tool and Insert a text as like the button in
webpage.
Step 6: Webpage has been created.
Output:
Result:
The program is done and the output is obtained.
PROGRAM: 12 CHANGING BLACK & WHITE TO COLOR IMAGE
DATE:.......................
Aim:
To Changing Black & White to Color Image using GIMP.
Algorithm:
Step 1: Open GIMP Image Editor
Step 2: Select File -> New - > Template, Select the Image Size.
Step 3: By using Fuzzy tool, select the particular area that you want to
color.
Step 4: Create a layer.
Step 5: Select mode as soft light or normal, then color those selected area.
Step 6: Repeat the step 3,4 and 5 for the coloured image.
Output:
Black & White Image
COLOR IMAGE
Result:
The program is done and the output is obtained.