Skip to content

Commit bdf849f

Browse files
committed
initial commit
0 parents  commit bdf849f

File tree

8 files changed

+2718
-0
lines changed

8 files changed

+2718
-0
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# gradle
2+
3+
.gradle/
4+
build/
5+
out/
6+
7+
# idea
8+
9+
.idea/
10+
*.iml
11+
*.ipr
12+
*.iws
13+
14+
# vscode
15+
16+
.settings/
17+
.vscode/
18+
bin/
19+
.classpath
20+
.project
21+
node_modules/
22+
lib/
23+
24+
# fabric
25+
26+
run/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 Lasm Gratel.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NoiseVisualizer
2+
3+
Only supports **Java 11+**!

build.gradle

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
plugins {
2+
id 'java'
3+
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
4+
id 'application'
5+
id 'org.openjfx.javafxplugin' version '0.0.8'
6+
}
7+
8+
group 'com.projecturanus.noisevisualizer'
9+
version '1.0-SNAPSHOT'
10+
11+
sourceCompatibility = 11
12+
13+
repositories {
14+
jcenter()
15+
}
16+
17+
application {
18+
mainClassName = 'com.projecturanus.noisevisualizer.NoiseVisualizerKt'
19+
}
20+
21+
javafx {
22+
version = "11.0.2"
23+
modules = [ 'javafx.controls', 'javafx.graphics' ]
24+
}
25+
26+
dependencies {
27+
testCompile group: 'junit', name: 'junit', version: '4.12'
28+
implementation "javax.vecmath:vecmath:1.5.2"
29+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
30+
implementation 'no.tornado:tornadofx:1.7.19'
31+
implementation 'org.controlsfx:controlsfx:11.0.0'
32+
}
33+
compileKotlin {
34+
kotlinOptions {
35+
jvmTarget = "1.8"
36+
}
37+
}
38+
compileTestKotlin {
39+
kotlinOptions {
40+
jvmTarget = "1.8"
41+
}
42+
}

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
rootProject.name = 'noisevisualizer'
2+

src/main/java/com/projecturanus/noisevisualizer/FastNoise.java

Lines changed: 2198 additions & 0 deletions
Large diffs are not rendered by default.

src/main/kotlin/com/projecturanus/noisevisualizer/FastNoiseKotlin.kt

Lines changed: 217 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
package com.projecturanus.noisevisualizer
2+
3+
import javafx.animation.TranslateTransition
4+
import javafx.application.Application
5+
import javafx.beans.property.BooleanProperty
6+
import javafx.scene.*
7+
import javafx.scene.control.Label
8+
import javafx.scene.input.KeyCode
9+
import javafx.scene.paint.Color
10+
import javafx.scene.paint.PhongMaterial
11+
import javafx.scene.shape.Box
12+
import javafx.scene.transform.Rotate
13+
import javafx.stage.Stage
14+
import javafx.util.Duration
15+
import org.controlsfx.control.RangeSlider
16+
import tornadofx.*
17+
import java.util.*
18+
import kotlin.math.abs
19+
20+
private var blockMap = (0 until 16).map { (0 until 256).map { arrayListOf<Box>() }.toCollection(arrayListOf()) }.toCollection(arrayListOf())
21+
22+
private var mousePosX: Double = 0.0
23+
private var mousePosY: Double = 0.0
24+
private var mouseOldX: Double = 0.0
25+
private var mouseOldY: Double = 0.0
26+
27+
val noise = FastNoise(Random().nextInt())
28+
29+
// Coloring threshold
30+
var lowValueColoring = 0.0
31+
var highValueColoring = 0.0
32+
33+
// Filtering threshold
34+
var lowValueFiltering = 0.0
35+
var highValueFiltering = 0.0
36+
37+
var enableColoring: BooleanProperty = false.toProperty()
38+
var enableFiltering: BooleanProperty = false.toProperty()
39+
40+
class NoiseVisualizer : Application() {
41+
42+
override fun start(primaryStage: Stage) {
43+
println(blockMap)
44+
val root = Group()
45+
for (x in 0 until 16) {
46+
for (y in 0 until 128) {
47+
for (z in 0 until 16) {
48+
// Creating an object of the class Box
49+
val box = Box()
50+
box.setOnMouseMoved { }
51+
box.width = 50.0
52+
box.height = 50.0
53+
box.depth = 50.0
54+
box.userData = Triple(x, y, z)
55+
box.material = PhongMaterial()
56+
box.translateX = x * 70.0
57+
box.translateY = y * 70.0
58+
box.translateZ = z * 70.0
59+
blockMap[x][y].add(z, box)
60+
root.children.add(box)
61+
}
62+
}
63+
}
64+
syncColor()
65+
66+
val scene = Scene(root, 800.0, 600.0, true, SceneAntialiasing.BALANCED)
67+
68+
val rotateX = Rotate(30.0, 500.0, 500.0, 500.0, Rotate.X_AXIS)
69+
val rotateY = Rotate(20.0, 500.0, 500.0, 500.0, Rotate.Y_AXIS)
70+
root.transforms.addAll(rotateX, rotateY)
71+
root.children.add(AmbientLight(Color.WHITE))
72+
73+
scene.setOnMousePressed { me ->
74+
mouseOldX = me.sceneX
75+
mouseOldY = me.sceneY
76+
}
77+
scene.setOnMouseDragged { me ->
78+
mousePosX = me.sceneX
79+
mousePosY = me.sceneY
80+
rotateX.angle = rotateX.angle - (mousePosY - mouseOldY)
81+
rotateY.angle = rotateY.angle + (mousePosX - mouseOldX)
82+
mouseOldX = mousePosX
83+
mouseOldY = mousePosY
84+
}
85+
val camera = PerspectiveCamera(true)
86+
camera.nearClip = 0.1
87+
camera.farClip = 10000.0
88+
camera.translateX = 0.0
89+
camera.translateY = 0.0
90+
camera.translateZ = -100.0
91+
scene.setOnKeyPressed {
92+
val animation = TranslateTransition(Duration.millis(100.0))
93+
animation.node = camera
94+
when (it.code) {
95+
KeyCode.W -> animation.byZ = 300.0
96+
KeyCode.A -> animation.byX = -300.0
97+
KeyCode.S -> animation.byZ = -300.0
98+
KeyCode.D -> animation.byX = 300.0
99+
}
100+
animation.play()
101+
}
102+
scene.fill = Color.WHITE
103+
scene.camera = camera
104+
105+
primaryStage.scene = scene
106+
primaryStage.show()
107+
showConfigStage()
108+
}
109+
110+
fun showConfigStage() {
111+
val stage = Stage()
112+
val pane = ConfigView().root
113+
val scene = Scene(pane, 600.0, 400.0)
114+
stage.scene = scene
115+
stage.show()
116+
}
117+
}
118+
119+
fun syncColor() {
120+
for (x in 0 until 16) {
121+
for (y in 0 until 128) {
122+
for (z in 0 until 16) {
123+
val box = blockMap[x][y][z]
124+
val noise = noise.GetNoise(x.toFloat(), y.toFloat(), z.toFloat()).toDouble()
125+
box.visibleProperty().value = true
126+
(box.material as PhongMaterial).diffuseColor = Color.grayRgb(abs(noise * 255).toInt())
127+
if (enableFiltering.value) {
128+
if (noise !in lowValueFiltering..highValueFiltering) {
129+
box.visibleProperty().value = false
130+
}
131+
}
132+
if (enableColoring.value) {
133+
if (noise in lowValueColoring..highValueColoring) {
134+
(box.material as PhongMaterial).diffuseColor = Color.rgb(abs(noise * 255).toInt() + 1, 0, 0)
135+
}
136+
}
137+
}
138+
}
139+
}
140+
}
141+
142+
class ConfigView : View() {
143+
override val root = gridpane {
144+
paddingAll = 10.0
145+
row {
146+
label { text = "Frequency" }
147+
val slider = slider(0, 1)
148+
slider.valueProperty().addListener { observable, oldValue, newValue -> noise.m_frequency = newValue.toFloat() }
149+
label(slider.valueProperty())
150+
}
151+
row {
152+
label { text = "Noise type" }
153+
combobox(null, FastNoise.NoiseType.values().toList()) {
154+
value = FastNoise.NoiseType.Perlin
155+
selectionModel.selectedItemProperty().onChange { noise.m_noiseType = it ?: FastNoise.NoiseType.Perlin }
156+
}
157+
}
158+
row {
159+
label { text = "Interpolation (Only in Fractal noise)" }
160+
combobox(null, FastNoise.Interp.values().toList()) {
161+
value = FastNoise.Interp.Quintic
162+
selectionModel.selectedItemProperty().onChange { noise.m_interp = it ?: FastNoise.Interp.Quintic }
163+
}
164+
}
165+
row {
166+
checkbox {
167+
text = "Enable coloring"
168+
selectedProperty().value = false
169+
enableColoring.bind(selectedProperty())
170+
}
171+
}
172+
row {
173+
label { text = "Light up threshold" }
174+
lateinit var range: Label
175+
RangeSlider(-1.0, 1.0, -0.4, 0.6).attachTo(this) {
176+
disableProperty().value = true
177+
enableColoring.onChange { disableProperty().set(!it) }
178+
lowValueProperty().onChange { lowValueColoring = it; range.text = "$lowValue~$highValue" }
179+
highValueProperty().onChange { highValueColoring = it; range.text = "$lowValue~$highValue" }
180+
}
181+
range = label()
182+
}
183+
row {
184+
checkbox {
185+
text = "Enable filtering"
186+
selectedProperty().value = false
187+
enableFiltering.bind(selectedProperty())
188+
}
189+
}
190+
row {
191+
label { text = "Filtering threshold" }
192+
lateinit var range: Label
193+
RangeSlider(-1.0, 1.0, -0.4, 0.6).attachTo(this) {
194+
disableProperty().value = true
195+
enableFiltering.onChange { disableProperty().set(!it) }
196+
lowValueProperty().onChange { lowValueFiltering = it; range.text = "$lowValue~$highValue" }
197+
highValueProperty().onChange { highValueFiltering = it; range.text = "$lowValue~$highValue" }
198+
}
199+
range = label()
200+
}
201+
row {
202+
button("Rebuild").setOnMouseClicked { syncColor() }
203+
}
204+
}
205+
}
206+
207+
fun main(args: Array<String>) {
208+
Application.launch(NoiseVisualizer::class.java, *args)
209+
}

0 commit comments

Comments
 (0)