
下記が、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を探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
【VBA】値を変更しながら連続で...
-
vba textboxへの入力について教...
-
【マクロ】シートの変数へ入れ...
-
【マクロ】並び替えの範囲が、...
-
【マクロ】売上一覧YYYYMMDDHHS...
-
【マクロ】開いているブックの...
-
Vba セルの4辺について罫線が有...
-
vbsでのwebフォームへの入力制限?
-
VBAでFOR NEXT分を Application...
-
Vba Array関数について教えてく...
-
Excel VBA 選択範囲の罫線色の...
-
複数のExcelファイルをマージす...
-
【ExcelVBA】5万行以上のデー...
-
ワードVBA どの表か知ることは...
-
VBAでCOPYを繰り返すと、処理が...
-
改行文字「vbCrLf」とは
-
VBA Application.Matchについて...
-
Visualbasicの現状について教え...
-
エクセル タブの下のメニューを...
-
Web画面の文字をVB6で取得したい
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「arg」は何の略?
-
Ruby Selenium 要素の待機
-
プログラミング言語 R
-
例外の再スロー時に、その原因...
-
ブロックローカル変数
-
Rails コンボボックスの値の保...
-
get() と find() の違いについて
-
エクセルVBA オートフィルタで...
-
教えてください。vb5.0
-
VBAで型が一致しないエラー(バ...
-
エラー「メソッドまたはデータ...
-
メソッド定義の構文のdefって
-
実行時エラー450:引数の数が一...
-
Csvファイルの最終行を取得する...
-
class roomとclassroom どちら...
-
変数の隠蔽とは?
-
関数の引数に複数のユーザ定義...
-
What class are you in? には何...
-
HSTLやSSTL等のI/Oピン
-
10円未満を切り捨てる方法は?
おすすめ情報