WIP - icon generator

This commit is contained in:
Trey t
2022-02-13 17:16:13 -06:00
parent 1e7199337f
commit 868b747291
41 changed files with 494 additions and 97 deletions

View File

@@ -7,17 +7,6 @@
import SwiftUI
struct CustomIcon {
let leftEye: Image
let rightEye: Image
let mouth: Image
let background: AnyView?
let bgColor: Color
let innerColor: Color
}
enum BackGroundOptions: String, CaseIterable {
case horrible
case bad
@@ -40,35 +29,64 @@ enum EyeOptions: String, CaseIterable {
case fire = "fire"
case bolt = "bolt2"
case dollar = "dollar"
case bell = "bell"
case btc = "btc"
case code = "code"
case crown = "crown"
case divide = "divide"
case exclamation = "exclamation"
case fan = "fan"
case floppy = "floppy"
case x = "x"
case skull = "skull"
case covid = "covid"
case bomb = "bomb"
case skull2 = "skull2"
case poo = "poo"
static public var defaultOption: AnyView {
let image = Image(EyeOptions.fire.rawValue, bundle: .main)
.resizable()
.frame(width: 20, height: 20)
return AnyView(image)
}
}
enum MouthOptions: String, CaseIterable {
case moonFill = "moon.fill"
case flame = "flame"
case flameCircle = "flame.circle"
case fire = "fire"
case bolt = "bolt2"
case dollar = "dollar"
case bell = "bell"
case btc = "btc"
case code = "code"
case crown = "crown"
case divide = "divide"
case exclamation = "exclamation"
case fan = "fan"
case floppy = "floppy"
case x = "x"
case skull = "skull"
case covid = "covid"
case bomb = "bomb"
case skull2 = "skull2"
case poo = "poo"
static public var defaultOption: MouthOptions {
return MouthOptions.flameCircle
static public var defaultOption: AnyView {
let image = Image(MouthOptions.bomb.rawValue, bundle: .main)
.resizable()
.frame(width: 20, height: 20)
return AnyView(image)
}
}
struct CreateIconView: View {
@State private var bgColor = Color.red
@State private var innerColor = Color.green
@State private var bgPattern = [(AnyView, UUID)]()
@State private var leftEye: AnyView = EyeOptions.defaultOption
@State private var rightEye: AnyView = EyeOptions.defaultOption
@State private var mouth: Image = Image(systemName: MouthOptions.defaultOption.rawValue)
@State private var mouth: AnyView = MouthOptions.defaultOption
@StateObject private var customIcon = CustomIcon(leftEye: EyeOptions.defaultOption,
rightEye: EyeOptions.defaultOption,
mouth: MouthOptions.defaultOption,
background: [(AnyView, UUID)](),
bgColor: .red,
innerColor: .green)
private var randomElements: [AnyView] = [
AnyView(Image(BackGroundOptions.selectable.randomElement()!.rawValue)
@@ -85,41 +103,26 @@ struct CreateIconView: View {
.frame(width: 20, height: 20))
]
let columns = [
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0)
]
func update(eye: Eyes, eyeOption: EyeOptions) {
let image = Image(eyeOption.rawValue, bundle: .main)
.resizable()
.frame(width: 20, height: 20)
switch eye {
case .left:
leftEye = AnyView(image)
customIcon.leftEye = AnyView(image)
case .right:
rightEye = AnyView(image)
customIcon.rightEye = AnyView(image)
}
}
func createRandom() {
bgColor = Color(
customIcon.bgColor = Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
)
innerColor = Color(
customIcon.innerColor = Color(
red: .random(in: 0...1),
green: .random(in: 0...1),
blue: .random(in: 0...1)
@@ -133,11 +136,14 @@ struct CreateIconView: View {
}
func update(mouthOption: MouthOptions) {
mouth = Image(systemName: mouthOption.rawValue)
let image = AnyView(Image(mouthOption.rawValue, bundle: .main)
.resizable()
.frame(width: 20, height: 20))
customIcon.mouth = image
}
func update(background: BackGroundOptions) {
bgPattern.removeAll()
customIcon.background.removeAll()
if background == .random {
for _ in 0...120 {
@@ -147,7 +153,7 @@ struct CreateIconView: View {
.resizable()
.frame(width: 20, height: 20)
bgPattern.append((AnyView(sizedImage), UUID()))
customIcon.background.append((AnyView(sizedImage), UUID()))
}
return
}
@@ -158,7 +164,7 @@ struct CreateIconView: View {
.frame(width: 20, height: 20)
for _ in 0...120 {
bgPattern.append((AnyView(sizedImage), UUID()))
customIcon.background.append((AnyView(sizedImage), UUID()))
}
}
@@ -176,44 +182,7 @@ struct CreateIconView: View {
}
var iconView: some View {
ZStack {
LazyVGrid(columns: columns, spacing: 0) {
ForEach(bgPattern, id: \.self.1) {
$0.0
}
}
.frame(width: 200, height: 200)
.position(x: 100, y: 110)
Circle()
.strokeBorder(Color.black, lineWidth: 12)
.background(Circle().fill(innerColor))
.frame(width: 120, height: 120, alignment: .center)
VStack {
Spacer()
.frame(height: 70)
HStack {
Spacer()
.frame(width: 72)
leftEye
Spacer()
.frame(width: 24)
rightEye
Spacer()
}
Spacer()
.frame(height: 28)
mouth
Spacer()
}
}
.frame(width: 200, height: 200)
.background(
bgColor
)
.cornerRadius(10)
IconView(customIcon: customIcon)
}
var body: some View {
@@ -223,9 +192,9 @@ struct CreateIconView: View {
Spacer()
VStack {
ColorPicker("Set the background color", selection: $bgColor)
ColorPicker("Set the background color", selection: $customIcon.bgColor)
.padding([.leading, .trailing])
ColorPicker("Set the inner color", selection: $innerColor)
ColorPicker("Set the inner color", selection: $customIcon.innerColor)
.padding([.leading, .trailing])
}
@@ -244,7 +213,7 @@ struct CreateIconView: View {
Menu("Right Eye") {
ForEach(EyeOptions.allCases, id: \.self) { option in
Button(action: {
update(eye: .right, eyeOption: option)
update(eye: .left, eyeOption: option)
}, label: {
Label(option.rawValue, image: option.rawValue)
})
@@ -256,7 +225,7 @@ struct CreateIconView: View {
Button(action: {
update(mouthOption: option)
}, label: {
Image(systemName: option.rawValue)
Label(option.rawValue, image: option.rawValue)
})
}
}
@@ -296,12 +265,7 @@ struct CreateIconView: View {
})
Button(action: {
// let newIcon = CustomIcon(leftEye: leftEye,
// rightEye: rightEye,
// mouth: mouth,
// background: bgPattern,
// bgColor: bgColor,
// innerColor: innerColor)
// let icon = icon
}, label: {
Text("Save")
.font(.title)

View File

@@ -0,0 +1,79 @@
//
// IconView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/13/22.
//
import SwiftUI
struct IconView: View {
@State public var customIcon: CustomIcon
let columns = [
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0),
GridItem(.fixed(20), spacing: 0)
]
var body: some View {
ZStack {
LazyVGrid(columns: columns, spacing: 0) {
ForEach(customIcon.background, id: \.self.1) {
$0.0
}
}
.frame(width: 200, height: 200)
.position(x: 100, y: 110)
Circle()
.strokeBorder(Color.black, lineWidth: 12)
.background(Circle().fill(customIcon.innerColor))
.frame(width: 120, height: 120, alignment: .center)
VStack {
Spacer()
.frame(height: 70)
HStack {
Spacer()
.frame(width: 72)
customIcon.leftEye
Spacer()
.frame(width: 20)
customIcon.rightEye
Spacer()
}
Spacer()
.frame(height: 28)
customIcon.mouth
Spacer()
}
}
.frame(width: 200, height: 200)
.background(
customIcon.bgColor
)
.cornerRadius(10)
}
}
struct IconView_Previews: PreviewProvider {
static var previews: some View {
IconView(customIcon: CustomIcon(leftEye: EyeOptions.defaultOption,
rightEye: EyeOptions.defaultOption,
mouth: MouthOptions.defaultOption,
background: [(AnyView, UUID)](),
bgColor: .red,
innerColor: .green))
}
}