import java.applet.Applet; import java.awt.*; import ccj.TextInputStream; public class treeandsnow extends java.applet.Applet { Font font1 = new Font("Helvetica", Font.BOLD, 72); Font font2 = new Font("Helvetica", Font.BOLD, 72); Font font3 = new Font("Helvetica", Font.BOLD, 24); public void paint(Graphics g) { setBackground(Color.blue); dataInput(g); }//End of method paint void dataInput(Graphics g) { snowflakes(g); char charInput; int xcoord, ycoord, size; String message = new String(""); TextInputStream input = new TextInputStream("input.txt"); if(input.fail()) input.close(); else { charInput = input.readCh(); while(charInput != '.') { switch(charInput) { case 'T': { input.readCh(); xcoord=input.readInt(); input.readCh(); ycoord=input.readInt(); input.readCh(); size=input.readInt(); input.readLine(); if((xcoord >=0) &&(ycoord >= 0)) tree(g,xcoord,ycoord,size); };break; case 'M': { input.readCh(); xcoord=input.readInt(); input.readCh(); ycoord=input.readInt(); input.readCh(); message = input.readWord(); input.readLine(); if((xcoord >=0) &&(ycoord >= 0)) title(g,xcoord,ycoord,message); };break; case 'P': { input.readCh(); xcoord=input.readInt(); input.readCh(); ycoord=input.readInt(); if((xcoord >=0) &&(ycoord >= 0)) present(g,xcoord,ycoord); };break; case 'S': { input.readCh(); xcoord=input.readInt(); input.readCh(); ycoord=input.readInt(); if((xcoord >=0) &&(ycoord >= 0)) snowman(g,xcoord,ycoord); };break; } // end switch charInput = input.readCh(); } // end while input.close(); } // end else //tree(g,tree_bl_x,tree_bl_y,tree_size); }//End of method dataInput() void title(Graphics g,int x, int y, String message) { g.setColor(Color.black); g.setFont(font2); g.drawString(message, x,y); g.setColor(Color.green); g.setFont(font1); g.drawString(message, (x-4),(y-4)); }//End of method title void tree(Graphics g,int x,int y,int size) { int exes[] = { size*x,size*(x+50),size*(x+76),size*(x-25)}; int whys[] = { size*y,size*y,size*(y-20),size*(y-20)}; int pts = exes.length; Polygon poly = new Polygon(exes,whys,pts); g.setColor(Color.black); g.fillPolygon(poly); int exes_2[] = { size*(x+15),size*(x+35),size*(x+35),size*(x+15)}; int whys_2[] = { size*(y-20),size*(y-20),size*(y-40),size*(y-40)}; int pts2 = exes_2.length; Polygon trunk = new Polygon(exes_2,whys_2,pts2); Color brown = new Color(1.0F,0.5F,0.0F); g.setColor(brown); g.fillPolygon(trunk); int exes_3[] = { size*(x-65),size*(x+115),size*(x+75),size*(x+85),size*(x+45),size*(x+55),size*(x+25),size*(x-5),size*(x+5),size*(x-35),size*(x-25)}; int whys_3[] = { size*(y-40),size*(y-40),size*(y-80),size*(y-80),size*(y-120),size*(y-120),size*(y-160),size*(y-120),size*(y-120),size*(y-80),size*(y-80)}; int pts3 = exes_3.length; Polygon tree = new Polygon(exes_3,whys_3,pts3); g.setColor(Color.green); g.fillPolygon(tree); star(g,x,y,size); decorations(g,x,y,size); } void snowflakes(Graphics g) { int number; for(int i =0;i<1000;i++) { int firstx = 1 + (int)(Math.random()*600); int firsty = 1 + (int)(Math.random()*600); g.setColor(Color.white); g.setFont(font3); g.drawString("*", firstx,firsty); } } void star(Graphics g,int x,int y,int size) { int exes_4[] = {size*(x+10),size*(x+40),size*(x+25)}; int whys_4[] = {size*(y-150),size*(y-150),size*(y-170)}; int pts4 = exes_4.length; Polygon star = new Polygon(exes_4,whys_4,pts4); g.setColor(Color.yellow); g.fillPolygon(star); int exes_5[] = {size*(x+10),size*(x+40),size*(x+25)}; int whys_5[] = {size*(y-165),size*(y-165),size*(y-145)}; int pts5 = exes_5.length; Polygon star2 = new Polygon(exes_5,whys_5,pts5); g.setColor(Color.yellow); g.fillPolygon(star2); }//End of Method Star void decorations(Graphics g,int x,int y, int size) { //First Set of Decorations g.setColor(Color.yellow); g.drawArc(size*(x+5),size*(y-130),size*40,size*20,180,180); g.setColor(Color.red); g.drawArc(size*(x+5),size*(y-130),size*40,size*22,180,180); g.setColor(Color.blue); g.drawArc(size*(x+5),size*(y-130),size*40,size*18,180,180); //Second Set of Decorations. g.setColor(Color.cyan); g.drawArc(size*(x-25),size*(y-90),size*100,size*20,180,180); g.setColor(Color.magenta); g.drawArc(size*(x-25),size*(y-90),size*100,size*22,180,180); g.setColor(Color.blue); g.drawArc(size*(x-25),size*(y-90),size*100,size*18,180,180); //Third set of decorations g.setColor(Color.red); g.fillOval(size*(x+50),size*(y-120),size*10,size*10); g.fillOval(size*(x-10),size*(y-120),size*10,size*10); g.setColor(Color.orange); g.fillOval(size*(x+80),size*(y-80),size*10,size*10); g.fillOval(size*(x-40),size*(y-80),size*10,size*10); Color purple = new Color(1.0F,0.0F,1.0F); g.setColor(purple); g.fillOval(size*(x+110),size*(y-40),size*10,size*10); g.fillOval(size*(x-70),size*(y-40),size*10,size*10); } void present(Graphics g,int x,int y) { //int x = 20; //int y = 270; g.setColor(Color.green); g.fillRect(x, (y-60), 60, 60); Color c = new Color(200,250,0); g.setColor(c); int exes[] = {x, (x+30), (x+90), (x+60)}; int whys[] = {(y-60), (y-90), (y-90), (y-60)}; int pts = exes.length; Polygon poly = new Polygon(exes, whys, pts); g.fillPolygon(poly); g.setColor(Color.orange); int newExe[] = {(x+60), (x+90), (x+90), (x+60)}; int newWhys[] = {(y-60), (y-90), (y-30), y, (y-60)}; int newPts = newExe.length; Polygon newPoly = new Polygon(newExe, newWhys, newPts); g.fillPolygon(newPoly); g.setColor(Color.red); int ribbon1Exe[] = {(x+20), (x+40), (x+40), (x+20)}; int ribbon1Whys[] = {(y-60), (y-60), y, y}; int ribbon1Pts = ribbon1Exe.length; Polygon ribbon1Poly = new Polygon(ribbon1Exe, ribbon1Whys, ribbon1Pts); g.fillPolygon(ribbon1Poly); int ribbon2Exe[] = {x, (x+60), (x+60), x}; int ribbon2Whys[] = {(y-40), (y-40), (y-20), (y-20)}; int ribbon2Pts = ribbon2Exe.length; Polygon ribbon2Poly = new Polygon(ribbon2Exe, ribbon2Whys, ribbon2Pts); g.fillPolygon(ribbon2Poly); int ribbon3Exe[] = {(x+20), (x+50), (x +70), (x+40)}; int ribbon3Whys[] = {(y-60), (y-90), (y-90), (y-60)}; int ribbon3Pts = ribbon3Exe.length; Polygon ribbon3Poly = new Polygon(ribbon3Exe, ribbon3Whys, ribbon3Pts); g.fillPolygon(ribbon3Poly); int ribbon4Exe[] = {(x+10), (x+20), (x+80), (x+70)}; int ribbon4Whys[] = {(y-70), (y-80), (y-80), (y-70)}; int ribbon4Pts = ribbon4Exe.length; Polygon ribbon4Poly = new Polygon(ribbon4Exe, ribbon4Whys, ribbon4Pts); g.fillPolygon(ribbon4Poly); int ribbon5Exe[] = {(x+70), (x+80), (x+80), (x+70)}; int ribbon5Whys[] = {(y-70), (y-80), (y-20), (y-10)}; int ribbon5Pts = ribbon5Exe.length; Polygon ribbon5Poly = new Polygon(ribbon5Exe, ribbon5Whys, ribbon5Pts); g.fillPolygon(ribbon5Poly); int ribbon6Exe[] = {(x+60), (x+90), (x+90), (x+60)}; int ribbon6Whys[] = {(y-40), (y-70), (y-50), (y-20)}; int ribbon6Pts = ribbon6Exe.length; Polygon ribbon6Poly = new Polygon(ribbon6Exe, ribbon6Whys, ribbon6Pts); g.fillPolygon(ribbon6Poly); } void snowman(Graphics g,int x,int y) { //body g.setColor(Color.white); g.fillOval((x+25), (y-100), 40, 40); g.fillOval((x+10), (y-60), 70, 60); g.fillOval(x, y, 90, 80); //eyes g.setColor(Color.black); g.fillOval((x+35), (y-90), 5, 5); g.fillOval((x+50), (y-90), 5, 5); //mouth g.setColor(Color.black); g.drawArc((x+32),(y-80),25,12,180,180); //coal g.fillOval((x+40), (y-50), 10, 10); g.fillOval((x+40), (y-20), 10, 10); g.fillOval((x+40), (y+15), 10, 10); g.fillOval((x+40), (y+45), 10, 10); //hat g.fillRect((x+20), (y-105), 50, 5); g.fillRect((x+33), (y-145), 25, 40); //Bowtie g.setColor(Color.red); int bowTieExe[] = {(x+50), (x+70), (x+70)}; int bowTieWhys[] = {(y-60), (y-75), (y-45)}; int bowTiePts = bowTieExe.length; Polygon bowTiePoly = new Polygon(bowTieExe, bowTieWhys, bowTiePts); g.fillPolygon(bowTiePoly); int bowTie2Exe[] = {(x+40), (x+20), (x+20)}; int bowTie2Whys[] = {(y-60), (y-75), (y-45)}; int bowTie2Pts = bowTie2Exe.length; Polygon bowTie2Poly = new Polygon(bowTie2Exe, bowTie2Whys, bowTie2Pts); g.fillPolygon(bowTie2Poly); } }