Index > N2 ... 六角形の描画用コード
Sun, November 1, 2009

N2 ... 六角形の描画用コード

一層

import sys
import commons
import ntwo.drawing as md
import painter as painter

import java.lang as lang
import java.io as io
import java.awt as awt




OUTFILE=io.File( sys.argv[1] )
W=lang.Integer.parseInt(sys.argv[2])
H=lang.Integer.parseInt(sys.argv[3])


bimg=commons.createImage(awt.Dimension(W,H))
g2=bimg.getGraphics()
g2.setRenderingHints(commons.getGoodRenderingHints())

# paint background as white
g2.setColor(awt.Color.WHITE)
g2.fill(awt.Rectangle(W,H))


# create honeycombOne obj.
honeycomb=md.HoneycombOne()
honeycomb.setSize(awt.Dimension(W,H))


# draw hexagon
cnt=0
for shape in honeycomb.getHexagonShapes():

    g2.setColor(awt.Color.BLACK) # hexagon border color is black 
    g2.draw(shape)

    cell=shape.getHexagonCell()

    #tbUtil=md.TextBoxLocationCalcUtil(cell)
    #tbUtil.setInsets(awt.Insets(-2,5,-2,5))
    #rect=tbUtil.getRectangle()
    rect=cell.getTextBoxRectangle(awt.Insets(-2,5,-2,5))

    g2.setColor(awt.Color(0xEE,0xEE,0xEE)) # paint textBox as gray
    g2.fill(rect)

    g2.setColor(awt.Color.BLACK) # paint text as black
    tp=painter.TextPainter()
    tp.location=rect.location
    tp.size=rect.size

    cnt=cnt+1
    tp.text=str(cnt)+")Hello world."

    tp.paint(g2)

g2.dispose()
commons.outputAsPNG(bimg,OUTFILE)

二層

import sys
import commons
import ntwo.drawing as md
import painter as painter

import java.lang as lang
import java.io as io
import java.awt as awt




OUTFILE=io.File( sys.argv[1] )
W=lang.Integer.parseInt(sys.argv[2])
H=lang.Integer.parseInt(sys.argv[3])


bimg=commons.createImage(awt.Dimension(W,H))
g2=bimg.getGraphics()
g2.setRenderingHints(commons.getGoodRenderingHints())

# paint background as white
g2.setColor(awt.Color.WHITE)
g2.fill(awt.Rectangle(W,H))


# create honeycombOne obj.
honeycomb=md.HoneycombTwo()
honeycomb.setSize(awt.Dimension(W,H))

# font
g2.setFont( awt.Font("Dialog",awt.Font.PLAIN,9) )


# draw hexagon
cnt=0
for shape in honeycomb.getHexagonShapes():

    g2.setColor(awt.Color.BLACK) # hexagon border color is black 
    g2.draw(shape)

    cell=shape.getHexagonCell()

    #tbUtil=md.TextBoxLocationCalcUtil(cell)
    #tbUtil.setInsets(awt.Insets(-2,5,-2,5))
    #rect=tbUtil.getRectangle()
    rect=cell.getTextBoxRectangle(awt.Insets(-2,5,-2,5))

    g2.setColor(awt.Color(0xEE,0xEE,0xEE)) # paint textBox as gray
    g2.fill(rect)

    g2.setColor(awt.Color.BLACK) # paint text as black

    g2.setColor(awt.Color.BLACK) # paint text as black
    tp=painter.TextPainter()
    tp.location=rect.location
    tp.size=rect.size

    cnt=cnt+1
    tp.text=str(cnt)+")Hello world."

    tp.paint(g2)

g2.dispose()
commons.outputAsPNG(bimg,OUTFILE)
 Twitter
follow me on Twitter
 Categories