LoginSignup
1
1

More than 5 years have passed since last update.

[GroovyとProcessing]図形の移動

Last updated at Posted at 2013-10-12

時間が経つごとに図形が右下に移動していく
(動画内ではフレームレートについての説明をしている)

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

DisplayTest.groovy
package episode007

import groovy.swing.SwingBuilder
import processing.core.PApplet

import javax.swing.*

class DisplayTest extends PApplet {

    def lastFrame

    def posX, posY
    def dx = 1, dy = 1

    def void setup() {
        frameRate(60)

        lastFrame = System.currentTimeMillis()
        posX = 100
        posY = 100
    }

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

        def delta = delta   // getDelta()
        posX += delta * dx * 0.1
        posY += delta * dy * 0.1

        noStroke()
        fill(255, 255, 255)
        rect(posX, posY, 50, 50)
    }

    def getDelta() {
        def currentTime = System.currentTimeMillis()
        def delta = currentTime - lastFrame
        lastFrame = currentTime
        delta
    }

    def static void main(args) {
        def display = new DisplayTest()
        new SwingBuilder().frame(
                title: 'Episode 3',
                defaultCloseOperation: JFrame.EXIT_ON_CLOSE,
                size: [640, 480], show: true) {
            widget(display)
        }
        display.init()
    }
}

grocessingGL007.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