Skip to content

Commit

Permalink
feat: setup grammar sugar
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepbox8646 committed Jun 15, 2024
1 parent 097fc7a commit b37ab59
Show file tree
Hide file tree
Showing 6 changed files with 187 additions and 193 deletions.
7 changes: 3 additions & 4 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ Please write it according to following rules:

| Task | Description | Status | Assigned | Create Date | Done Date | Related Issue | Related Pull Request | Species |
| ---------------------------------------------------------- | ----------------------------- | ---------------- | -------------------------- | ----------- | ---------- | ------------- | -------------------- | ------- |
| Color Animation (core) | The Animation that for color. | Intend | @sheepbox8646 | 2024-05-23 |
| Perfect Type Check (core) | ... | Ready | None | 2024-05-23 |
| The Automated Test Scripts (core) | ... | Ready | None | 2024-05-23 |
| Layout System (core) | ... | Ready | None | 2024-05-23 |
| Failed to create too long video under the local mode (cli) | ... | Ready | None | 2024-5-25 |
| Theme (core) | ... | Ready | None | 2024-05-23 |
| Documentation for Developer (docs) | ... | Ready | None | 2024-05-23 |
| Playground Sources Preload | ... | Intend | None | 2024-05-25 |
| Playground Sources Preload | ... | WIP | None | 2024-05-25 |
| SVG Analyzer (mods) | ... | WIP | @sheepbox8646 @jiwangyihao | 2024-05-23 |
| Mod Web Component (mods) | ... | WIP | @justyukie | 2024-05-23 | | | #40 |
| Mod Chart (mods) | ... | WIP | @jiwangyihao | 2024-05-23 |
| Mod Math (mods) | ... | WIP | @sheepbox8646 | 2024-05-23 |
| Mod Geometry (mods) | ... | WIP | @sheepbox8646 | 2024-05-23 |
| Mod Markdown (mods) | ... | WIP | @sheepbox8646 | 2024-05-23 |
| Plugin Debug (plugins) | ... | WIP | @sheepbox8646 | 2024-05-23 |
| Perfect Type Check (core) | ... | Done | None | 2024-05-23 |
| Color Animation (core) | The Animation that for color. | Done | @sheepbox8646 | 2024-05-23 |
| Unit support for local mode (core) | ... | Done | None | 2024-05-25 |
| Widget Lifecycle | ... | Done | None | 2024-05-24 |
| Refactor `changeProperty` and `changeStyle` | ... | Done | @wgxh-cli | 2024-05-23 | 2024-05-25 |
Expand Down
299 changes: 154 additions & 145 deletions examples/scene1.ts
Original file line number Diff line number Diff line change
@@ -1,157 +1,166 @@
import * as nc from 'newcar'
import * as mt from '@newcar/mod-math'
import { Arc } from '@newcar/basic'

await nc.useFont('../Roboto-Regular.ttf')
// await nc.useFont('../Roboto-Regular.ttf')

// remove ck from AnimationContext
// // remove ck from AnimationContext

const show = () => nc.depend<() => boolean, nc.AnimationContext<nc.Widget>>(ctx => () => {
ctx.widget.show()
return true
})
// const show = () => nc.depend<() => boolean, nc.AnimationContext<nc.Widget>>(ctx => () => {
// ctx.widget.show()
// return true
// })

const withFunction = <T extends nc.Widget>(f: (widget: T) => boolean) => {
return nc.depend<() => boolean, nc.AnimationContext<nc.T>>(ctx => () => {
return f(ctx.widget)
})
}
// const withFunction = <T extends nc.Widget>(f: (widget: T) => boolean) => {
// return nc.depend<() => boolean, nc.AnimationContext<nc.T>>(ctx => () => {
// return f(ctx.widget)
// })
// }

const withInitial = <T extends nc.Widget>(f: (widget: T, anim: Anim<T>) => boolean) => { }
// const withInitial = <T extends nc.Widget>(f: (widget: T, anim: Anim<T>) => boolean) => { }

export default nc.createScene(
new nc.Widget()
.add(new nc.Widget()
.add(new nc.Widget()
.add(
new nc.Text("What is Newcar?", {
style: {
fontSize: 50
},
width: 1600,
textAlign: 'center',
y: 450
})
.animate(nc.stroke().withAttr({ duration: 3 }))
.animate(nc.move().withAttr({ duration: 1, to: [0, 150], by: nc.easeOutCubic }))
.animate(nc.fadeOut().withAttr({ duration: 0.7 }))
.animate(nc.delay(0.6))
.animate(withFunction<nc.Text>((w) => {
w.text.value = 'This is a circle, you can see it gradually grows.'
w.style.transparency.value = 1
w.style.interval.value = [0, 0]
return true
}))
.animate(nc.stroke().withAttr({ duration: 3 }))
.animate(nc.delay(4))
.animate(withFunction<nc.Text>((w) => {
w.text.value = 'And it is falling down with bounce'
w.style.transparency.value = 1
w.style.interval.value = [0, 0]
return true
}))
.animate(nc.stroke().withAttr({ duration: 3 }))
.animate(nc.delay(1))
.animate(nc.fadeOut().withAttr({ duration: 1 }))
// export default nc.createScene(
// new nc.Widget()
// .add(new nc.Widget()
// .add(new nc.Widget()
// .add(
// new nc.Text("What is Newcar?", {
// style: {
// fontSize: 50
// },
// width: 1600,
// textAlign: 'center',
// y: 450
// })
// .animate(nc.stroke().withAttr({ duration: 3 }))
// .animate(nc.move().withAttr({ duration: 1, to: [0, 150], by: nc.easeOutCubic }))
// .animate(nc.fadeOut().withAttr({ duration: 0.7 }))
// .animate(nc.delay(0.6))
// .animate(withFunction<nc.Text>((w) => {
// w.text.value = 'This is a circle, you can see it gradually grows.'
// w.style.transparency.value = 1
// w.style.interval.value = [0, 0]
// return true
// }))
// .animate(nc.stroke().withAttr({ duration: 3 }))
// .animate(nc.delay(4))
// .animate(withFunction<nc.Text>((w) => {
// w.text.value = 'And it is falling down with bounce'
// w.style.transparency.value = 1
// w.style.interval.value = [0, 0]
// return true
// }))
// .animate(nc.stroke().withAttr({ duration: 3 }))
// .animate(nc.delay(1))
// .animate(nc.fadeOut().withAttr({ duration: 1 }))

// )
// .add(new nc.Arc(Math.PI * 50, 0, 360, {
// x: 800,
// y: 450,
// })
// .add(
// new mt.MathFunction(x => Math.PI * Math.sin(x / Math.PI), [-4 * Math.PI, 0], {
// style: {
// scaleY: -1
// },
// x: Math.PI * 50
// }).kill()
// .animate(nc.delay(16))
// .animate(withFunction(w => {
// w.resurrect()
// return true
// }))
// .animate(

)
.add(new nc.Arc(Math.PI * 50, 0, 360, {
x: 800,
y: 450,
})
.add(
new mt.MathFunction(x => Math.PI * Math.sin(x / Math.PI), [-4 * Math.PI, 0], {
style: {
scaleY: -1
},
x: Math.PI * 50
}).kill()
.animate(nc.delay(16))
.animate(withFunction(w => {
w.resurrect()
return true
}))
.animate(
// nc.move().withAttr({ duration: 6, to: [5 * Math.PI * 50, 0] })
// )
// )
// .animate(withFunction(w => {
// w.progress.value = 0
// return true
// }))
// .animate(nc.delay(7.5))
// .animate(nc.create().withAttr({ duration: 1 }))
// .animate(nc.delay(3.5))
// .animate(nc.move().withAttr({ duration: 2, to: [800, 1200], by: nc.easeBounce }))
// .animate(nc.delay(1))
// .animate(nc.parallel(
// nc.scale().withAttr({ to: [2, 2], duration: 1 }),
// nc.move().withAttr({ to: [1600, 900], duration: 1, by: nc.easeInOutCubic }),
// ))
// .animate(withFunction<nc.Arc>(w => {
// w.style.fill.value = false
// w.style.border.value = true
// return true
// }))
// .add(
// new mt.NumberPlane([-1000, 1000], [-1000, 1000], {
// style: {
// textsX: false,
// textsY: false
// }
// }).kill()
// .animate(nc.delay(16))
// .animate(withFunction(w => {
// w.resurrect()
// return true
// }))
// .animate(nc.create().withAttr({ duration: 1, by: nc.easeOutExpo }))
// )
// .add(...(() => {
// const main = new nc.Line([0, 0], [Math.PI * 50, 0], {
// style: {
// width: 3
// }
// }).kill()
// .animate(nc.delay(16))
// .animate(withFunction(w => {
// w.resurrect()
// return true
// }))
// .animate(nc.rotate().withAttr({ duration: 6, to: 720 }))
// return [main]
// })()))

nc.move().withAttr({ duration: 6, to: [5 * Math.PI * 50, 0] })
)
)
.animate(withFunction(w => {
w.progress.value = 0
return true
}))
.animate(nc.delay(7.5))
.animate(nc.create().withAttr({ duration: 1 }))
.animate(nc.delay(3.5))
.animate(nc.move().withAttr({ duration: 2, to: [800, 1200], by: nc.easeBounce }))
.animate(nc.delay(1))
.animate(nc.parallel(
nc.scale().withAttr({ to: [2, 2], duration: 1 }),
nc.move().withAttr({ to: [1600, 900], duration: 1, by: nc.easeInOutCubic }),
))
.animate(withFunction<nc.Arc>(w => {
w.style.fill.value = false
w.style.border.value = true
return true
}))
.add(
new mt.NumberPlane([-1000, 1000], [-1000, 1000], {
style: {
textsX: false,
textsY: false
}
}).kill()
.animate(nc.delay(16))
.animate(withFunction(w => {
w.resurrect()
return true
}))
.animate(nc.create().withAttr({ duration: 1, by: nc.easeOutExpo }))
)
.add(...(() => {
const main = new nc.Line([0, 0], [Math.PI * 50, 0], {
style: {
width: 3
}
}).kill()
.animate(nc.delay(16))
.animate(withFunction(w => {
w.resurrect()
return true
}))
.animate(nc.rotate().withAttr({ duration: 6, to: 720 }))
return [main]
})()))
// )

)
// .add(new nc.Rect(500, 500, {
// style: {
// fillColor: nc.Color.parse('skyblue'),
// blendMode: 'srcIn',
// rotation: 45,
// },
// x: 600,
// y: 250,
// }).hide()
// .animate(nc.delay(9))
// .animate(withFunction(w => {
// w.show()
// return true
// }))
// .animate(nc.create().withAttr({ duration: 1 })))
// .animate(nc.delay(11))
// .animate(nc.scale().withAttr({ duration: 1, to: [0.5, 0.5] }))
// )
// .add(
// new nc.Line([0, 700], [1600, 700]).kill()
// .animate(nc.delay(11))
// .animate(withFunction((w) => {
// w.resurrect()
// return true
// }))
// .animate(
// nc.create().withAttr({ duration: 1 })
// )
// )
// )

.add(new nc.Rect(500, 500, {
style: {
fillColor: nc.Color.parse('skyblue'),
blendMode: 'srcIn',
rotation: 45,
},
x: 600,
y: 250,
}).hide()
.animate(nc.delay(9))
.animate(withFunction(w => {
w.show()
return true
}))
.animate(nc.create().withAttr({ duration: 1 })))
.animate(nc.delay(11))
.animate(nc.scale().withAttr({ duration: 1, to: [0.5, 0.5] }))
)
.add(
new nc.Line([0, 700], [1600, 700]).kill()
.animate(nc.delay(11))
.animate(withFunction((w) => {
w.resurrect()
return true
}))
.animate(
nc.create().withAttr({ duration: 1 })
)
)
)
export default nc.createScene(
new nc.Rect(500, 500)
.setup(function *() {
// yield 1
yield nc.move().withAttr({ duration: 1, to: [1000, 1000] })
})
.animate(nc.delay(1))

)
9 changes: 2 additions & 7 deletions packages/basic/src/widgets/arc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,8 @@ export class Arc extends Path {
this.radius.value,
this.radius.value,
)
this.path.rewind()
this.path.addArc(this.rect, this.from.value, this.to.value * this.progress.value)
})
}

draw(canvas: Canvas): void {
this.path.rewind()
this.path.addArc(this.rect, this.from.value, this.to.value * this.progress.value)

super.draw(canvas)
}
}
28 changes: 0 additions & 28 deletions packages/core/src/apiAnimate.ts

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ export * from './scene'
export * from './widget'
export * from './asyncWidget'
export * from './global'

export * from './apiAnimate'
export * from './apiUseFont'
export * from './apiUseImage'

Expand Down

0 comments on commit b37ab59

Please sign in to comment.