Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    JonathanZwiebel
    @JonathanZwiebel
    fadsfs
    '''
    '''
    int code = 4;
    '''
    ' ' '
    int code = 4;
    ' ' '
    'int code = 4'
    ' int code = 4 '
    int code = 4
    You should log out next time
    @andrewqho
    ?
    i DON
    T
    UNDERSTAND
    JonathanZwiebel
    @JonathanZwiebel
    int code = 4;
    code += 2;
    Use the tilde three times
    then code
    then tilde three times
    code
    package flag;
    import java.awt.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    
    public class FlagPanel extends JPanel { 
        //I extended JPanel instead of JFrame so 
        //that part of my flag would not be covered by the border of the window 
    
        public FlagPanel() {
            setSize(950, 500);
        }
    
        public void init() {
            setBackground(Color.WHITE);
            repaint();
        }
    
        public void paintComponent(Graphics g){
            int height = this.getHeight();
            int width = height*(int)1.9;
            drawStripes(g, height, width);
            drawUnion(g, height, width);
            drawStarz(g, height, width);
        }
    
        public void drawStripes(Graphics g, int height, int width){
            Color OLD_GLORY_RED = new Color(0xBB133E);
            g.setColor(OLD_GLORY_RED);
            for(int i=0; i < 13; i++){ //Draws a red rectangle every other time
                if(i%2 == 0){
                    g.fillRect(0, (height*i)/13, (int)(height*1.9), height/13);
                }
    
            }
        }
    
        public void drawUnion(Graphics g, int height, int width){
            Color OLD_GLORY_BLUE = new Color(0x0052A5);
            g.setColor(OLD_GLORY_BLUE);
            g.fillRect(0, 0, (int) (height*0.76), (int) (height*0.5385)); //everything dependent on the height, allowing it to rescale
        }
    
        public void drawStarz(Graphics g, int height, int width){
            g.setColor(Color.WHITE);
            int[] px = new int[10];
            int[] py = new int[10];
            double ro = this.getHeight()*(.0308);
            double ri = ro*(.3819);
            double angle1 = Math.PI/5;
            for(int starCount = 0; starCount<50; starCount++){ //Please note this is not exactly hardcoding... I cut it down by 7 fold!
                if(starCount < 6){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.063*width)+(int)(starCount*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height);//with this, it starts at the bottom-most inner point
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.063*width)+(int)(starCount*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height);//second point generated is the top-most outer point
                        }
                    }
                    g.fillPolygon(px, py, 10);
                }
                //same formula used for every other case below it. 
                //Basically, the only difference between each of the
                //following "cases" is the y-coord, which corresponds 
                //to starCount. The larger starCount is, the farther 
                //down the point is.
                else if(6 <= starCount && starCount <11){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.126*width)+(int)((starCount-6)*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height*2);
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.126*width)+(int)((starCount-6)*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height*2);
                        }
                    }
                    g.fillPolygon(px,py,10);
                }
                else if(11 <= starCount && starCount < 17){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.063*width)+(int)((starCount-11)*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height*3);
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.063*width)+(int)((starCount-11)*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height*3);
                        }
                    }
                    g.fillPolygon(px, py, 10);
                }
                else if(17 <= starCount && starCount < 22){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.126*width)+(int)((starCount-17)*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height*4);
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.126*width)+(int)((starCount-17)*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height*4);
                        }
                    }
                    g.fillPolygon(px,py,10);
                }
                else if(22 <= starCount && starCount < 28){
                    for(int
    You should log out next time
    @andrewqho
    tilde?
    what is a tilde?
    JonathanZwiebel
    @JonathanZwiebel
    yes
    its a key
    `
    `
    `
    tilde: `
    else if(11 <= starCount && starCount < 17){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.063*width)+(int)((starCount-11)*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height*3);
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.063*width)+(int)((starCount-11)*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height*3);
                        }
                    }
                    g.fillPolygon(px, py, 10);
                }
    ok that seems to be one iteration through your stars
    so instead of having many many else if blocks
    You should log out next time
    @andrewqho
    yes
    what to do?
    JonathanZwiebel
    @JonathanZwiebel
    you could have a method where you enter the star count
    else if(17 <= starCount && starCount < 22){
                    for(int i = 0; i < 10; i++){
                        if(i%2 == 0){
                            px[i] = (int) (Math.cos(2.19911486+((i-1)*angle1))*ri)+(int)(.126*width)+(int)((starCount-17)*.126*width);
                            py[i] = (int) (Math.sin((2.19911486+((i-1)*angle1)))*ri)+(int)(.054*height*4);
                        }
                        else{
                            px[i] = (int) (Math.cos((Math.PI/2)+(i*angle1))*ro)+(int)(.126*width)+(int)((starCount-17)*.126*width);
                            py[i] = (int) (Math.sin(((Math.PI/2)+(i*angle1)))*ro)+(int)(.054*height*4);
                        }
                    }
                    g.fillPolygon(px,py,10);
                }
    these are literally the same with the exception of one number
    the 17 in place of the 11
    You should log out next time
    @andrewqho
    YES
    LIKE A GOD
    JonathanZwiebel
    @JonathanZwiebel
    so you make a method that does that except instead of the 11 or the 17
    you call it 'swag'
    int swag;