1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paiza.ioでelixirAdvent Calendar 2022

Day 1

paiza.ioでelixir その76

Last updated at Posted at 2022-11-16

概要

paiza.ioでelixirやってみた。
練習問題やってみた。

練習問題

sin波を描け。

サンプルコード

IO.puts """
<html><head></head><body>
<canvas id="canvas" width="300" height="300"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
function draw(data) {
    ctx.strokeStyle = "#f0f";
    ctx.lineWidth = 2;
    ctx.moveTo(0, 150);
    for (var i = 1; i < canvas.width; i++) 
    {
        ctx.lineTo(i, 150 - data[i] * 30);
    }
    ctx.stroke();
}
var src = [
"""
for i <- 0..300 do 
    v = :math.sin(i * 440.0 * 2.0 * :math.pi / 48000.0);
    IO.puts(v)
    IO.puts ","
end
IO.puts """

];
draw(src);
</script></body></html>
"""



実行結果

image.png

成果物

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?