A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/AlmasB/FXGL/commit/eab55b5b6 below:

added interpolateIntermediateImages() · AlmasB/FXGL@eab55b5 · GitHub

File tree Expand file treeCollapse file tree 2 files changed

+46

-1

lines changed

Filter options

Expand file treeCollapse file tree 2 files changed

+46

-1

lines changed Original file line number Diff line number Diff line change

@@ -6,6 +6,7 @@

6 6 7 7

package com.almasb.fxgl.texture

8 8 9 +

import com.almasb.fxgl.animation.AnimatedImage

9 10

import com.almasb.fxgl.core.concurrent.Async

10 11

import com.almasb.fxgl.logging.Logger

11 12

import javafx.scene.Group

@@ -611,3 +612,34 @@ fun writeToFile(image: Image, filePath: Path): Boolean {

611 612

}

612 613

}

613 614 615 +

/**

616 +

* Using given [images] interpolates between them to produce intermediate images (inbetweening).

617 +

* The given [images] list must have at least 2 images, otherwise a new list containing the originals is returned.

618 +

*

619 +

* @return list with intermediate images, including the original images.

620 +

* The new list size is (images.size - 1) * [numFramesBetweenImages] + (images.size).

621 +

*/

622 +

fun interpolateIntermediateImages(images: List<Image>, numFramesBetweenImages: Int): List<Image> {

623 +

if (images.size < 2)

624 +

return ArrayList(images)

625 + 626 +

val result = arrayListOf<Image>()

627 + 628 +

images.zipWithNext().forEach { (img1, img2) ->

629 +

val anim = AnimatedImage(img1, img2)

630 + 631 +

result += img1

632 + 633 +

repeat(numFramesBetweenImages) { i ->

634 + 635 +

// we add +1 since i == 0 will give us [img1], which we add manually, so ignore

636 +

// and i+1 == numFramesBetweenImages will give us [img2],

637 +

// which we also add manually during next cycle, so ignore by +1

638 +

result += anim.getValue((i + 1) / (numFramesBetweenImages.toDouble() + 1))

639 +

}

640 +

}

641 + 642 +

result += images.last()

643 + 644 +

return result

645 +

}

Original file line number Diff line number Diff line change

@@ -10,9 +10,9 @@ import javafx.geometry.HorizontalDirection

10 10

import javafx.geometry.VerticalDirection

11 11

import javafx.scene.paint.Color

12 12

import org.hamcrest.MatcherAssert.assertThat

13 +

import org.hamcrest.Matchers.*

13 14

import org.junit.jupiter.api.Test

14 15 15 - 16 16

/**

17 17

*

18 18

* @author Almas Baimagambetov (almaslvl@gmail.com)

@@ -64,4 +64,17 @@ class ImagesTest {

64 64 65 65

assertThat("Diagonal flip is not correct", matchPixels(expected, Texture(result)))

66 66

}

67 + 68 +

@Test

69 +

fun `Interpolate intermediate images`() {

70 +

val img1 = ColoredTexture(200, 200, Color.WHITE).image

71 +

val img2 = ColoredTexture(200, 200, Color.RED).image

72 +

val img3 = ColoredTexture(200, 200, Color.BLACK).image

73 + 74 +

val result = interpolateIntermediateImages(listOf(img1, img2, img3), 10)

75 +

assertThat(result.size, `is`(10*2 + 3))

76 +

assertThat(result[0], `is`(img1))

77 +

assertThat(result[11], `is`(img2))

78 +

assertThat(result[22], `is`(img3))

79 +

}

67 80

}

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4