HOME | DD

OneEyedValkyr — Interlocking Square Code for Java Eclipse

Published: 2014-06-25 19:28:23 +0000 UTC; Views: 773; Favourites: 1; Downloads: 0
Redirect to original
Description okay so here's the code :3

import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.util.Date;

/**
 * Class MyApplet - write a description of the class here
 *
 * author (your name)
 * version (a version number)
 */
public class MyApplet extends JApplet implements Runnable

{
   
    int r = 0;
    int gr = 0;
    int b = 255;
    String name = "";
   
    public final int SIZE = 500;
    public final int DIST = 20;
   
    Random rand = new Random();
   
    Image offscreen;
    Graphics bufferGraphics;
    Thread clock;
   
    public void init()
    {
        offscreen = createImage(SIZE,SIZE);
        bufferGraphics = offscreen.getGraphics();
        clock = new Thread(this);
    }
   
    public void run()
    {
       
    }
   
    public void paint(Graphics g)
    {
        bufferGraphics.setColor(new Color(255,255,0));
        bufferGraphics.clearRect(0,0,SIZE,SIZE);
        bufferGraphics.fillRect(0,0,SIZE,SIZE);
       
        /*DrawLines(g);
        DrawNames(g);
        //DrawOvals(g);
        DrawFilledOvals(g);
        DrawFilledRects(g);*/
       
        //DrawHorOffscreen(DIST);
        //parLines(g, DIST);
        //diagLines(g, SIZE - DIST);
        DrawRecursiveRectangles(g, 200, SIZE/2, SIZE/2);
        //DrawAltColorCircles(g, DIST, Color.blue);
        //DrawCircles(g,DIST);
        //DrawVerticalLines(g,DIST);
        //DrawHorizontalLines(g, DIST);
       
       /*DrawStairs(g);
       /*
       DrawFilledRectsRainbow(g);
       DrawFilledRectsRainbowDifferentThickness(g);*/
      
       //g.drawImage(offscreen,0,0,this);
       
       //repaint();
    }
   
    public void update(Graphics g)
    {
          paint(g);
    }

   
   
    public void DrawStairs(Graphics g)
    {
        int currentX = 0;
        int currentY = DIST;
        boolean horizontal = true;
        int endX = currentX + DIST;
        int endY = currentY;       
        g.setColor(Color.black);
       
        while(currentX < SIZE && currentY < SIZE)
        {
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            if(horizontal)
                endX = currentX + DIST;               
            else
                endY = currentY + DIST;
               
            g.drawLine(currentX,currentY,endX,endY);
           
            horizontal = !horizontal;           
            currentX = endX;
            currentY = endY;
        }

    }
   
   
    public void DrawHorOffscreen(int y)
    {
        Color c = altColor ? Color.red : Color.blue;
           
        bufferGraphics.setColor(c);  
        bufferGraphics.drawLine(DIST,y,SIZE - DIST,y);
        altColor = !altColor;
        if(y < SIZE)
            DrawHorOffscreen(y + DIST);
    }
   
    public void parLines(Graphics g, int x)
    {
        g.drawLine(0,x,SIZE,x);
        if(x < SIZE - DIST)
            parLines(g, x + DIST);
    }
   
    public void diagLines(Graphics g, int x)
    {
        g.drawLine(x,0,SIZE,SIZE -x);
        g.drawLine(0,x,SIZE - x,SIZE);
        if(x >= 0)
            diagLines(g, x - DIST);
    }
   
    public void DrawHorizontalLines(Graphics g, int y)
    {       
        g.setColor(Color.black);  
        g.drawLine(DIST,y,SIZE - DIST,y);
        if(y < SIZE)
            DrawHorizontalLines(g, y + DIST);
    }
   
    public void DrawVerticalLines(Graphics g, int x)
    {         
        g.drawLine(x,DIST,x,SIZE - DIST);
        if(x < SIZE)
            DrawVerticalLines(g, x + DIST);
    }
   
   
    boolean altColor = false;
    public void DrawAltColorCircles(Graphics g, int xy, Color c)
    {       
       
        g.setColor(c);
        g.fillOval(xy,xy,SIZE - 2*xy, SIZE - 2*xy);
        if(xy < SIZE / 2)
            DrawAltColorCircles(g, xy + DIST, (c == Color.blue) ? Color.red : Color.blue);
    }
   
    public void DrawRecursiveRectangles(Graphics g, int n, int x, int y)
    {
       
        g.drawRect(x - n/2, y - n/2, n, n);
        if(n > 20)
        {
            DrawRecursiveRectangles(g, n/2, x - n/2, y - n/2);
            DrawRecursiveRectangles(g, n/2, x + n/2, y - n/2);
            DrawRecursiveRectangles(g, n/2, x - n/2, y + n/2);
            DrawRecursiveRectangles(g, n/2, x + n/2, y + n/2);           
        }
       
    }
   
   
    public void DrawCircles(Graphics g, int xy)
    {
        g.drawOval(xy,xy,SIZE - xy, SIZE - xy);
        if(xy < SIZE / 2)
            DrawCircles(g, xy + DIST);
    }
   
   
   
    public void DrawCircles2(Graphics g, int xy)
    {
        g.drawOval(xy,xy,SIZE - 2*xy, SIZE - 2*xy);
        if(xy < SIZE / 2)
            DrawCircles(g, xy + DIST);
    }
   
    public void DrawRects(Graphics g)
    {
        int currentSize = SIZE - 2 * DIST;
        int currentX = DIST;
        int currentY = DIST;
        g.setColor(Color.black);
       
        while(currentSize + currentX > SIZE/2)
        {
            g.drawRect(currentX,currentY,currentSize,currentSize);
            currentSize -= 2 * DIST;
            currentX += DIST;
            currentY += DIST;
           
        }
    }
   
    public void DrawFilledRects(Graphics g)
    {
        int currentSize = SIZE - 2 * DIST;
        int currentX = DIST;
        int currentY = DIST;
        boolean altColor = false;
       
        while(currentSize + currentX > SIZE/2)
        {
            Color c = (altColor)? Color.red : Color.blue;
            g.setColor(c);
            g.fillRect(currentX,currentY,currentSize,currentSize);
            currentSize -= 2 * DIST;
            currentX += DIST;
            currentY += DIST;
            altColor = !altColor;
           
        }
    }
  
    public void DrawFilledRectsRainbow(Graphics g)
    {
        int currentSize = SIZE - 2 * DIST;
        int currentX = DIST;
        int currentY = DIST;
       
        while(currentSize + currentX > SIZE/2)
        {
           
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)));
            g.fillRect(currentX,currentY,currentSize,currentSize);
            currentSize -= 2 * DIST;
            currentX += DIST;
            currentY += DIST;
           
        }
    }
    public void DrawFilledRectsRainbowDifferentThickness(Graphics g)
    {
        int currentSize = SIZE - 2 * DIST;
        int currentX = DIST;
        int currentY = DIST;
       
        while(currentSize + currentX > SIZE/2)
        {
           
            g.setColor(new Color(rand.nextInt(256), rand.nextInt(40), rand.nextInt(40)));
            g.fillRect(currentX,currentY,currentSize,currentSize);
            int thickness = rand.nextInt(DIST);
            currentSize -= 2 * thickness;
            currentX += thickness;
            currentY += thickness;
           
        }
    }
   
    public void DrawLines(Graphics g)
    {
       
        g.setColor(new Color(r,gr,b));
        g.drawLine(0,0,SIZE,SIZE);
        g.setColor(new Color(r,gr,b));
        g.drawLine(0,SIZE,SIZE,0);
        g.setColor(Color.green);
        g.drawLine(0,SIZE/2,SIZE,SIZE/2);
        g.drawLine(SIZE/2,0,SIZE/2,SIZE);
    }
   
    public void DrawNames(Graphics g)
    {       
        g.setColor(Color.black);
        g.drawString(name, 0, 10);
        g.drawString(name, SIZE - 85, 10);
        g.drawString(name, 0, SIZE);
        g.drawString(name, SIZE - 85, SIZE);
    }
   
    public void DrawOvals(Graphics g)
    {
        g.setColor(new Color(0,0,0));
       
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 3;j++)
            {
                g.drawOval(SIZE/3 * i, SIZE/3 * j, SIZE/3, SIZE/3);
            }
        }
    }
   
    public void DrawFilledOvals(Graphics g)
    {
        g.setColor(new Color(0,0,0));
       
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 3;j++)
            {
                g.fillOval(SIZE/3 * i, SIZE/3 * j, SIZE/3, SIZE/3);
            }
        }
    }
   
   
}

Related content
Comments: 8

SaikoroSama [2014-06-25 20:09:08 +0000 UTC]

Hidden by Admin

👍: 0 ⏩: 1

OneEyedValkyr In reply to SaikoroSama [2014-06-25 20:46:37 +0000 UTC]

thanks

👍: 0 ⏩: 0

Miku-and-Mikuo [2014-06-25 19:59:47 +0000 UTC]

Woah! That's crazy looking

👍: 0 ⏩: 1

OneEyedValkyr In reply to Miku-and-Mikuo [2014-06-25 20:46:48 +0000 UTC]

IT IS XD
it took me foreverrrrr

👍: 0 ⏩: 1

Miku-and-Mikuo In reply to OneEyedValkyr [2014-06-26 19:06:52 +0000 UTC]

Well it's impressive 

👍: 0 ⏩: 1

OneEyedValkyr In reply to Miku-and-Mikuo [2014-06-26 19:19:19 +0000 UTC]

thanks

👍: 0 ⏩: 1

Miku-and-Mikuo In reply to OneEyedValkyr [2014-06-26 21:04:20 +0000 UTC]

Your welcome

👍: 0 ⏩: 1

OneEyedValkyr In reply to Miku-and-Mikuo [2014-06-27 01:58:47 +0000 UTC]

:3

👍: 0 ⏩: 0