Add spinning cube demo to particle gallery
No-Try: true Docs-Preview: https://skia.org/?cl=249229 Bug: skia:9513 Change-Id: If72d809d843af73debb8cb2d797283d9aa65f314 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/249229 Commit-Queue: Brian Osman <brianosman@google.com> Commit-Queue: Kevin Lubick <kjlubick@google.com> Auto-Submit: Brian Osman <brianosman@google.com> Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
parent
96d9a07a90
commit
5f827ee657
@ -31,8 +31,14 @@ Samples
|
||||
<figure>
|
||||
<canvas id=trail width=400 height=400></canvas>
|
||||
<figcaption>
|
||||
<a href="https://particles.skia.org/84a757d92c424b3d378b55481a4b2394"
|
||||
target=_blank rel=noopener>Trail (Click and Drag!)</a>
|
||||
Trail (Click and Drag!)
|
||||
</figcaption>
|
||||
</figure>
|
||||
<figure>
|
||||
<canvas id=cube width=400 height=400></canvas>
|
||||
<figcaption>
|
||||
<a href="https://particles.skia.org/f03ffe333483db27fb045d0f3f508db3"
|
||||
target=_blank rel=noopener>Cuboid</a>
|
||||
</figcaption>
|
||||
</figure>
|
||||
<figure>
|
||||
@ -96,6 +102,7 @@ Samples
|
||||
TrailExample(CanvasKit, 'trail', trail);
|
||||
ParticleExample(CanvasKit, 'confetti', confetti, 200, 200);
|
||||
ParticleExample(CanvasKit, 'curves', curves, 200, 300);
|
||||
ParticleExample(CanvasKit, 'cube', cube, 200, 200);
|
||||
ParticleExample(CanvasKit, 'fireworks', fireworks, 200, 300);
|
||||
ParticleExample(CanvasKit, 'raincloud', raincloud, 200, 100);
|
||||
ParticleExample(CanvasKit, 'text', text, 75, 250);
|
||||
@ -170,6 +177,101 @@ const confetti ={
|
||||
"Bindings": []
|
||||
};
|
||||
|
||||
const cube = {
|
||||
"MaxCount": 2000,
|
||||
"Drawable": {
|
||||
"Type": "SkCircleDrawable",
|
||||
"Radius": 4
|
||||
},
|
||||
"EffectCode": [
|
||||
"void effectSpawn(inout Effect effect) {",
|
||||
" effect.lifetime = 2;",
|
||||
" effect.rate = 200;",
|
||||
"}",
|
||||
""
|
||||
],
|
||||
"Code": [
|
||||
"void spawn(inout Particle p) {",
|
||||
" p.lifetime = 10;",
|
||||
"}",
|
||||
"",
|
||||
"float4x4 rx(float rad) {",
|
||||
" float c = cos(rad);",
|
||||
" float s = sin(rad);",
|
||||
" return float4x4(1, 0, 0, 0,",
|
||||
" 0, c, -s, 0,",
|
||||
" 0, s, c, 0,",
|
||||
" 0, 0, 0, 1);",
|
||||
"}",
|
||||
"",
|
||||
"float4x4 ry(float rad) {",
|
||||
" float c = cos(rad);",
|
||||
" float s = sin(rad);",
|
||||
" return float4x4(c, 0, -s, 0,",
|
||||
" 0, 1, 0, 0,",
|
||||
" s, 0, c, 0,",
|
||||
" 0, 0, 0, 1);",
|
||||
"}",
|
||||
"",
|
||||
"float4x4 rz(float rad) {",
|
||||
" float c = cos(rad);",
|
||||
" float s = sin(rad);",
|
||||
" return float4x4( c, s, 0, 0,",
|
||||
" -s, c, 0, 0,",
|
||||
" 0, 0, 1, 0,",
|
||||
" 0, 0, 0, 1);",
|
||||
"}",
|
||||
"",
|
||||
"void update(inout Particle p) {",
|
||||
" float3 pos = float3(rand, rand, rand);",
|
||||
" if (rand < 0.33) {",
|
||||
" if (pos.x > 0.5) {",
|
||||
" pos.x = 1;",
|
||||
" p.color.rgb = float3(1, 0.2, 0.2);",
|
||||
" } else {",
|
||||
" pos.x = 0;",
|
||||
" p.color.rgb = float3(0.2, 1, 1);",
|
||||
" }",
|
||||
" } else if (rand < 0.5) {",
|
||||
" if (pos.y > 0.5) {",
|
||||
" pos.y = 1;",
|
||||
" p.color.rgb = float3(0.2, 0.2, 1);",
|
||||
" } else {",
|
||||
" pos.y = 0;",
|
||||
" p.color.rgb = float3(1, 1, 0.2);",
|
||||
" }",
|
||||
" } else {",
|
||||
" if (pos.z > 0.5) {",
|
||||
" pos.z = 1;",
|
||||
" p.color.rgb = float3(0.2, 1, 0.2);",
|
||||
" } else {",
|
||||
" pos.z = 0;",
|
||||
" p.color.rgb = float3(1, 0.2, 1);",
|
||||
" }",
|
||||
" }",
|
||||
"",
|
||||
" float s = effect.age * 2 - 1;",
|
||||
" s = s < 0 ? -s : s;",
|
||||
"",
|
||||
" pos = pos * 2 - 1;",
|
||||
" pos = mix(pos, normalize(pos), s);",
|
||||
" pos = pos * 100;",
|
||||
"",
|
||||
" float age = effect.loop + effect.age;",
|
||||
" float4x4 mat = rx(age * radians(60))",
|
||||
" * ry(age * radians(70))",
|
||||
" * rz(age * radians(80));",
|
||||
" pos = (mat * float4(pos, 1)).xyz;",
|
||||
"",
|
||||
" p.pos.x = pos.x;",
|
||||
" p.pos.y = pos.y;",
|
||||
" p.scale = ((pos.z + 50) / 100 + 0.5) / 2;",
|
||||
"}",
|
||||
""
|
||||
],
|
||||
"Bindings": []
|
||||
};
|
||||
|
||||
const curves = {
|
||||
"MaxCount": 1000,
|
||||
"Drawable": {
|
||||
|
Loading…
Reference in New Issue
Block a user