サインを求める

説明

Dart言語でサインを求めるにはsin()メソッドを参照します。
なお、使用にあたってはmathパッケージを読み込む必要があります。パッケージを読み込まないとエラーになります。パッケージの読み込み指定はパッケージを追加するを参照してください。ライブラリをインポートした後にimport 'dart:math' as Math;のようにすることでmathライブラリが使用できるようになります。この場合、as MathとしてMathという名前でアクセスできるように指定しています。

[サンプルをダウンロード]

HTMLソース

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Sample18</title>
<link rel="stylesheet" href="sample18.css">
</head>
<body>
<h1>Sample18</h1>
<div id="result"></div>
<script type="application/dart" src="sample18.dart"></script>
<script src="packages/browser/dart.js"></script>
</body>
</html>

Dartコード

import 'dart:html';
import 'dart:math' as Math;

void main() {
	var d = 45; // 角度
	var n = Math.sin(d * Math.PI / 180);
	querySelector("#result").text = n.toString();
}