Skip to content

Instantly share code, notes, and snippets.

@mebigfatguy
Created December 24, 2018 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebigfatguy/b3084e98b80506f15b0e51b9fb9ee035 to your computer and use it in GitHub Desktop.
Save mebigfatguy/b3084e98b80506f15b0e51b9fb9ee035 to your computer and use it in GitHub Desktop.
a little winter fun
/*
* polycasso - Cubism Artwork generator
* Copyright 2010-2008 * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations
* under the License.
*/
import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Polygon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Timer;
/**
* generates an image by laying semi-transparent polygons on top of each other.
* Class generated by Polycasso (http://polycasso.sourceforge.net)
*/
public class Penguin {
private static final int DEFAULT_DELAY = 500;
public static void main(String[] args) {
int inputDelay;
try {
inputDelay = Integer.parseInt(args[0]);
} catch (Exception e) {
inputDelay = DEFAULT_DELAY;
}
final int delay = inputDelay;
JFrame frame = new JFrame() {
private static final long serialVersionUID = 1L;
private Timer timer;
private int displayCount = 0;
private int[][][] polygonData = new int[][][]
{
{
{0,0,391,391,404,391,391},
{464,0,0,388,388,405,464}
},
{
{301,23,0,44,211,349,142},
{271,410,416,412,442,449,58}
},
{
{224,300,268,217,264,256,273},
{238,226,194,240,242,158,261}
},
{
{370,355,323,300,360,328,297},
{348,374,385,384,346,331,307}
},
{
{86,212,226,225,208,170,102},
{54,58,73,47,22,12,33}
},
{
{110,278,268,262,244,270,194},
{25,263,284,253,255,291,16}
},
{
{352,304,307,296,296,123,176},
{347,356,334,354,272,67,84}
},
{
{369,291,278,317,313,301,279},
{365,277,213,282,261,229,247}
},
{
{363,370,385,373,367,333,163},
{382,348,356,374,350,338,193}
},
{
{266,280,254,291,316,301,195},
{167,197,242,248,272,226,225}
},
{
{142,291,230,295,279,194,225},
{418,457,429,431,355,313,126}
},
{
{262,286,269,235,272,200,159},
{176,204,258,188,177,169,140}
},
{
{23,28,157,26,27,65,274},
{402,448,440,432,441,448,440}
},
{
{100,76,95,159,214,158,163},
{424,417,400,415,423,432,423}
},
{
{49,44,56,82,82,98,116},
{418,410,406,383,371,375,367}
},
{
{222,212,199,183,187,213,226},
{40,25,18,14,105,114,67}
},
{
{203,223,181,145,241,102,151},
{397,335,298,341,458,453,314}
},
{
{277,185,181,188,309,263,220},
{183,186,201,214,282,283,247}
},
{
{192,157,163,124,124,115,7},
{448,427,422,426,420,425,409}
},
{
{161,309,142,280,233,333,373},
{184,291,443,425,422,402,429}
},
{
{96,160,179,231,163,126,79},
{393,347,350,352,356,337,378}
},
{
{162,242,159,330,381,350,188},
{443,439,449,458,445,461,270}
},
{
{217,179,132,155,127,123,124},
{305,347,271,313,113,129,158}
},
{
{156,162,366,246,332,273,325},
{317,334,356,298,355,354,383}
},
{
{352,335,309,263,285,325,335},
{350,346,338,350,317,334,335}
},
{
{298,301,300,282,266,332,288},
{240,241,224,196,265,319,228}
},
{
{125,138,225,265,295,308,324},
{39,30,100,167,269,262,333}
},
{
{244,242,169,157,141,165,175},
{145,153,153,135,57,151,77}
},
{
{286,236,203,178,282,198,273},
{358,395,358,429,412,421,434}
},
{
{96,114,161,125,137,107,87},
{56,56,36,38,27,26,31}
},
{
{291,383,387,383,356,326,271},
{388,416,381,348,347,354,252}
},
{
{33,165,204,232,240,221,219},
{97,188,229,232,239,237,236}
},
{
{249,242,290,276,259,300,253},
{422,368,429,433,432,372,384}
},
{
{81,219,216,232,212,237,221},
{19,22,10,165,93,110,109}
},
{
{240,293,247,318,331,275,210},
{463,399,373,388,378,374,372}
},
{
{105,103,87,68,76,73,96},
{64,52,30,51,50,49,50}
},
{
{60,82,140,190,133,144,141},
{367,373,224,314,340,330,366}
},
{
{85,138,238,226,182,216,139},
{23,436,436,394,408,385,379}
},
{
{218,191,265,284,279,306,326},
{246,221,258,283,270,244,310}
},
{
{230,242,191,246,259,235,204},
{208,158,123,169,177,169,200}
},
{
{248,289,291,268,328,290,257},
{240,287,274,224,315,226,218}
},
{
{151,157,161,151,174,179,196},
{63,133,142,132,157,159,167}
},
{
{92,49,71,114,187,165,152},
{363,434,451,443,436,374,343}
},
{
{319,281,294,264,228,258,294},
{427,414,389,413,420,379,380}
},
{
{307,310,299,270,300,287,266},
{306,332,349,363,371,382,376}
},
{
{178,192,138,106,137,113,157},
{125,23,43,48,23,27,116}
},
{
{208,213,157,194,218,186,159},
{86,45,76,20,34,65,99}
},
{
{233,257,244,202,202,216,106},
{107,156,163,121,145,129,63}
},
{
{110,92,134,148,106,74,147},
{27,55,53,18,60,45,21}
},
{
{282,274,252,265,320,246,295},
{278,271,241,281,292,363,351}
},
{
{308,327,341,262,332,325,365},
{446,449,430,431,393,423,437}
},
{
{241,194,214,154,217,209,237},
{390,435,409,422,396,375,377}
},
{
{244,225,229,270,251,148,245},
{372,391,381,376,372,427,427}
},
{
{104,103,96,155,120,150,93},
{379,426,421,424,408,393,390}
},
{
{280,290,302,295,258,210,54},
{287,299,320,333,337,314,170}
},
{
{217,234,260,312,285,263,254},
{90,90,156,227,204,173,146}
},
{
{68,134,148,155,173,164,198},
{57,94,83,80,76,36,55}
},
{
{201,225,202,193,139,196,220},
{146,73,28,46,45,18,32}
},
{
{224,247,260,259,193,176,138},
{140,229,217,237,138,16,23}
},
{
{133,183,204,228,206,199,165},
{185,303,329,348,333,336,251}
},
{
{278,276,246,217,148,268,277},
{340,339,346,349,339,339,317}
},
{
{212,246,196,213,195,211,158},
{89,228,203,211,213,182,119}
},
{
{162,163,152,158,196,237,203},
{366,381,394,396,399,383,368}
},
{
{182,195,198,214,226,128,145},
{200,235,88,115,71,104,84}
},
{
{222,230,239,246,236,197,195},
{151,109,122,134,197,154,146}
},
{
{299,191,240,278,249,171,214},
{226,61,122,214,173,203,177}
},
{
{245,224,218,177,241,206,181},
{190,196,211,182,211,161,134}
},
{
{188,199,23,12,178,185,120},
{314,324,354,36,255,172,153}
},
{
{226,206,236,271,256,236,167},
{188,176,182,248,191,159,141}
},
{
{258,225,229,187,217,243,127},
{173,174,142,132,153,159,11}
},
{
{159,116,123,209,309,187,214},
{326,359,351,377,337,375,362}
},
{
{203,210,232,264,227,125,219},
{17,193,190,258,148,100,35}
},
{
{270,329,273,351,383,367,377},
{327,373,415,453,444,390,347}
},
{
{109,146,163,210,308,206,142},
{422,387,365,378,329,370,336}
},
{
{244,205,257,226,200,164,151},
{193,240,227,203,234,174,119}
},
{
{199,180,153,188,145,151,200},
{348,393,411,429,422,406,395}
},
{
{126,137,126,126,136,128,122},
{113,94,127,153,194,172,143}
},
{
{141,193,174,228,168,155,96},
{380,349,353,350,359,362,386}
},
{
{127,222,162,164,125,144,121},
{185,147,108,181,152,79,126}
},
{
{184,249,233,273,296,311,260},
{163,184,167,188,216,254,165}
},
{
{159,186,183,163,153,128,152},
{241,288,299,246,224,175,231}
},
{
{151,148,159,160,133,124,128},
{227,218,239,245,181,153,174}
},
{
{90,82,118,104,134,125,104},
{417,386,387,387,382,400,416}
},
{
{345,260,305,343,390,361,333},
{337,256,265,343,355,370,365}
},
{
{190,248,183,183,145,152,171},
{317,344,280,231,171,227,265}
},
{
{310,256,247,230,215,215,182},
{148,162,143,113,160,194,258}
},
{
{297,326,380,337,322,301,160},
{230,335,354,327,296,221,124}
},
{
{358,362,368,212,237,59,43},
{67,93,386,20,47,77,74}
},
{
{136,157,117,150,172,200,140},
{24,14,52,67,71,91,34}
},
{
{101,149,173,200,204,205,143},
{48,66,72,70,71,40,35}
},
{
{179,169,197,191,166,159,125},
{55,63,65,48,64,53,39}
},
{
{106,0,59,38,64,65,95},
{464,387,383,450,444,413,367}
},
{
{0,0,76,43,98,69,49},
{421,384,385,397,403,425,427}
},
{
{161,161,285,161,127,0,263},
{4,14,20,51,37,66,46}
},
{
{303,311,327,291,331,319,249},
{268,173,302,210,278,226,189}
},
{
{290,348,297,226,140,163,101},
{460,445,442,449,451,447,428}
},
{
{263,210,228,335,339,296,209},
{378,430,390,420,429,429,392}
},
{
{248,284,333,298,293,278,267},
{313,298,385,317,268,286,312}
},
{
{223,206,192,244,236,255,256},
{426,430,424,402,407,393,394}
},
{
{203,205,172,151,223,215,144},
{51,58,82,100,81,98,96}
}
};
private int[][] colorData = new int[][]
{
{255,255,255},
{188,193,188},
{27,27,27},
{21,19,21},
{68,68,68},
{224,224,224},
{110,107,107},
{0,0,0},
{187,186,190},
{11,10,11},
{118,114,115},
{27,27,27},
{0,0,0},
{67,69,67},
{72,66,72},
{0,0,0},
{151,145,151},
{47,47,47},
{255,255,255},
{68,56,65},
{112,108,112},
{68,59,71},
{0,2,0},
{151,151,151},
{254,255,255},
{88,88,88},
{50,50,50},
{140,139,139},
{0,4,0},
{50,49,50},
{206,207,206},
{253,252,253},
{29,27,21},
{255,255,255},
{0,0,0},
{122,122,122},
{252,252,252},
{255,255,255},
{60,60,60},
{253,255,252},
{232,228,228},
{46,46,46},
{42,43,43},
{233,235,236},
{0,0,12},
{72,72,72},
{109,109,109},
{8,8,8},
{18,18,18},
{9,10,9},
{46,41,45},
{255,255,255},
{0,0,0},
{15,25,15},
{244,244,244},
{248,248,248},
{252,252,252},
{0,1,0},
{255,255,255},
{14,16,13},
{0,0,0},
{169,167,169},
{252,253,252},
{0,0,0},
{42,41,41},
{0,0,0},
{192,189,192},
{252,252,252},
{0,0,0},
{182,182,181},
{5,4,3},
{59,58,58},
{102,101,94},
{0,0,0},
{0,0,2},
{62,62,61},
{64,64,63},
{38,35,34},
{0,0,0},
{35,35,34},
{174,175,174},
{33,33,32},
{255,255,255},
{255,255,255},
{210,212,210},
{255,255,255},
{0,0,0},
{255,255,255},
{21,21,22},
{1,2,1},
{129,129,129},
{150,151,148},
{38,40,37},
{248,245,245},
{255,255,255},
{0,0,0},
{13,11,14},
{179,179,177},
{90,90,90},
{18,18,18}
};
private float [] transparencyData = new float[]
{
0.98797786f,0.6216274f,0.73382217f,0.85513675f,0.970294f,0.91714925f,0.9990846f,0.5674075f,0.9994812f,0.38332075f,0.23752809f,0.84135216f,0.10664803f,0.7332022f,0.6532362f,0.800861f,0.28618866f,0.8243628f,0.997358f,0.20671111f,0.4043383f,0.11465263f,0.21266776f,0.98501194f,0.98666376f,0.993428f,0.8974783f,0.75326663f,0.31368673f,0.6658167f,0.5253086f,0.76320356f,0.45995808f,0.17943466f,0.1302861f,0.99818975f,0.93939656f,0.31655753f,0.76679564f,0.45331275f,0.12186825f,0.97271544f,0.19427222f,0.745453f,0.19904125f,0.97842836f,0.9902964f,0.23960578f,0.55218077f,0.31063437f,0.36992633f,0.567894f,0.24141014f,0.3343385f,0.8330716f,0.9000377f,0.9688046f,0.3822778f,0.27503818f,0.5158329f,0.2782632f,0.3796249f,0.46295357f,0.09438509f,0.39261872f,0.25083393f,0.42871708f,0.6926224f,0.3198431f,0.35704005f,0.25489306f,0.122249186f,0.16753286f,0.15647006f,0.07072753f,0.47437036f,0.5042306f,0.42934126f,0.059163988f,0.45987165f,0.70849985f,0.5389744f,0.6095944f,0.15797526f,0.36429077f,0.06741804f,0.23420179f,0.13564533f,0.6487648f,0.50078547f,0.89513636f,0.22152519f,0.1846224f,0.1399222f,0.14854985f,0.16154802f,0.16013479f,0.5688522f,0.9910273f,0.4955632f
};
{
Container cp = getContentPane();
cp.add(new JPanel() {
private static final long serialVersionUID = 1L;
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLACK);
g2d.fillRect(0, 0, 391, 464);
int limit;
synchronized(timer) {
limit = displayCount;
}
for (int i = 0; i < limit; i++) {
Polygon polygon = new Polygon(polygonData[i][0], polygonData[i][1], polygonData[i][0].length);
Color color = new Color(colorData[i][0], colorData[i][1], colorData[i][2]);
g2d.setColor(color);
AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, transparencyData[i]);
g2d.setComposite(composite);
g2d.fillPolygon(polygon);
}
}
});
pack();
timer = new Timer(delay, new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
synchronized(timer) {
if (displayCount < polygonData.length) {
displayCount++;
} else {
timer.stop();
}
repaint();
}
}
});
timer.setRepeats(true);
timer.start();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
};
frame.setSize(391, 464 + 20);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment