Wednesday, September 23, 2009

groovyとJOGLでテクスチャの張られたポリゴンを描画する

groovyとJOGLでテクスチャの張られたポリゴンを描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;
import com.sun.opengl.util.texture.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
Texture texture = TextureIO.newTexture(
new File("sf.jpg"), true)
texture.enable()
texture.bind()
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// テクスチャが張られたポリゴンを描画
gl.glBegin(GL_POLYGON)
gl.glTexCoord2f(0.0f, 1.0f)
gl.glVertex3f(-1.5f, -1.5f, 0.0f)
gl.glTexCoord2f(1.0f, 1.0f)
gl.glVertex3f(1.5f, -1.5f, 0.0f)
gl.glTexCoord2f(1.0f, 0.0f)
gl.glVertex3f(1.5f, 1.5f, 0.0f)
gl.glTexCoord2f(0.0f, 0.0f)
gl.glVertex3f(-1.5f, 1.5f, 0.0f)
gl.glEnd()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1287a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1287a.png)
groovyとJOGLで描画したテクスチャの張られたポリゴン

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Tuesday, September 22, 2009

groovyとJOGLでつぶれた球を描画する

groovyとJOGLでつぶれた球を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f)
// 球を描画
gl.glScalef(1f,1f,0.5f)
glut.glutSolidSphere(1.5f, 32, 32)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1286a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1286a.png)
groovyとJOGLで描画したつぶれた球

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Monday, September 21, 2009

groovyとJOGLで立方体の市松模様を描画する

groovyとJOGLで立方体の市松模様を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(-4.0f, -6.0f, -25.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
// gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// X軸回転
gl.glRotatef(30.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(35.0f, 0.0f, 1.0f, 0.0f)

cs = 0.4f
gs = 0.5f
xs = 20
ys = 20
for(ly in 0..ys-1){
for(lx in 0..xs-1){
if( (lx+ly)%2 == 0 ){
gl.glColor3f(
0xff/0xff as Float,
0xff/0xff as Float,
0xff/0xff as Float
)
} else {
gl.glColor3f(
0xe0/0xff as Float,
0xb0/0xff as Float,
0x40/0xff as Float
)
}
gl.glTranslatef(gs, 0.0f, 0.0f)
glut.glutSolidCube(cs)
}
gl.glTranslatef(-gs*xs as Float, gs, 0.0f)
}
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1285a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1285a.png)
groovyとJOGLで描画した立方体の市松模様

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Sunday, September 20, 2009

groovyとJOGLで市松模様の面を描画する

groovyとJOGLで市松模様の面を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(-2.0f, -2.0f, -12.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
// gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// X軸回転
gl.glRotatef(-70.0f, 1.0f, 0.0f, 0.0f)

tw = 0.4f
th = 0.4f
xs = 10
ys = 10
for(ly in 0..ys-1){
for(lx in 0..xs-1){
if( (lx+ly)%2 == 0 ){
gl.glColor3f(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float
)
} else {
gl.glColor3f(
0x40/0xff as Float,
0x40/0xff as Float,
0x40/0xff as Float
)
}
gl.glRectf(lx*tw as Float,
ly*th as Float,
(lx+1)*tw as Float,
(ly+1)*tw as Float)
}
}
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1284a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1284a.png)


動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

PyWin32とImageMagickで直線を描画する

PyWin32とImageMagickで直線を描画するには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("-size", "200x200", "xc:white",
"-stroke", "#7799ff",
"-draw", "stroke-width 4 line 0,0,199,199", "sample1333a.png")


出力画像(sample1333a.png)
PyWin32とImageMagickで描画した直線

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

Saturday, September 19, 2009

groovyとJOGLでビットマップ文字列を描画する

groovyとJOGLでビットマップ文字列を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -12.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// ビットマップ文字の描画
gl.glRasterPos2f(-1f, 0.0f)

glut.glutBitmapCharacter(GLUT.BITMAP_8_BY_13, 'A' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_9_BY_15, 'B' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_10, 'C' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_12, 'D' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_HELVETICA_18, 'E' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_TIMES_ROMAN_10, 'F' as char)
glut.glutBitmapCharacter(GLUT.BITMAP_TIMES_ROMAN_24, 'G' as char)
// ビットマップ文字列の描画
glut.glutBitmapString(GLUT.BITMAP_TIMES_ROMAN_24, "123");
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1283a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1283a.png)
groovyとJOGLで描画したビットマップ文字列

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Friday, September 18, 2009

groovyとJOGLで2つのワイヤーフレームの立方体を重ね書きする

groovyとJOGLで2つのワイヤーフレームの立方体を重ね書きするには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x40/0xff as Float,
0x40/0xff as Float,
0x40/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -12.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(35.0f, 0.0f, 1.0f, 0.0f)
// 1つ目の立方体
gl.glColor3f(0.3f,0.5f,1.0f)
gl.glLineWidth(6f)
glut.glutWireCube(2.0f)
// 2つ目の立方体
gl.glColor3f(1f,1f,1f)
gl.glLineWidth(2f)
glut.glutWireCube(2.0f)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1282a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1282a.png)


動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Thursday, September 17, 2009

groovyとJOGLでティーポットを描画する

groovyとJOGLでティーポットを描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(-0.5f, -1.0f, -10.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
// gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(-70.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(15.0f, 0.0f, 1.0f, 0.0f)
// ティーポットを描画
glut.glutSolidTeapot(1.0f,false)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1281a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1281a.png)


動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Wednesday, September 16, 2009

groovyとJOGLで球を描画する

groovyとJOGLで球を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// 球を描画
glut.glutSolidSphere(1.5f, 32, 32)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1280a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1280a.png)
groovyとJOGLで描画した球

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

PyWin32とImageMagickで画像を4色グレースケールの画像に減色する

PyWin32とImageMagickで画像を4色グレースケールの画像に減色するには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-colorspace", "gray",
"-colors", "4", "sample1332a.png")


元画像(sf.jpg)


出力画像(sample1332a.png)
PyWin32とImageMagickで4色グレースケールに減色した画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

Tuesday, September 15, 2009

groovyとJOGLでひし形12面体を描画する

groovyとJOGLでひし形12面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -7.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(30.0f, 0.0f, 1.0f, 0.0f)
// ひし形12面体を描画
glut.glutSolidRhombicDodecahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1279a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1279a.png)
groovyとJOGLで描画したひし形12面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Monday, September 14, 2009

im4javaで直線を描画する

im4javaで直線を描画するには、以下のコードを実行します。


import java.util.*;
import org.im4java.core.*;
import org.im4java.process.*;

// im4java-0.98.0-bin.tar.bz2を解凍してim4java-0.98.0.jarはclasspathに通す
public class Im4java34
{
public static void main(String args[])
throws Exception
{
try
{
// ConvertCmd convert = new ConvertCmd();
ImageCommand convert = new WindowsConvertCmd();

IMOperation op = new IMOperation();
op.size(200, 200);
op.addImage("xc:white");
op.stroke("#7799ff");
op.draw("stroke-width 4 line 0,0,199,199");

op.addImage("sample1341a.png");
convert.run(op);
}
catch(CommandException cex)
{
System.out.println(cex.getErrorText());
cex.printStackTrace();
}
}

// im4java 0.98
static class WindowsConvertCmd extends ImageCommand
{
public WindowsConvertCmd()
{
setCommand("cmd");
setCommand("/c");
setCommand("convert");
/* another way
setCommand("C:\\Program Files\\ImageMagick-6.4.9-Q16\\convert");
*/
}
}
}


出力画像(sample1341a.png)
im4javaで描画した直線

関連情報
im4javaのまとめ

groovyとJOGLで8面体を描画する

groovyとJOGLで8面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -7.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(10.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// 8面体を描画
glut.glutSolidOctahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1278a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1278a.png)
groovyとJOGLで描画した8面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Sunday, September 13, 2009

groovyとJOGLで20面体を描画する

groovyとJOGLで20面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -7.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(10.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// 20面体を描画
glut.glutSolidIcosahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1277a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1277a.png)


動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Saturday, September 12, 2009

PyWin32とImageMagickで画像をタイル配置する

PyWin32とImageMagickで画像をタイル配置するには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("-size", "200x200", "tile:flower1.png", "sample1331a.png")


元画像(flower1.png)


出力画像(sample1331a.png)
PyWin32とImageMagickでタイル配置した画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

groovyとJOGLで12面体を描画する

groovyとJOGLで12面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -12.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(30.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// 12面体を描画
glut.glutSolidDodecahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1276a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1276a.png)
groovyとJOGLで描画した12面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Friday, September 11, 2009

groovyとJOGLで円柱を描画する

groovyとJOGLで円柱を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, -1.0f, -15.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(-60.0f, 1.0f, 0.0f, 0.0f)
// 円柱を描画
glut.glutSolidCylinder(2.0f, 2.5f, 16, 4)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1275a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1275a.png)
groovyとJOGLで描画した円柱

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Thursday, September 10, 2009

groovyとJOGLで円錐を描画する

groovyとJOGLで円錐を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, -1.0f, -15.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(-70.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(10.0f, 0.0f, 1.0f, 0.0f)
// 円錐を描画
glut.glutSolidCone(2.0f, 3.5f, 16, 4)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1274a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1274a.png)
groovyとJOGLで描画した円錐

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Wednesday, September 09, 2009

groovyとJOGLで立方体を描画する

groovyとJOGLで立方体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xf0/0xff as Float,
0xf0/0xff as Float,
0xf0/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glEnable(GL_LIGHTING);
gl.glEnable(GL_LIGHT0);
gl.glEnable(GL_COLOR_MATERIAL);
gl.glEnable(GL_NORMALIZE);
gl.glEnable(GL_DEPTH_TEST);
gl.glEnable(GL_CULL_FACE);
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

gl.glPushMatrix()
// 面の色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float
)
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(25.0f, 0.0f, 1.0f, 0.0f)
// 立方体を描画
glut.glutSolidCube(2.0f)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1273a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1273a.png)
groovyとJOGLで描画した立方体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Tuesday, September 08, 2009

PyWin32とImageMagickで画像を反転させる

PyWin32とImageMagickで画像を反転させるには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-negate", "sample1330a.png")


元画像(sf.jpg)


出力画像(sample1330a.png)
PyWin32とImageMagickで反転させた画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

groovyとJOGLでワイヤーフレームの四角を描画する

groovyとJOGLでワイヤーフレームの四角を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// ワイヤーフレームで四角形を描画
gl.glBegin(GL_LINE_LOOP)
gl.glVertex2f(-1,-1)
gl.glVertex2f(1,-1)
gl.glVertex2f(1,1)
gl.glVertex2f(-1,1)
gl.glEnd()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1272a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1272a.png)
groovyとJOGLで描画したワイヤーフレームの四角

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Monday, September 07, 2009

groovyとJOGLで線のスタイルを指定する

groovyとJOGLで線のスタイルを指定するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -15.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

// ラインスタイルを設定
gl.glEnable(GL_LINE_STIPPLE);
gl.glLineStipple(2, (short)0x3333);

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(10.0f, 0.0f, 1.0f, 0.0f)
// ワイヤフレームで12面体を描画
glut.glutWireDodecahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1271a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1271a.png)
groovyとJOGLで線のスタイルを指定した画像

出力画像
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Sunday, September 06, 2009

groovyとJOGLでワイヤーフレームの線の太さを指定する

groovyとJOGLでワイヤーフレームの線の太さを指定するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -15.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

// ワイヤーフレームの線の太さを設定
gl.glLineWidth(4f);

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームで円錐を描画
glut.glutWireCone(2.0f, 3f, 16, 4)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1270a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1270a.png)
groovyとJOGLでワイヤフレームの線の太さを指定した画像

出力画像
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Saturday, September 05, 2009

groovyとJOGLでワイヤーフレームのティーポットを描画する

groovyとJOGLでワイヤーフレームのティーポットを描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0xff/0xff as Float,
0xff/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -15.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

// ワイヤーフレームの色を設定
gl.glColor3f(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームでティーポットを描画する
glut.glutWireTeapot(1.5f)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1269a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1269a.png)
groovyとJOGLで描画したティーポット

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Friday, September 04, 2009

PyWin32とImageMagickでビルトインパターンの背景画像を作成する

PyWin32とImageMagickでビルトインパターンの背景画像を作成するには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("-size", "200x200", "pattern:RIGHTSHINGLE", "sample1329a.png")


出力画像(sample1329a.png)
PyWin32とImageMagickで生成したビルトインパターンの画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

groovyとJOGLでワイヤーフレームの球を描画する

groovyとJOGLでワイヤーフレームの球を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームで球を描画する
glut.glutWireSphere(1.5f, 32, 32)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1268a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1268a.png)
groovyとJOGLで描画したワイヤーフレームの球

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Thursday, September 03, 2009

groovyとJOGLでワイヤーフレームのドーナツ型を描画する

groovyとJOGLでワイヤーフレームのドーナツ型を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -15.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(20.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームでドーナツを描画する
glut.glutWireTorus(0.5f, 1f, 32, 16)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1267a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1267a.png)
groovyとJOGLで描画したワイヤーフレームのドーナツ型

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Wednesday, September 02, 2009

groovyとJOGLでワイヤーフレームのひし形12面体を描画する

groovyとJOGLでワイヤーフレームのひし形12面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームでひし形12面体を描画
glut.glutWireRhombicDodecahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1266a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1266a.png)
groovyとJOGLで描画したワイヤーフレームのひし形12面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Tuesday, September 01, 2009

groovyとJOGLでワイヤーフレームの4面体を描画する

groovyとJOGLでワイヤーフレームの4面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(30.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームで4面体を描画する
glut.glutWireTetrahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1265a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1265a.png)
groovyとJOGLで描画したワイヤーフレームの4面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

PyWin32とImageMagickで画像を回転させる

PyWin32とImageMagickで画像を回転させるには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-background", "#7799ff",
"-rotate", "30", "sample1326a.png")


元画像(sf.jpg)


出力画像(sample1326a.png)
PyWin32とImageMagickで回転させた画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

Monday, August 31, 2009

groovyとJOGLでワイヤーフレームのティーポットを描画する

groovyとJOGLでワイヤーフレームのティーポットを描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(45.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームでティーポットを描画
glut.glutWireTeapot(1.5f)
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1264a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1264a.png)
groovyとJOGLで描画したワイヤーフレームのティーポット

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Sunday, August 30, 2009

groovyとJOGLでワイヤーフレームの8面体を描画する

groovyとJOGLでワイヤーフレームの8面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(30.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームの8面体を描画
glut.glutWireOctahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1263a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1263a.png)
groovyとJOGLで描画したワイヤーフレームの8面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Saturday, August 29, 2009

groovyとJOGLでワイヤーフレームの20面体を描画する

groovyとJOGLでワイヤーフレームの20面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -10.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームの20面体を描画する
glut.glutWireIcosahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1262a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1262a.png)
groovyとJOGLで描画したワイヤーフレームの20面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

PyWin32とImageMagickで画像をビデオ風に変換する

PyWin32とImageMagickで画像をビデオ風に変換するには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-fx", "j%2==0?p:p*0.5", "sample1328a.png")


元画像(sf.jpg)


出力画像(sample1328a.png)
PyWin32とImageMagickでビデオ風に変換した画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

PyWin32とImageMagickで画像を傾ける

PyWin32とImageMagickで画像を傾けるには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-background", "#7799ff",
"-shear", "10x0", "sample1327a.png")


元画像(sf.jpg)


出力画像(sample1327a.png)
PyWin32とImageMagickで傾けた画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

PyWin32とImageMagickで画像をスクロールさせる

PyWin32とImageMagickで画像をスクロールさせるには、以下のコードを実行します。


# coding=UTF-8
import win32com.client

im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
# 横方向に20ピクセル分スクロール
im.convert("sf.jpg", "-roll", "+20+0", "sample1325a.png")
# 縦方向に20ピクセル分スクロール
im.convert("sf.jpg", "-roll", "+0+20", "sample1325b.png")


元画像(sf.jpg)


出力画像1(sample1325a.png)
PyWin32とImageMagickで横方向にスクロールした画像

出力画像2(sample1325b.png)
PyWin32とImageMagickで縦方向にスクロールした画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

PyWin32とImageMagickで画像をグレースケールに変換する

PyWin32とImageMagickで画像をグレースケールに変換するには、以下のコードを実行します。


import win32com.client
im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-colorspace", "gray", "sample1324a.png")


元画像(sf.jpg)


出力画像(sample1324a.png)
PyWin32とImageMagickでグレースケールに変換した画像

動作環境
Python3.1.1, Python for Windows Extensions (Build 214), ImageMagick6.5.5

Friday, August 28, 2009

groovyとJOGLでワイヤーフレームの12面体を描画する

groovyとJOGLでワイヤーフレームの12面体を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, 0.0f, -15.0f)

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(45.0f, 1.0f, 0.0f, 0.0f)
// Y軸回転
gl.glRotatef(20.0f, 0.0f, 1.0f, 0.0f)
// ワイヤーフレームの十二面体を描画する
glut.glutWireDodecahedron()
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1261a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1261a.png)
groovyとJOGLで描画したワイヤーフレームの12面体

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

Thursday, August 27, 2009

groovyとJOGLでワイヤーフレームの円柱を描画する

groovyとJOGLでワイヤーフレームの円柱を描画するには、以下のコードを実行します。


import static javax.media.opengl.GL.*;
import java.io.*;
import javax.media.opengl.*;
import com.sun.opengl.util.*;

// 出力画像サイズ
width = 300
height = 300

GLDrawableFactory gldf =
GLDrawableFactory.getFactory()
GLCapabilities glc = new GLCapabilities()
glc.setDoubleBuffered(false)
GLPbuffer buf = gldf.createGLPbuffer(
glc, null, width, height, null)
GL gl = buf.getGL()

buf.addGLEventListener(
[ init: {
// 背景色
gl.glClearColor(
0x77/0xff as Float,
0x99/0xff as Float,
0xff/0xff as Float,
1f)
},

display: {
GLUT glut = new GLUT()
gl.glViewport(0, 0, width, height)

// 透視投影
gl.glMatrixMode(GL_PROJECTION)
gl.glLoadIdentity()
float ratio = height/width as Float
gl.glFrustum(-1.0f, 1.0f, -ratio, ratio,
5.0f, 40.0f)

gl.glMatrixMode(GL_MODELVIEW)
gl.glLoadIdentity()
gl.glTranslatef(0.0f, -1.0f, -15.0f);

gl.glClear(GL_COLOR_BUFFER_BIT)

gl.glPushMatrix()
// X軸回転
gl.glRotatef(-60.0f, 1.0f, 0.0f, 0.0f);
// ワイヤーフレームの円柱を描画
glut.glutWireCylinder(2.0f, 2.5f, 16, 4);
gl.glPopMatrix()
},

reshape: {},
displayChanged: {}
] as GLEventListener
)
GLContext context =
buf.createContext(null)
context.makeCurrent()
buf.display()
Screenshot.writeToFile(
new File("sample1260a.png"),
width, height, true)
context.release()
context.destroy()


出力画像(sample1260a.png)
groovyとJOGLで描画したワイヤーフレームの円柱

動作環境
JDK1.6 Update14, Groovy 1.6.3, JOGL 1.1.1a

関連情報
groovyとJOGLのまとめ

PyWin32とImageMagickのインストール

PyWin32とImageMagickのインストールするには、以下の手順を実行します。

1.ImageMagick(ImageMagick-6.5.5-3-Q16-windows-dll.exeなどのDLL版)を
http://www.imagemagick.org/script/binary-releases.php#windows
からダウンロードして、installする。この際、インストーラーで、
Install ImageMagickObject OLE Control for VBscript, Visual Base, and WSHに
チェックを入れる。(失敗する場合は、VC++2008 Redistributable Packageを入れる)

2.http://www.python.org/download/からpythonをダウンロードして、
python3.1.1のインストール

3.以下のページからWin32 Extensions for Pythonをダウンロードしてインストール
http://starship.python.net/crew/mhammond/win32/Downloads.html

4.動作確認
以下のコードを実行して、画像の縮小を行います。

import win32com.client
im = win32com.client.Dispatch("ImageMagickObject.MagickImage.1")
im.convert("sf.jpg", "-resize", "100x100", "sample1323a.png")


元画像(sf.jpg)


出力画像(sample1323a.png)
PyWin32とImageMagickで縮小した画像