LoginSignup
1
1

More than 5 years have passed since last update.

[GroovyとProcessing]透視射影投影法

Posted at

透視射影投影法で描画する。
Processing公式のサンプルは立方体を描画している。
今回は動画に沿って宇宙っぽいものを描画する。
上キーでスピードアップ、下キーでスピードダウン、スペースキーでスピードを0にしてCキーで初期値に戻る。

動画リスト:LWJGLのチュートリアル
動画はココ

package episode016

import processing.core.PApplet

class DisplayTest extends PApplet {

    def z = 0
    def speed = 0
    def points = []

    def void setup() {
        size(640, 480, P3D)
        frameRate(60)

        10000.times {
            points << [x: random(width), y: random(height), z: random(200) - 200]
        }
    }

    def void draw() {
        background(0, 0, 0)

        perspective(30, width / height, 0.01, 200)

        z += speed
        translate(0, 0, z)

        noSmooth()
        stroke(255, 255, 255)
        strokeWeight(1)
        points.each {
            point((float)it.x, (float)it.y, (float)it.z)
        }
    }

    def void keyPressed() {
        if (keyCode == UP) {
            speed += 1
        }
        if (keyCode == DOWN) {
            speed -= 1
        }
        if (key == ' ') {
            speed = 0
        }
        if (key == 'c') {
            speed = 0
            z = 0
        }
    }

    def static void main(args) {
        PApplet.main('episode016.DisplayTest')
    }
}

grocessingGL016.png

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1