LoginSignup
0
0

More than 5 years have passed since last update.

[GroovyとProcessing]X軸方向にスライドする

Posted at

マウスを左右に移動させると画面を左右にスライドさせる。
動画ではスペースキー押下とマウスを組み合わせているけどProcessingではキー入力中はマウスが動かなかったのでスペースキーの押下でフラグを切り替えることにした。
あと、pushMatrix()とpopMatrix()を書いてても書いてなくても動作に変化はなかったのでその辺のサンプルとしては意味が無い・・・。

package episode017

import processing.core.PApplet

class DisplayTest extends PApplet {

    def translation_x =0
    def moveEnabled = false

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

        // 正射影投影法
        ortho()
    }

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

        pushMatrix()

        if (moveEnabled) translation_x += mouseX - pmouseX

        translate(translation_x, 0, 0)

        stroke(255, 255, 255)
        fill(255, 255, 255)
        rect(400, 300, 50, 50)
        line(100, 100, 200, 200)

        popMatrix()
    }

    def void keyTyped() {
        if (key == ' ') {
            moveEnabled = !moveEnabled
        }
    }

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

grocessingGL017.png

0
0
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
0
0