Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Timeline for Draw a regular polygon

Current License: CC BY-SA 3.0

23 events
when toggle format what by license comment
Jun 17, 2020 at 9:04 history edited Community Bot
Commonmark migration
Feb 9, 2017 at 9:10 comment added Kevin Cruijssen Since you specified it as Java 8, you can change class D{public static void main( to interface D{static void main( to save 3 more bytes.
Oct 18, 2016 at 17:22 comment added FThompson @KevinCruijssen Hah nice one!
Oct 18, 2016 at 13:49 comment added Kevin Cruijssen @Vulcan Actually, r=Short.valueOf(v[0]),s=Short.valueOf(v[1]) can be golfed to r=new Short(v[0]),s=new Short(v[1]) (-8 bytes) - and yes, I know this answer is from 2+ years ago. ;) And I agree, great work with this answer!
Apr 17, 2014 at 23:29 comment added FThompson I can't think of anything else to further reduce the bytes either; great work.
Apr 17, 2014 at 19:44 comment added Geobits @Vulcan Never knew about drawPolygon, nice. Might as well shave off 3 more by pulling the loop in. I'm running out of stuff to do here...
Apr 17, 2014 at 19:43 history edited Geobits CC BY-SA 3.0
deleted 118 characters in body
Apr 17, 2014 at 4:25 comment added FThompson Reduced to 325 bytes by using drawPolygon instead of drawLine. Whitespace version.
Apr 17, 2014 at 2:45 history edited Geobits CC BY-SA 3.0
added 13 characters in body
Apr 17, 2014 at 2:42 comment added Geobits @Vulcan Nice! I didn't think about pulling setSize() in, so I couldn't figure out a way to get rid of the Frame.
Apr 17, 2014 at 2:37 comment added FThompson @Geobits Great improvements. Working off of your reduced version, I've cut it down further to 349 bytes by eliminating the Frame as a local variable, removing the d integer, and using/abusing the for-loop to save a few characters, mainly semicolons. Here's a version with whitespace as well.
Apr 17, 2014 at 2:18 history edited Geobits CC BY-SA 3.0
moved to Java 8, removed `final `
Apr 16, 2014 at 23:26 comment added Geobits @Vulcan I got it down another 120 (mainly by trashing the BufferedImage and Graphics altogether and just throwing everything in paint()). It did change the color of the image, though it still looks good IMO. Thanks for making me take another look at this :)
Apr 16, 2014 at 23:24 history edited Geobits CC BY-SA 3.0
we're slashin' bytes in here!
Apr 16, 2014 at 22:15 comment added FThompson I've reduced it to 500 bytes using a few tricks. 1) Use Short.valueOf instead of Integer.valueOf to save four bytes, as input should never exceed the range of shorts. 2) y[]=x.clone() saves one byte over y[]=new int[s]. 3) Use the deprecated f.show(); instead of f.setVisible(1>0); to save an addition nine bytes. 4) Use 6.28 instead of Math.PI*2, as the estimation is accurate enough for this purpose, saving three bytes. 5) Declare Graphics g instead of Graphics2D g when creating the graphics instance to save two bytes.
Apr 16, 2014 at 15:35 history edited Geobits CC BY-SA 3.0
thanks, Vulcan!
Apr 16, 2014 at 15:32 comment added FThompson Eliminate 12 bytes by importing java.awt.image.* instead of java.awt.image.BufferedImage
Apr 16, 2014 at 11:59 comment added Rob Audenaerde Oh yes, you are right.. An enum needs at least an enum definition
Apr 16, 2014 at 11:44 history edited Geobits CC BY-SA 3.0
not sure why I wrote 9 o_O
Apr 16, 2014 at 11:41 comment added Geobits @RobAu The only way I can get that to compile is by adding a ; and losing the saved character.
Apr 16, 2014 at 11:32 comment added Rob Audenaerde Shave off a byte by replacing class by enum
Apr 16, 2014 at 10:09 history edited user12205 CC BY-SA 3.0
Syntax highlighting
Apr 16, 2014 at 2:31 history answered Geobits CC BY-SA 3.0
toggle format

AltStyle によって変換されたページ (->オリジナル) /