Help us understand the problem. What is going on with this article?

[GroovyとProcessing]図形の移動

More than 5 years have passed since last update.

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

動画リスト: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

hina0118
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away