mirror of
https://github.com/exyte/Macaw.git
synced 2024-09-19 08:57:35 +03:00
Groups hierarhy transformation
This commit is contained in:
parent
063cf5a378
commit
dcadb01c4a
@ -15,6 +15,18 @@ class MorphingView: MacawView {
|
||||
|
||||
class func newScene() -> Node {
|
||||
|
||||
|
||||
/*
|
||||
let form1 = Rect(x: 50.0, y: 50.0, w: 200.0, h: 200.0)
|
||||
let form2 = Circle(cx: 150.0, cy: 150.0, r: 100.0)
|
||||
|
||||
let shape = Shape(form: form1)
|
||||
let animation = shape.formVar.animation(to: form2, during:1.5, delay: 2.0)
|
||||
animation.autoreversed().play()//.cycle().play()
|
||||
|
||||
return shape
|
||||
*/
|
||||
|
||||
/*
|
||||
let group1 = [
|
||||
Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: Stroke(width: 6.0, cap: .round)),
|
||||
@ -28,24 +40,42 @@ class MorphingView: MacawView {
|
||||
Shape(form: Line(x1: 90.0, y1: 210.0, x2: 210.0, y2: 90.0), stroke: Stroke(width: 6.0, cap: .round))
|
||||
].group()
|
||||
|
||||
group1.contentsVar.animate(to: group2)
|
||||
|
||||
return group1
|
||||
*/
|
||||
|
||||
|
||||
|
||||
let stroke = Stroke(width: 15.0, cap: .round)
|
||||
|
||||
let group1 = [
|
||||
Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: stroke),
|
||||
[Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: stroke),
|
||||
Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: stroke)].group(),
|
||||
].group()
|
||||
|
||||
let group2 = [
|
||||
Shape(form: Line(x1: 110.0, y1: 150.0, x2: 135.0, y2: 125.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Line(x1: 110.0, y1: 150.0, x2: 190.0, y2: 150.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Line( x1: 110.0, y1: 150.0, x2: 135.0, y2: 175.0), stroke: Stroke(width: 15.0, cap: .round)),
|
||||
Shape(form: Circle(cx: 150.0, cy: 150.0, r: 100.0), stroke: Stroke(width: 6.0, cap: .round))
|
||||
[Shape(form: Line(x1: 110.0, y1: 150.0, x2: 135.0, y2: 125.0), stroke: stroke),
|
||||
Shape(form: Line(x1: 110.0, y1: 150.0, x2: 190.0, y2: 150.0), stroke: stroke)].group(),
|
||||
Shape(form: Line( x1: 110.0, y1: 150.0, x2: 135.0, y2: 175.0), stroke: stroke),
|
||||
].group()
|
||||
|
||||
let anim = group1.contentsVar.animation(to: group2, during: 0.5, delay: 2.0)
|
||||
anim.easing(.easeIn).play()
|
||||
let presentedGroup = [
|
||||
Shape(form: Line(x1: 90.0, y1: 110.0, x2: 210.0, y2: 110.0), stroke: stroke),
|
||||
Shape(form: Line(x1: 90.0, y1: 150.0, x2: 210.0, y2: 150.0), stroke: stroke),
|
||||
Shape(form: Line(x1: 90.0, y1: 190.0, x2: 210.0, y2: 190.0), stroke: stroke),
|
||||
].group()
|
||||
|
||||
return group1
|
||||
[
|
||||
presentedGroup.contentsVar.animation(to: group2, during: 10.0, delay: 5.0),
|
||||
//presentedGroup.contentsVar.animation(to: group1, during: 0.5, delay: 2.0),
|
||||
].sequence().play()
|
||||
|
||||
return presentedGroup
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +80,7 @@ public extension AnimatableVariable where T: GroupInterpolation {
|
||||
fromNode = passedFromNode
|
||||
}
|
||||
|
||||
// Shapes on same hierarhy level
|
||||
let fromShapes = fromNode.contents.flatMap{$0 as? Shape}
|
||||
let toShapes = to.contents.flatMap{$0 as? Shape}
|
||||
let minPathsNumber = min(fromShapes.count, toShapes.count)
|
||||
@ -111,6 +112,32 @@ public extension AnimatableVariable where T: GroupInterpolation {
|
||||
}
|
||||
}
|
||||
|
||||
// Groups on same hierahy level
|
||||
let fromGroups = fromNode.contents.flatMap{$0 as? Group}
|
||||
let toGroups = to.contents.flatMap{$0 as? Group}
|
||||
let minGroupsNumber = min(fromGroups.count, toGroups.count)
|
||||
for i in 0..<minGroupsNumber {
|
||||
let fromGroup = fromGroups[i]
|
||||
let toGroup = toGroups[i]
|
||||
let groupAnimation = fromGroup.contentsVar.animation(to: toGroup, during: during, delay: delay)
|
||||
animations.append(groupAnimation)
|
||||
}
|
||||
|
||||
for i in minGroupsNumber..<fromGroups.count {
|
||||
let groupToHide = fromGroups[i]
|
||||
let animation = groupToHide.opacityVar.animation(to: 0.0, during:during, delay: delay)
|
||||
animations.append(animation)
|
||||
}
|
||||
|
||||
for i in minGroupsNumber..<toGroups.count {
|
||||
let groupToShow = toGroups[i]
|
||||
groupToShow.opacity = 0.0
|
||||
fromNode.contents.append(groupToShow)
|
||||
|
||||
let animation = groupToShow.opacityVar.animation(to: 1.0, during:during, delay: delay)
|
||||
animations.append(animation)
|
||||
}
|
||||
|
||||
return animations.combine()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user