daily pastebin goal
80%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.*;
  2.  
  3. public class Illusion {
  4.  
  5.     public static void main(String[] args) {
  6.         drawFigures();
  7.     }
  8.  
  9.     public static void drawFigures() {
  10.         DrawingPanel panel = new DrawingPanel(500, 400);
  11.         panel.setBackground(Color.CYAN);   
  12.         Graphics g = panel.getGraphics();
  13.  
  14.         //Draws the three unique circles that are not inside grids.
  15.         drawSubfigure(g, 0, 0, 3, 90);
  16.         drawSubfigure(g, 120, 10, 3, 90);
  17.         drawSubfigure(g, 250, 50, 5, 80);
  18.        
  19.         //Draws the three different grids of circles.
  20.         drawGrid(g, 350, 20, 120);
  21.         drawGrid(g, 10, 120, 200);
  22.         drawGrid(g, 240, 160, 200);
  23.     }
  24.    
  25.     //Draws a "subfigure" that contains the appropriate number of concentric circles and a square.
  26.     public static void drawSubfigure(Graphics g, int x, int y, int circles, int size) {
  27.         g.setColor(Color.YELLOW);                               //Fills each circle as yellow.
  28.         g.fillOval(x, y, size, size);
  29.        
  30.         g.setColor(Color.BLACK);                                //Draws square and concentric circle lines as black.
  31.         g.drawLine(x, y + size/2, x + size/2, y);
  32.         g.drawLine(x + size/2, y, x + size, y + size/2);
  33.         g.drawLine(x + size, y + size/2, x + size/2, y + size);
  34.         g.drawLine(x + size/2, y + size, x, y + size/2);
  35.  
  36.         for (int i = 1; i <= circles; i++) {
  37.             g.drawOval(x + (size / (2 * i)) * (i - 1),          //x
  38.                        y + (size / (2 * i)) * (i - 1),          //y
  39.                        size - 2 * (size / (3 * i)) * (i - 1),   //width
  40.                        size - 2 * (size / (3 * i)) * (i - 1));  //height
  41.         }
  42.     }  
  43.    
  44.     //Draws a light gray box with a red outline where required as a backdrop.
  45.     public static void drawGrid(Graphics g, int x, int y, int size) {
  46.         g.setColor(Color.LIGHT_GRAY);                           //Fills each grid as light gray.
  47.         g.fillRect(x, y, size, size);
  48.        
  49.         g.setColor(Color.RED);                                  //Outlines each grid in red.
  50.         g.drawRect(x, y, size, size);
  51.        
  52.         //Draws the grid that contains nine subfigures.
  53.         for (int i = 0; i < 3; i++) {
  54.            
  55.             //Specifically draws the nine subfigures of the grid.
  56.             for (int j = 0; j < 3; j++) {
  57.                 drawSubfigure(g, 350 + 40*i, 20 + 40*j, 5, 40);
  58.             }
  59.         }
  60.        
  61.         //Draws the grid that contains four subfigures.
  62.         for (int i = 0; i < 2; i++) {
  63.            
  64.             //Specifically draws the four subfigures of the grid.
  65.             for (int j = 0; j < 2; j++) {
  66.                 drawSubfigure(g, 10 + 100*i, 120 + 100*j, 10, 100);
  67.             }
  68.         }
  69.        
  70.         //Draws the grid that contains sixteen subfigures.
  71.         for (int i = 0; i < 4; i++) {
  72.            
  73.             //Specifically draws the sixteen subfigures of the grid.
  74.             for (int j = 0; j < 4; j++) {
  75.                 drawSubfigure(g, 240 + 50*i, 160 + 50*j, 5, 50);
  76.             }
  77.         }
  78.     }
  79.        
  80. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top