Advertisement
daniel_lawson9999

Daniel Lawson Java 1, 3G Projects 1,2,3

Apr 17th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.32 KB | None | 0 0
  1. /**
  2.  * Created by Daniel on 4/13/2016.
  3.  */
  4. //-------------------------------------------------------------------------------------------------------------------------------------
  5. //Project 1
  6. import java.awt.*;
  7. public class project1 {
  8.     public static void main(String[] args){
  9.         DrawingPanel panel = new DrawingPanel(400,400);
  10.         Graphics g = panel.getGraphics();
  11.         square(g,0,0,100,5);
  12.         grid(g,10,120,120,5,4);
  13.         grid(g,150,20,240,6,5);
  14.         grid(g,130,275,108,3,3);
  15.  
  16.     }
  17.     public static void square(Graphics g ,int x, int y, int l,int s){
  18.         g.setColor(Color.GREEN);
  19.         g.fillRect(x,y,l,l);
  20.         g.setColor(Color.BLACK);
  21.         g.drawRect(x,y,l,l);
  22.         g.setColor(Color.YELLOW);
  23.         g.fillOval(x ,y,l,l);
  24.         g.setColor(Color.BLACK);
  25.         for(int i = 0; i < s;i++){
  26.             g.drawOval(x + i*l/s/2, y+ i*l/s/2,l - i*l/s,l- i*l/s);
  27.         }
  28.         g.drawLine(x,y + l/2,x+l,y+l/2);
  29.         g.drawLine(x+l/2,y,x+l/2,y+l);
  30.     }
  31.     public static void grid(Graphics g, int x,int y,int l,int c,int ci){
  32.         int size = l/c;
  33.         for(int row = 0; row< c;row++){
  34.             for(int col = 0; col< c;col++){
  35.                 square(g,x+ col*size,y+ row*size,size,4);
  36.  
  37.             }
  38.         }
  39.     }
  40. }
  41. //-------------------------------------------------------------------------------------------------------------------------------------
  42. //Project 2
  43. /**
  44.  * Created by Daniel on 4/15/2016.
  45.  */
  46. import java.awt.*;
  47. public class project2{
  48.     public static void main(String[] args){
  49.         DrawingPanel panel = new DrawingPanel(200,200);
  50.         Graphics g = panel.getGraphics();
  51.         int nE = 1;
  52.         int nS = 2;
  53.         int nT = 3;
  54.         boolean e = true;
  55.         boolean s = true;
  56.         boolean t = true;
  57.         Color c = new Color(0,0,0);
  58.         int cc = 1;
  59.         // I wanted to do the placement with for loops, I did the placement itself pretty well,
  60.         // but was already spending a lot of time on the placement so I cheated a bit and used clunky if statements for the colors.
  61.         for(int i = 0; i < 3;i++){
  62.             for(int j = 0; j<3;j++){
  63.                 if (nE == j +1 && e){
  64.                     if(cc == 1)c = Color.LIGHT_GRAY;
  65.                     if(cc == 2)c = Color.DARK_GRAY;
  66.                     if(cc == 3)c = Color.GRAY;
  67.                     eyes(g,j*50,i*50,c);
  68.                     nE--;
  69.                     if (nE< 1){
  70.                         nE = 3;
  71.                     }
  72.                     e = false;
  73.                 }
  74.                 if (nS == j+1 && s){
  75.                     if(cc == 1)c = Color.DARK_GRAY;
  76.                     if(cc == 2)c = Color.GRAY;
  77.                     if(cc == 3)c = Color.LIGHT_GRAY;
  78.                     shapes(g,j*50,i*50,c);
  79.                     nS--;
  80.                     if (nS < 1){
  81.                         nS = 3;
  82.                     }
  83.                     s = false;
  84.                 }
  85.                 if (nT == j+1&&t){
  86.                     if(cc == 1)c = Color.GRAY;
  87.                     if(cc == 2)c = Color.LIGHT_GRAY;
  88.                     if(cc == 3)c = Color.DARK_GRAY;
  89.                     text(g,j*50,i*50,c);
  90.                     nT--;
  91.                     if (nT < 1){
  92.                         nT = 3;
  93.                     }
  94.                     t = false;
  95.                 }
  96.                 cc++;
  97.                 if(cc>3){
  98.                     cc = 1;
  99.                 }
  100.  
  101.             }
  102.             e= true;
  103.             t= true;
  104.             s= true;
  105.         }
  106.         //eyes(g,0,0,Color.RED);
  107.        //text(g,0,0,Color.BLACK);
  108.         //shapes(g,0,0,Color.GRAY);
  109.     }
  110.     public static void eyes(Graphics g, int x, int y, Color c){
  111.         g.setColor(Color.BLACK);
  112.         g.drawRect(x,y,50,50);
  113.         g.setColor(c);
  114.         g.fillOval(x+5,y+30,15,15);
  115.         g.fillOval(x+45-15,y+30,15,15);
  116.         g.setColor(Color.BLACK);
  117.         g.drawOval(x+5,y+5,15,45);
  118.         g.drawOval(x+45-15,y+5,15,45);
  119.  
  120.     }
  121.     public static void text(Graphics g, int x, int y, Color c){
  122.         g.setColor(Color.BLACK);
  123.         g.drawRect(x,y,50,50);
  124.         g.setColor(c);
  125.         Font standard = new Font("SansSerif",Font.PLAIN,16);
  126.         g.setFont(standard);
  127.         g.drawString("i",x+25,y+12);
  128.         Font small = new Font("SansSerif",Font.PLAIN,12);
  129.         g.setFont(small);
  130.         g.drawString("Love",x+13,y+25);
  131.         g.drawString("Java",x+13,y+37);
  132.  
  133.     }
  134.     public static void pyramid(Graphics g,Color c, int x, int y,int dx,int yx, int w, int h, int ws, int hs){
  135.         g.setColor(c);
  136.         for(int i = 0; i < 5; i++){
  137.             g.drawRect(x + i*dx,y + i*yx,w - ws*i, h - hs*i);
  138.         }
  139.  
  140.     }
  141.     public static void shapes(Graphics g, int x, int y, Color c){
  142.         g.setColor(Color.BLACK);
  143.         g.drawRect(x,y,50,50);
  144.         pyramid(g,c,x,y,5,5,5,45,0,10);
  145.         pyramid(g,c,x+45,y+5,-5,5,5,45,0,10);
  146.         pyramid(g,c,x+5,y,5,5,45,5,10,0);
  147.         pyramid(g,c,x,y+45,5,-5,45,5,10,0);
  148.         g.setColor(Color.BLACK);
  149.         g.drawRect(x,y,50,50);
  150.     }
  151. }
  152. //-------------------------------------------------------------------------------------------------------------------------------------
  153. //Project 3
  154. /**
  155.  * Created by Daniel on 4/17/2016.
  156.  */
  157. import java.awt.*;
  158. public class Project3 {
  159.     public static void main(String[] args){
  160.         DrawingPanel panel = new DrawingPanel(420,300);
  161.         Graphics g = panel.getGraphics();
  162.         // some examples:
  163.         square(g,0,0,100,5);
  164.         grid(g,150,0,200,4,5);
  165.         grid(g,0,150,120,6,5);
  166.         square(g,300,220,40,8);
  167.  
  168.     }
  169.     public static void square(Graphics g, int x, int y, int l, int s){
  170.         g.setColor(Color.WHITE);
  171.         g.fillRect(x,y,l,l);
  172.         g.setColor(Color.GRAY);
  173.         boolean odd = true;
  174.         for(int i = 0; i < s; i++){
  175.             for(int j = 0; j<s; j++){
  176.                 if(odd)g.fillRect(x+j*l/s,y+i*l/s,l/s,l/s);
  177.                 odd = !odd;
  178.             }
  179.             if(s % 2 == 0)odd = !odd;
  180.         }
  181.         g.setColor(Color.BLACK);
  182.         g.drawRect(x,y,l,l);
  183.     }
  184.     public static void grid(Graphics g, int x, int y, int l, int s,int lms){
  185.         for(int i = 0; i < s; i++){
  186.             for(int j = 0;j<s;j++){
  187.                 square(g, x+j*l/s ,y+i*l/s, l/s , l/s/lms );
  188.             }
  189.         }
  190.     }
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement