Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Daniel on 4/13/2016.
- */
- //-------------------------------------------------------------------------------------------------------------------------------------
- //Project 1
- import java.awt.*;
- public class project1 {
- public static void main(String[] args){
- DrawingPanel panel = new DrawingPanel(400,400);
- Graphics g = panel.getGraphics();
- square(g,0,0,100,5);
- grid(g,10,120,120,5,4);
- grid(g,150,20,240,6,5);
- grid(g,130,275,108,3,3);
- }
- public static void square(Graphics g ,int x, int y, int l,int s){
- g.setColor(Color.GREEN);
- g.fillRect(x,y,l,l);
- g.setColor(Color.BLACK);
- g.drawRect(x,y,l,l);
- g.setColor(Color.YELLOW);
- g.fillOval(x ,y,l,l);
- g.setColor(Color.BLACK);
- for(int i = 0; i < s;i++){
- g.drawOval(x + i*l/s/2, y+ i*l/s/2,l - i*l/s,l- i*l/s);
- }
- g.drawLine(x,y + l/2,x+l,y+l/2);
- g.drawLine(x+l/2,y,x+l/2,y+l);
- }
- public static void grid(Graphics g, int x,int y,int l,int c,int ci){
- int size = l/c;
- for(int row = 0; row< c;row++){
- for(int col = 0; col< c;col++){
- square(g,x+ col*size,y+ row*size,size,4);
- }
- }
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //Project 2
- /**
- * Created by Daniel on 4/15/2016.
- */
- import java.awt.*;
- public class project2{
- public static void main(String[] args){
- DrawingPanel panel = new DrawingPanel(200,200);
- Graphics g = panel.getGraphics();
- int nE = 1;
- int nS = 2;
- int nT = 3;
- boolean e = true;
- boolean s = true;
- boolean t = true;
- Color c = new Color(0,0,0);
- int cc = 1;
- // I wanted to do the placement with for loops, I did the placement itself pretty well,
- // but was already spending a lot of time on the placement so I cheated a bit and used clunky if statements for the colors.
- for(int i = 0; i < 3;i++){
- for(int j = 0; j<3;j++){
- if (nE == j +1 && e){
- if(cc == 1)c = Color.LIGHT_GRAY;
- if(cc == 2)c = Color.DARK_GRAY;
- if(cc == 3)c = Color.GRAY;
- eyes(g,j*50,i*50,c);
- nE--;
- if (nE< 1){
- nE = 3;
- }
- e = false;
- }
- if (nS == j+1 && s){
- if(cc == 1)c = Color.DARK_GRAY;
- if(cc == 2)c = Color.GRAY;
- if(cc == 3)c = Color.LIGHT_GRAY;
- shapes(g,j*50,i*50,c);
- nS--;
- if (nS < 1){
- nS = 3;
- }
- s = false;
- }
- if (nT == j+1&&t){
- if(cc == 1)c = Color.GRAY;
- if(cc == 2)c = Color.LIGHT_GRAY;
- if(cc == 3)c = Color.DARK_GRAY;
- text(g,j*50,i*50,c);
- nT--;
- if (nT < 1){
- nT = 3;
- }
- t = false;
- }
- cc++;
- if(cc>3){
- cc = 1;
- }
- }
- e= true;
- t= true;
- s= true;
- }
- //eyes(g,0,0,Color.RED);
- //text(g,0,0,Color.BLACK);
- //shapes(g,0,0,Color.GRAY);
- }
- public static void eyes(Graphics g, int x, int y, Color c){
- g.setColor(Color.BLACK);
- g.drawRect(x,y,50,50);
- g.setColor(c);
- g.fillOval(x+5,y+30,15,15);
- g.fillOval(x+45-15,y+30,15,15);
- g.setColor(Color.BLACK);
- g.drawOval(x+5,y+5,15,45);
- g.drawOval(x+45-15,y+5,15,45);
- }
- public static void text(Graphics g, int x, int y, Color c){
- g.setColor(Color.BLACK);
- g.drawRect(x,y,50,50);
- g.setColor(c);
- Font standard = new Font("SansSerif",Font.PLAIN,16);
- g.setFont(standard);
- g.drawString("i",x+25,y+12);
- Font small = new Font("SansSerif",Font.PLAIN,12);
- g.setFont(small);
- g.drawString("Love",x+13,y+25);
- g.drawString("Java",x+13,y+37);
- }
- public static void pyramid(Graphics g,Color c, int x, int y,int dx,int yx, int w, int h, int ws, int hs){
- g.setColor(c);
- for(int i = 0; i < 5; i++){
- g.drawRect(x + i*dx,y + i*yx,w - ws*i, h - hs*i);
- }
- }
- public static void shapes(Graphics g, int x, int y, Color c){
- g.setColor(Color.BLACK);
- g.drawRect(x,y,50,50);
- pyramid(g,c,x,y,5,5,5,45,0,10);
- pyramid(g,c,x+45,y+5,-5,5,5,45,0,10);
- pyramid(g,c,x+5,y,5,5,45,5,10,0);
- pyramid(g,c,x,y+45,5,-5,45,5,10,0);
- g.setColor(Color.BLACK);
- g.drawRect(x,y,50,50);
- }
- }
- //-------------------------------------------------------------------------------------------------------------------------------------
- //Project 3
- /**
- * Created by Daniel on 4/17/2016.
- */
- import java.awt.*;
- public class Project3 {
- public static void main(String[] args){
- DrawingPanel panel = new DrawingPanel(420,300);
- Graphics g = panel.getGraphics();
- // some examples:
- square(g,0,0,100,5);
- grid(g,150,0,200,4,5);
- grid(g,0,150,120,6,5);
- square(g,300,220,40,8);
- }
- public static void square(Graphics g, int x, int y, int l, int s){
- g.setColor(Color.WHITE);
- g.fillRect(x,y,l,l);
- g.setColor(Color.GRAY);
- boolean odd = true;
- for(int i = 0; i < s; i++){
- for(int j = 0; j<s; j++){
- if(odd)g.fillRect(x+j*l/s,y+i*l/s,l/s,l/s);
- odd = !odd;
- }
- if(s % 2 == 0)odd = !odd;
- }
- g.setColor(Color.BLACK);
- g.drawRect(x,y,l,l);
- }
- public static void grid(Graphics g, int x, int y, int l, int s,int lms){
- for(int i = 0; i < s; i++){
- for(int j = 0;j<s;j++){
- square(g, x+j*l/s ,y+i*l/s, l/s , l/s/lms );
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement