下記が、sin波を表示させるためのプログラムです。
これを改良し(mysin→mycosにし、mysin2→mycos2にする。)cos波を表示させたいです。
今、作ってみましたが、変な形です。
どこをどのように改良すればよいか、教えていただけませんでしょうか。
ちなみに、cos波は、picturebox2に作り、button2をクリックしたときに表示させるようにする。
Imports System.Math
Public Class Form1
Dim b As Bitmap
Dim g As Graphics
Dim p As Pen
Dim w, h, mw, mmw, mh As Integer
Dim b2 As Bitmap
Dim g2 As Graphics
Dim p2 As Pen
Dim w2, h2, mw2, mmw2, mh2 As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Sin波 Cos波"
w = PictureBox1.Width
h = PictureBox1.Height
w2 = PictureBox2.Width
h2 = PictureBox2.Height
mw = w \ 2
mmw = mw \ 2
mh = h \ 2
mw2 = w2 \ 2
mmw2 = mw2 \ 2
mh2 = h2 \ 2
Button1.Text = "Sin Curve"
Button2.Text = "Cos Curve"
b = New Bitmap(w, h)
g = Graphics.FromImage(b)
p = New Pen(Color.Black, 1)
b2 = New Bitmap(w2, h2)
g2 = Graphics.FromImage(b2)
p2 = New Pen(Color.Black, 1)
g.DrawLine(p, 0, mh, w, mh)
g.DrawLine(p, mw \ 2, 0, mw \ 2, h)
g2.DrawLine(p2, 0, mh2, w2, mh2)
g2.DrawLine(p2, mw2 \ 2, 0, mw2 \ 2, h2)
p.Dispose()
p2.Dispose()
PictureBox1.Image = b
PictureBox2.Image = b2
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i, k, x0, y0 As Integer
p = New Pen(Color.Blue, 2)
For i = mw + mmw - w To w - mmw
k = mysin(i * PI / 180) * mh * 0.9
x0 = mmw + i
y0 = mh - k
g.DrawLine(p, x0, y0, x0 + 1, y0 + 1)
Next
PictureBox1.Image = b
End Sub
Function mysin(ByVal arg) As Double
Dim s = Sign(arg)
Dim mp = Int(arg / (2 * PI))
arg = arg - 2 * PI * mp
If s < 0 Then arg = 2 * PI - arg
If arg > 3 * PI / 2 Then
Return -s * mysin2(2 * PI - arg)
ElseIf arg > PI Then
Return -s * mysin2(arg - PI)
ElseIf arg > PI / 2 Then
Return s * mysin2(PI - arg)
Else
Return s * mysin2(arg)
End If
End Function
Function mysin2(ByVal arg) As Double
Return arg - Pow(arg, 3) / 6 + Pow(arg, 5) / 120 - Pow(arg, 7) / 5040
End Function
Function mycos(ByVal arg2) As Double
Dim c = Sign(arg2)
Dim mp = Int(arg2 / (2 * PI))
arg2 = arg2 - 2 * PI * mp
If c < 0 Then arg2 = -2 * PI - arg2
If arg2 > 3 * PI / 2 Then
Return c * mycos2(-2 * PI - arg2)
ElseIf arg2 > PI Then
Return c * mycos2(arg2 - PI)
ElseIf arg2 > PI / 2 Then
Return -c * mycos2(PI - arg2)
Else
Return -c * mycos2(arg2)
End If
End Function
Function mycos2(ByVal arg2) As Double
Return 1 - Pow(arg2, 2) / 4 + Pow(arg2, 4) / 24 - Pow(arg2, 6) / 720
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim j, l, x1, y1 As Integer
p2 = New Pen(Color.Red, 2)
For j = mw2 - mmw2 - w2 To w2 - mmw2
l = mycos(j * PI / 180) * mh2
x1 = mmw2 + j
y1 = mh2 - l
g2.DrawLine(p2, x1, y1, x1 + 1, y1 + 1)
Next
PictureBox2.Image = b2
End Sub
End Class
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
- ・ゆるやかでぃべーと タイムマシンを破壊すべきか。
- ・歩いた自慢大会
- ・許せない心理テスト
- ・字面がカッコいい英単語
- ・これ何て呼びますか Part2
- ・人生で一番思い出に残ってる靴
- ・ゆるやかでぃべーと すべての高校生はアルバイトをするべきだ。
- ・初めて自分の家と他人の家が違う、と意識した時
- ・単二電池
- ・チョコミントアイス
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
【VBA】別シートにデータ転記
-
EXCEL vbaでシート上に配置した...
-
【ExcelVBA】値を変更しながら...
-
VBA ユーザーフォーム ボタンク...
-
VB.net(VB)で、フォームにExcel...
-
VBA 別ブックから条件に合うも...
-
配列のペースト出力結果の書式...
-
【ExcelVBA】インデックスが有...
-
Outlookの「受信日時」「件名」...
-
VBA 別ブックからコピペしたい...
-
VBA 入力箇所指定方法
-
VBA 複数条件の分岐処理の上手...
-
Excel VBA 定義されたプロージ...
-
エクセルのマクロについて教え...
-
VBA コードどこがおかしいですか?
-
エクセルVBA
-
【ExcelVBA】値を変更しながら...
-
Excelのマクロについて教えてく...
-
エクセルVBAについて
-
VBAの計算で@が出てしまう件
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「arg」は何の略?
-
VBA/GetTickCountの49.7日の境...
-
例外の再スロー時に、その原因...
-
Ruby Selenium 要素の待機
-
ブロックローカル変数
-
SMLのエラーについて
-
プログラミング言語 R
-
【Ruby】基本的な質問 数字を...
-
get() と find() の違いについて
-
教えてください。vb5.0
-
What class are you in? には何...
-
エラー「メソッドまたはデータ...
-
エクセルVBA オートフィルタで...
-
Csvファイルの最終行を取得する...
-
クラス名やモジュール名の競合...
-
VBAで型が一致しないエラー(バ...
-
HSTLやSSTL等のI/Oピン
-
実行時エラー450:引数の数が一...
-
【BrowseForFolderでデスクトッ...
-
テンプレートの特殊化でコンパ...
おすすめ情報