下記が、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を探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・【お題】絵本のタイトル
- ・【大喜利】世界最古のコンビニについて知ってる事を教えてください【投稿~10/10(木)】
- ・メモのコツを教えてください!
- ・CDの保有枚数を教えてください
- ・ホテルを選ぶとき、これだけは譲れない条件TOP3は?
- ・家・車以外で、人生で一番奮発した買い物
- ・人生最悪の忘れ物
- ・【コナン30周年】嘘でしょ!?と思った○○周年を教えて【ハルヒ20周年】
- ・ハマっている「お菓子」を教えて!
- ・最近、いつ泣きましたか?
- ・夏が終わったと感じる瞬間って、どんな時?
- ・10秒目をつむったら…
- ・人生のプチ美学を教えてください!!
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・都道府県穴埋めゲーム
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
VBAでセルの書式を変えずに文字...
-
【ExcelVBA】5万行以上のデー...
-
【VBA】 結合セルに複数画像と...
-
VBA 別ブックからコピペしたい...
-
[Excel VBA]特定の条件で文字を...
-
エクセルのマクロについて教え...
-
【ExcelVBA】インデックスが有...
-
Excel 範囲指定スクショについ...
-
VBA 別ブックから条件に合うも...
-
配列のペースト出力結果の書式...
-
【VBA】スペースが入っていない...
-
VBA 入力箇所指定方法
-
エクセルのマクロについて教え...
-
【VBA】値を変更しながら連続で...
-
エクセル タブの下のメニューを...
-
Web画面の文字をVB6で取得したい
-
エクセルのマクロについて教え...
-
エクセルのマクロについて教え...
-
エクセルのマクロについて教え...
-
EXCEL vbaでシート上に配置した...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
「arg」は何の略?
-
VBA/GetTickCountの49.7日の境...
-
例外の再スロー時に、その原因...
-
ruby の nil エラー
-
ブロック2 Ruby認定試験対策問題
-
cos波表示について マクローリ...
-
ヒープの質問です(難易度高)
-
英語訳をおねがいします
-
ブロックローカル変数
-
What class are you in? には何...
-
教えてください。vb5.0
-
Csvファイルの最終行を取得する...
-
get() と find() の違いについて
-
エラー「メソッドまたはデータ...
-
class roomとclassroom どちら...
-
関数の引数に複数のユーザ定義...
-
実行時エラー450:引数の数が一...
-
クラス名やモジュール名の競合...
-
windows embdded standard7
-
VBAで型が一致しないエラー(バ...
おすすめ情報