# misc/indicator (vanilla-engine 0.4.0)

> https://vanillapunch.com/docs/vanilla-engine/0.4.0/api/misc/indicator/

인디케이터. (돌아가는 톱니바퀴 모양 로딩 표시)
- 원본 misc/indicator.js 를 옮긴 것이다. 노드가 아닌 그냥 객체라서, 들고 있는 쪽이 tick 과 draw 를 불러 준다.
  중심에서 바깥으로 뻗는 톱니 8 개와 두꺼운 안쪽 링을 회전시켜 그린다.
- 원본과 같이 선 끝은 각지다. set_color 는 Color 와 글("#ffffff" 등, Color 의 `From<&str>`)을 받는다.
  build_teeth_segments, get_radius, get_rotation 은 원본에도 있다.

## Indicator (struct) (Clone, Debug, Default)

인디케이터.

예제: 보일 때만 돈다

```rust
use vanilla::Indicator;

let mut indicator = Indicator::new();
indicator.set_speed(2.0);
indicator.tick(0.5);
assert_eq!(indicator.get_rotation(), 1.0);

indicator.set_visible(false);
indicator.tick(0.5);
assert_eq!(indicator.get_rotation(), 1.0);
```

예제: 화면 가운데에 로딩 표시 그리기

```rust
use vanilla::{Graphic, Indicator};

fn create_loading_indicator() -> Indicator {
	let mut indicator = Indicator::new();
	indicator.set_position(640.0, 360.0);
	indicator.set_radius(32.0);
	indicator.set_color("#ffcc00");
	indicator
}

fn draw_loading(indicator: &mut Indicator, graphic: &mut Graphic, time_delta: f64) {
	indicator.tick(time_delta);
	indicator.draw(graphic);
}
```

- `pub fn new() -> Indicator` (constructor, since 0.3.2): 생성. (반지름 20, 흰색, 초당 0.75 바퀴, 보임)
  - returns Indicator: 위치 (0, 0), 회전 0 인 인디케이터.
- `pub fn tick(&mut self, time_delta: f64)` (method, since 0.3.2): 갱신. (보일 때만 회전 각도를 쌓는다)
  - `time_delta` f64: 지난 프레임부터 흐른 시간. (초)
- `pub fn build_teeth_segments(&self) -> Vec<(Vector2, Vector2)>` (method, since 0.3.2): 톱니 선분 목록. (회전 전 가운데 기준. 안쪽 링보다 살짝 안쪽에서 바깥 끝까지)
  - returns Vec<(Vector2, Vector2)>: 톱니 8 개의 (안쪽 끝, 바깥 끝). 안쪽 끝은 반지름의 0.4 배, 바깥 끝은 반지름 거리이고, 0 라디안(오른쪽)부터 시계 방향(y 아래)으로 45 도씩이다.
- `pub fn draw(&self, graphic: &mut Graphic)` (method, since 0.3.2): 출력. (위치로 옮기고 돌린 뒤 톱니와 안쪽 링을 선으로 그린다)
  - 숨겨 있으면 그리지 않는다. 톱니 굵기는 반지름의 0.2 배, 안쪽 링은 반지름 0.5 배 자리에 0.3 배 굵기다. 그리기 상태는 들어올 때로 되돌린다.
  - `graphic` &mut Graphic: 그릴 그래픽.
- `pub fn set_position(&mut self, x: f64, y: f64)` (method, since 0.3.2): 위치 설정. (가운데 좌표)
  - `x` f64: 가운데 x. (그릴 때의 좌표계)
  - `y` f64: 가운데 y. (그릴 때의 좌표계)
- `pub fn get_position(&self) -> Vector2` (method, since 0.3.2): 위치 반환.
  - returns Vector2: 가운데 좌표.
- `pub fn set_radius(&mut self, radius: f64)` (method, since 0.3.2): 크기 설정. (반지름, 1 이상)
  - `radius` f64: 톱니 바깥 끝까지의 반지름. (1 보다 작으면 1)
- `pub fn get_radius(&self) -> f64` (method, since 0.3.2): 크기 반환.
  - returns f64: 반지름. (처음 20)
- `pub fn set_color(&mut self, color: impl Into<Color>)` (method, since 0.3.2): 색 설정.
  - `color` impl Into<Color>: 톱니와 링의 색. (Color 나 "#ffffff" 꼴 글)
- `pub fn set_speed(&mut self, speed_radians_per_second: f64)` (method, since 0.3.2): 회전 속도 설정. (라디안 / 초)
  - `speed_radians_per_second` f64: 회전 속도. (라디안 / 초, 처음 1.5π, 음수면 거꾸로 돈다)
- `pub fn get_rotation(&self) -> f64` (method, since 0.3.2): 회전 각도 반환. (라디안)
  - returns f64: 지금까지 쌓인 회전 각도. (라디안, 한 바퀴마다 되감지 않는다)
- `pub fn set_visible(&mut self, is_visible: bool)` (method, since 0.3.2): 출력 여부 설정.
  - `is_visible` bool: 참이면 그리고 돈다. 거짓이면 그리지 않고 회전도 멈춘다.
- `pub fn get_visible(&self) -> bool` (method, since 0.3.2): 출력 여부 반환.
  - returns bool: 보이면 true.
