Created
August 18, 2017 11:29
-
-
Save w568w/0e6e398577ade3de245daeb990f3e473 to your computer and use it in GitHub Desktop.
Draw a hexagon on a Pixmap(by libGdx).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Created by w568w on 2017-7-29. | |
| */ | |
| class CommonDrawer : SixPloDrawer { | |
| var w: Int = 0 | |
| var height: Int = 0 | |
| override fun draw(pixmap: Pixmap?, color: Color?) { | |
| this.w = pixmap!!.width | |
| height = (w / 4 * Math.sqrt(3.0)).toInt() | |
| pixmap.setColor(color) | |
| pixmap.drawRightTriangle(0, height, true) | |
| pixmap.drawRightTriangle(0, height, false) | |
| pixmap.drawRightTriangle(w / 2, height, true) | |
| pixmap.drawRightTriangle(w / 2, height, false) | |
| pixmap.drawRightTriangle(w / 4, height * 2, false) | |
| pixmap.drawRightTriangle(w / 4, 0, true) | |
| } | |
| private fun Pixmap.drawRightTriangle(x: Int, y: Int, isUp: Boolean) { | |
| this.fillTriangle(x, y, x + w / 2, y, x + w / 4, y + if (isUp) [email protected] else [email protected]) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx