Skip to content

Instantly share code, notes, and snippets.

@w568w
Created August 18, 2017 11:29
Show Gist options
  • Select an option

  • Save w568w/0e6e398577ade3de245daeb990f3e473 to your computer and use it in GitHub Desktop.

Select an option

Save w568w/0e6e398577ade3de245daeb990f3e473 to your computer and use it in GitHub Desktop.
Draw a hexagon on a Pixmap(by libGdx).
/**
* 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])
}
}
@MobyDrake
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment