Skip to content

Commit

Permalink
All examples are complete.
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau committed Jul 14, 2020
1 parent 1be1fe5 commit 0f921d7
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 129 deletions.
38 changes: 31 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,37 @@ The name cala is derived from the fungus known as
[calafate rust](https://en.wikipedia.org/wiki/Aecidium_magellanicum).

### Support
Here's a list of all of the targeted platforms (**bold** means a port has been made, *italic* means the feature doesn't work on the platform):

- **Linux**
- **MacOS** - WIP [*audio*](https://github.com/libcala/cala/issues/5), [*controller*](https://github.com/libcala/cala/issues/7), [*draw*](https://github.com/libcala/cala/issues/9)
- **Windows** - WIP [*audio*](https://github.com/libcala/cala/issues/4), [*controller*](https://github.com/libcala/cala/issues/6), [*draw*](https://github.com/libcala/cala/issues/8)
- **Web (WASM)** - WIP controller, draw, files
- Android
Here's a list of all of the targeted platforms and what they support. "X" means
it's supported, "-" means it's not planned. "?" means it might work, but hasn't
been tested yet. Some planned features have associated issues linked with the
number.

| Feature | Linux | MacOS | Windows | Web | Android |
|------------|-------|-------|---------|-----|---------|
| accel | | | | | |
| bluetooth | | | | | |
| camera | | | | | |
| draw | X |[9][3] | [8][6] | | |
| exec | X | | | X | |
| file | X | X | X | | |
| gpio | | - | - | - | |
| input | X |[7][2] | [6][5] | ? | |
| journal | X | X | X | X | |
| microphone | X |[5][1] | [4][4] | X | ? |
| net | X | X | X | ? | |
| pixels | X |[9][3] | | | |
| speaker | X | | [4][4] | X | ? |
| time | X | X | X | X | |
| user | X | X | X | X | |

[1]: https://github.com/libcala/cala/issues/5
[2]: https://github.com/libcala/cala/issues/7
[3]: https://github.com/libcala/cala/issues/9
[4]: https://github.com/libcala/cala/issues/4
[5]: https://github.com/libcala/cala/issues/6
[6]: https://github.com/libcala/cala/issues/8

#### Not Yet Attempted Support, But Planned
- iOS
- Fuchsia
- Redox
Expand Down
4 changes: 1 addition & 3 deletions examples/video/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
fn main() {
res::generate(&[
res::shader("color").transform().gradient()
]);
res::generate(&[res::shader("color").transform().gradient()]);
}
101 changes: 47 additions & 54 deletions examples/video/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use cala::*;

use cala::input::{Input, UiInput, GameInput, TextInput};
use cala::draw::{Group, Shader, ShaderBuilder, ShapeBuilder, shader, Transform, color::SRgb32};
use cala::draw::{
color::SRgb32, shader, Group, Shader, ShaderBuilder, ShapeBuilder,
Transform,
};
use cala::input::{GameInput, Input, TextInput, UiInput};

#[allow(unused)]
pub struct Context {
colors: Shader,
triangle: Group,
Expand All @@ -18,71 +20,62 @@ async fn init() {
// Load a shader.
let colors = Shader::new(shader!("color"));

// Define vertices.
// Build triangle Shape
let triangle = Group::new();
let mut context = Context {
colors,
triangle,
timed,
};

// Game loop
while [canvas(&mut context).fut(), input().fut()].select().await.1 {}
}

fn animate_triangle(context: &mut Context, time: f32, aspect: f32) {
#[rustfmt::skip]
let vertices = [
0.25, 0.75, 1.0, 0.5, 0.0,
0.75, 0.75, 0.0, 0.0, 1.0,
0.50, 0.25, 1.0, 1.0, 1.0,
-1.0, 1.0, 1.0, 0.5, 0.0,
1.0, 1.0, 0.0, 0.0, 1.0,
0.0, -1.0, 1.0, 1.0, 1.0,

0.0, -1.0, 1.0, 0.7, 0.0,
1.0, 1.0, 1.0, 0.7, 0.0,
-1.0, 1.0, 1.0, 0.7, 0.0,
];

// Build triangle Shape
let mut triangle = Group::new();
let triangle_shape = ShapeBuilder::new()
.vert(&vertices)
.face(Transform::new())
.finish(&colors);
triangle.push(
&triangle_shape,
&Transform::new()
);
/*triangle.push(
&triangle_shape,
&Transform::new()
.scale(0.5, 0.5, 0.5)
.translate(-0.5, 0.5, 0.0),
);
triangle.push(
&triangle_shape,
&Transform::new()
.scale(0.5, 0.5, 0.5)
.translate(0.5, 0.5, 0.0),
);*/

let context = Context {
colors,
triangle,
timed,
};
[canvas(context).fut(), input().fut()].select().await;
.finish(&context.colors);
let transform = Transform::new()
.rotate(0.0, 1.0, 0.0, time)
.scale(0.25, 0.25 * aspect, 0.25)
.translate(0.5, 0.5 * aspect, 0.0);
context.triangle.write(0, &triangle_shape, &transform);
}

// Function that runs while your app runs.
pub async fn canvas(mut context: Context) {
loop {
// Set the background color.
let mut canvas = pixels::canvas(SRgb32::new(0.0, 1.0, 0.0)).await;
pub async fn canvas(context: &mut Context) -> bool {
// Set the background color.
let mut canvas = pixels::canvas(SRgb32::new(0.0, 0.5, 0.0)).await;

context.timed = (context.timed + canvas.elapsed().as_secs_f64()) % 1.0;
let delta = context.timed as f32;
// Update triangle
context.timed = (context.timed + canvas.elapsed().as_secs_f64()) % 1.0;
animate_triangle(context, context.timed as f32, canvas.height());

/*context.triangle.transform(0, Transform::new()
.scale(0.5, 0.5, 0.5)
.translate(-0.5, -0.5 + delta, 0.0)
);*/
// Draw triangle
canvas.draw(&context.colors, &context.triangle);

// Draw triangle
canvas.draw(&context.colors, &context.triangle);
}
true
}

async fn input<'a>() {
loop {
match cala::input::input().await {
Input::Ui(UiInput::Back) => break,
Input::Game(_id, GameInput::Back) => break,
Input::Text(TextInput::Back) => break,
input => println!("{:?}", input),
}
async fn input<'a>() -> bool {
match cala::input::input().await {
Input::Ui(UiInput::Back) => return false,
Input::Game(_id, GameInput::Back) => return false,
Input::Text(TextInput::Back) => return false,
input => println!("{:?}", input),
}
true
}
Loading

0 comments on commit 0f921d7

Please sign in to comment.