Skip to content

Commit

Permalink
Merge pull request #17 from AdAstraCA/main
Browse files Browse the repository at this point in the history
Code for Issues 13(Hide/Show Filters) and 14(Black/White Filter Toggle)
  • Loading branch information
truedat101 authored Jan 10, 2023
2 parents 9629a0b + 13eb282 commit 1d7f7e0
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 26 deletions.
45 changes: 37 additions & 8 deletions Shared/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// Shared
//
// Created by Delta on 24/5/22.
// Edited by Astra on 1/8/23.
//

import AVFoundation
import SwiftUI

var swipePreview = true
var chosenColor = 1.0

struct ContentView: View {
var body: some View {
CameraView()
Expand All @@ -22,21 +26,25 @@ struct ContentView_Previews: PreviewProvider {

struct CameraView: View{
@State private var filtersPreview = [
FilterModel(filter: .circle, isPreview: true),
FilterModel(filter: .rectangle, isPreview: true),
FilterModel(filter: .lines, isPreview: true),
FilterModel(filter: .start, isPreview: true)
FilterModel(filter: .circle, isPreview: true, color: chosenColor),
FilterModel(filter: .rectangle, isPreview: true, color: abs(chosenColor - 1.0)),
FilterModel(filter: .lines, isPreview: true, color: abs(chosenColor - 1.0)),
FilterModel(filter: .start, isPreview: true, color: chosenColor)
]
@StateObject var camera = CameraModel()
@StateObject var viewModel = ViewModel()
var body: some View{
let _ = print("test")
GeometryReader { geometry in
VStack{
ZStack(alignment: .center){
CameraPreview(camera: camera).ignoresSafeArea(.all, edges: .all
).frame(width: geometry.size.width, alignment: .center)
Filter(data: FilterModel(filter: viewModel.indexFilter, isPreview: false))
.clipped()
// this code adds the filter
if (swipePreview) {
Filter(data: FilterModel(filter: viewModel.indexFilter, isPreview: false, color: chosenColor))
.clipped()
}
}.onAppear {
camera.Check()
}.frame(width: geometry.size.width, height: geometry.size.height / 1.4, alignment: .center).clipped()
Expand All @@ -50,6 +58,28 @@ struct CameraView: View{
}
}.frame(height: Constant.sizeWidthPreview)
.background(Color.gray)
HStack(alignment: .center) {
Button(action: {
if chosenColor == 1.0 {
chosenColor = 0.0
} else {
chosenColor = 1.0
}
}) {
Text("Color Toggle")
.padding(10)
.foregroundColor(.white)
.background(Color.pink)
}
Button(action: {
swipePreview.toggle()
}) {
Text("Show/Hide Toggle")
.padding(10)
.foregroundColor(.white)
.background(Color.pink)
}
}
}
}
}
Expand All @@ -62,6 +92,7 @@ struct TakePictureButton: View {
HStack{
if isTaken {
Button(action: {}, label: {

//todo
})
}else{
Expand Down Expand Up @@ -169,5 +200,3 @@ struct CameraPreview: UIViewRepresentable {

}
}


7 changes: 5 additions & 2 deletions Shared/FCircle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
// MoireLens (iOS)
//
// Created by Delta on 11/7/22.
// Edited by Astra on 1/8/23.
//

import SwiftUI

struct FCircle: View{
var isPreview = false
var color = 1.0
var numShapes: Int

init(isPreview: Bool) {
init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.numShapes = Constant.num / (isPreview ? 3 : 1)
self.color = color
}

var body: some View{
ZStack(alignment: .center){
ForEach(Array(stride(from: 0, to: numShapes, by: 4)), id: \.self) { i in
Circle()
.stroke(Color.white, lineWidth: Constant.borderWidth)
.stroke(Color(white: color), lineWidth: Constant.borderWidth)
.frame(
width: Constant.minSizeShape + (CGFloat(i) * 4),
height: Constant.minSizeShape + (CGFloat(i) * 4),
Expand Down
11 changes: 6 additions & 5 deletions Shared/FLines.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,26 @@
// MoireLens (iOS)
//
// Created by Delta on 11/7/22.
// Edited by Astra on 1/8/23.
//

import SwiftUI

struct FLines: View{
var isPreview = false
var color = 0.0
var scale: Int

init(isPreview: Bool) {
init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.scale = isPreview ? 3 : 5
self.color = color
}

var body: some View{
GeometryReader { geometry in
HStack{
ForEach(0..<Constant.num) { i in
ForEach(0..<Constant.num, id: \.self) { i in
Rectangle()
.fill(Color.black)
.fill(Color(white: color))
.frame(
width: Constant.borderWidth,
height: geometry.size.height)
Expand Down
7 changes: 5 additions & 2 deletions Shared/FReactangle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
// MoireLens (iOS)
//
// Created by Delta on 11/7/22.
// Edited by Astra on 1/8/23.
//

import SwiftUI

struct FReactngle: View{
var isPreview = false
var color = 0.0
var numShapes: Int

init(isPreview: Bool) {
init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.numShapes = Constant.num / (isPreview ? 3 : 1)
self.color = color
}

var body: some View{
ZStack {
ForEach(Array(stride(from: 0, to: numShapes, by: 4)), id: \.self) { i in
Rectangle()
.stroke(Color.white, lineWidth: Constant.borderWidth)
.stroke(Color(white: color), lineWidth: Constant.borderWidth)
.frame(
width: Constant.minSizeShape + (CGFloat(i) * 4),
height: Constant.minSizeShape + (CGFloat(i) * 4),
Expand Down
9 changes: 6 additions & 3 deletions Shared/FStar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,27 @@
// MoireLens (iOS)
//
// Created by Delta on 11/7/22.
// Edited by Astra on 1/8/23.
//

import SwiftUI

struct FStart: View{
var isPreview = false
var color = 1.0
var scale: Int

init(isPreview: Bool) {
init(isPreview: Bool, color: Double) {
self.isPreview = isPreview
self.scale = Constant.num
self.color = color
}

var body: some View{
ZStack{
ForEach(0..<scale * 5) { i in
ForEach(0..<scale * 5, id: \.self) { i in
Rectangle()
.fill(Color.white)
.fill(Color(white: color))
.frame(width: Constant.borderWidth, height: 1000)
.rotationEffect(Angle(degrees: Double(90 + (i * 5)) ))
}
Expand Down
11 changes: 6 additions & 5 deletions Shared/Filter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Filter.swift
// MoireLens (iOS)
//
// Created by Delta on 11/7/22.
// Created by Delta on 11/7/22
// Edited by Astra on 1/8/23
//

import SwiftUI
Expand All @@ -26,13 +27,13 @@ struct Filter: View {
} label: {
switch data.filter {
case .circle:
FCircle(isPreview: data.isPreview)
FCircle(isPreview: data.isPreview, color: data.color)
case .rectangle:
FReactngle(isPreview: data.isPreview)
FReactngle(isPreview: data.isPreview, color: data.color)
case .lines:
FLines(isPreview: data.isPreview)
FLines(isPreview: data.isPreview, color: data.color)
case .start:
FStart(isPreview: data.isPreview)
FStart(isPreview: data.isPreview, color: data.color)
}
}.frame(width: geometry.size.width, height: geometry.size.height, alignment: .center)
}
Expand Down
4 changes: 3 additions & 1 deletion Shared/Model.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Model.swift
// MoireLens
//
// Created by Delta on 13/6/22.
// Created by Delta on 13/6/22
// Edited by Astra on 1/8/23
//

import Foundation

struct FilterModel {
var filter: FILTERS
var isPreview: Bool
var color: Double
}
9 changes: 9 additions & 0 deletions addition
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args) {
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum = sum + i;
}
System.out.println(sum);
}
}

0 comments on commit 1d7f7e0

Please sign in to comment.