-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.swift
64 lines (53 loc) · 1.96 KB
/
App.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import RaylibKit
@main struct ImageGeneration: Applet {
var index = 0
var textures: [TextureItem]
init() {
Window.create(800, by: 450, title: "Examples - Textures - Image Generation")
Application.target(fps: 60)
textures = [
TextureItem("VERTICAL GRADIENT", 560, .raywhite,
Image.verticalGradient(size: Window.width, by: Window.height, from: .red, to: .blue)),
TextureItem("HORIZONTAL GRADIENT", 540, .raywhite,
Image.horizontalGradient(size: Window.width, by: Window.height, from: .red, to: .blue)),
TextureItem("RADIAL GRADIENT", 580, .lightGray,
Image.radialGradient(size: Window.width, by: Window.height, from: .white, to: .black)),
TextureItem("CHECKED", 680, .raywhite,
Image.checked(size: Window.width, by: Window.height, tiles: 32, 32, colors: .maroon, .darkBlue)),
TextureItem("WHITE NOISE", 650, .red,
Image.whiteNoise(size: Window.width, by: Window.height, factor: 0.5)),
TextureItem("CELLULAR", 670, .raywhite,
Image.cellular(size: Window.width, by: Window.height, cell: 32)),
]
}
mutating func update() {
if Mouse.left.isPressed || Keyboard.right.isPressed {
index = textures.cycle(after: index)
}
if Mouse.right.isPressed || Keyboard.left.isPressed {
index = textures.cycle(before: index)
}
}
func draw() {
textures[index].draw()
Renderer2D.rectangle(at: 30, 400, size: 325, 30, color: .skyBlue.faded(to: 0.5))
WireRenderer2D.rectangle(at: 30, 400, size: 325, 30, color: .white.faded(to: 0.5))
Renderer2D.text("MOUSE LEFT BUTTON to CYCLE PROCEDURAL TEXTURES", at: 40, 410, size: 10, color: .white)
}
}
struct TextureItem {
let name: String
let position: Int
let color: Color
let texture: Texture
init(_ name: String, _ position: Int, _ color: Color, _ image: Image) {
self.name = name
self.position = position
self.color = color
texture = image.upload()
}
public func draw() {
Renderer2D.texture(texture, at: .zero)
Renderer2D.text(name, at: position, 10, color: color)
}
}