Anda di halaman 1dari 17

Nim : 1804045 (Teknik Informatika)

Nama : Cindy Nadhira Noor Salsabila

Kelas : Pemrograman Grafik (A)

1. Soal UTS Nomor 1

a. Coding

Dim Px(100), Py(100), spasi, lh, th, jrkbaris As Integer

Private Sub Command1_Click()

spasi = 50
lh = 75
th = 120
jrkbaris = spasi + th + spasi

'Huruf C
Px(1) = spasi: Py(1) = spasi + th
Px(2) = spasi: Py(2) = spasi
Px(3) = spasi + lh: Py(3) = spasi
Px(4) = spasi: Py(4) = spasi
Px(5) = spasi + lh: Py(5) = spasi + th
Px(6) = spasi: Py(6) = spasi + th

Line (Px(1), Py(1))-(Px(2), Py(2))


Line (Px(3), Py(3))-(Px(4), Py(4))
Line (Px(5), Py(5))-(Px(6), Py(6))

'Huruf I
Px(7) = 125 + spasi: Py(7) = spasi + th
Px(8) = 125 + spasi: Py(8) = spasi
Line (Px(7), Py(7))-(Px(8), Py(8))
'Huruf N
Px(9) = 175 + spasi: Py(9) = spasi + th
Px(10) = 175 + spasi: Py(10) = spasi
Px(11) = 175 + spasi: Py(11) = spasi
Px(12) = 175 + spasi + lh: Py(12) = spasi + th
Px(13) = 250 + spasi: Py(13) = spasi + th
Px(14) = 250 + spasi: Py(14) = spasi

Line (Px(9), Py(9))-(Px(10), Py(10))


Line (Px(11), Py(11))-(Px(12), Py(12))
Line (Px(13), Py(13))-(Px(14), Py(14))

'Huruf D
Px(15) = 300 + spasi: Py(15) = spasi + th
Px(16) = 300 + spasi: Py(16) = spasi

Px(17) = 300 + spasi: Py(17) = spasi


Px(18) = 300 + spasi + lh: Py(18) = spasi

Px(19) = 300 + spasi: Py(19) = spasi + th


Px(20) = 300 + spasi + lh: Py(20) = spasi + th

Px(21) = 375 + spasi: Py(21) = spasi


Px(22) = 375 + spasi + 25: Py(22) = spasi + 25

Px(23) = 375 + spasi: Py(23) = spasi + th


Px(24) = 375 + spasi + 25: Py(24) = spasi - 25 + th

Px(25) = 400 + spasi: Py(25) = spasi + th - 25


Px(26) = 400 + spasi: Py(26) = spasi + 25

Line (Px(15), Py(15))-(Px(16), Py(16))


Line (Px(17), Py(17))-(Px(18), Py(18))
Line (Px(19), Py(19))-(Px(20), Py(20))
Line (Px(21), Py(21))-(Px(22), Py(22))
Line (Px(23), Py(23))-(Px(24), Py(24))
Line (Px(25), Py(25))-(Px(26), Py(26))
'Huruf Y
Px(27) = 450 + spasi + 50: Py(27) = spasi + 50
Px(28) = 450 + spasi: Py(28) = spasi

Px(29) = 450 + spasi + 50: Py(29) = spasi + 50


Px(30) = 450 + spasi + 100: Py(30) = spasi

Px(31) = 450 + spasi + 50: Py(31) = spasi + th


Px(32) = 450 + spasi + 50: Py(32) = spasi + 50

Line (Px(27), Py(27))-(Px(28), Py(28))


Line (Px(29), Py(29))-(Px(30), Py(30))
Line (Px(31), Py(31))-(Px(32), Py(32))

'Angka 1
Px(33) = spasi + 50: Py(33) = jrkbaris
Px(34) = spasi + 50: Py(34) = jrkbaris + th

Px(35) = spasi + 50: Py(35) = jrkbaris


Px(36) = spasi + 25: Py(36) = jrkbaris + 25

Px(37) = spasi + 75: Py(37) = jrkbaris + th


Px(38) = spasi + 25: Py(38) = jrkbaris + th

Line (Px(33), Py(33))-(Px(34), Py(34))


Line (Px(35), Py(35))-(Px(36), Py(36))
Line (Px(37), Py(37))-(Px(38), Py(38))

'Angka 0

Px(39) = 125 + spasi: Py(39) = jrkbaris


Px(40) = 125 + spasi: Py(40) = jrkbaris + th

Px(41) = 125 + spasi + lh: Py(41) = jrkbaris


Px(42) = 125 + spasi + lh: Py(42) = jrkbaris + th

Px(43) = 125 + spasi + lh: Py(43) = jrkbaris


Px(44) = 125 + spasi: Py(44) = jrkbaris
Px(45) = 125 + spasi + lh: Py(45) = jrkbaris + th
Px(46) = 125 + spasi: Py(46) = jrkbaris + th

Line (Px(39), Py(39))-(Px(40), Py(40))


Line (Px(41), Py(41))-(Px(42), Py(42))
Line (Px(43), Py(43))-(Px(44), Py(44))
Line (Px(45), Py(45))-(Px(46), Py(46))

'angka 4
Px(47) = 250 + spasi: Py(47) = jrkbaris
Px(48) = 250 + spasi: Py(48) = jrkbaris + (th / 2)

Px(49) = 250 + spasi: Py(49) = jrkbaris + (th / 2)


Px(50) = 250 + spasi + lh: Py(50) = jrkbaris + (th / 2)

Px(51) = 250 + spasi + lh: Py(51) = jrkbaris


Px(52) = 250 + spasi + lh: Py(52) = jrkbaris + th

Line (Px(47), Py(47))-(Px(48), Py(48))


Line (Px(49), Py(49))-(Px(50), Py(50))
Line (Px(51), Py(51))-(Px(52), Py(52))

'Angka 5
Px(53) = 375 + spasi: Py(53) = jrkbaris
Px(54) = 375 + spasi + lh: Py(54) = jrkbaris

Px(55) = 375 + spasi: Py(55) = jrkbaris


Px(56) = 375 + spasi: Py(56) = jrkbaris + (th / 2)

Px(57) = 375 + spasi: Py(57) = jrkbaris + (th / 2)


Px(58) = 375 + spasi + lh: Py(58) = jrkbaris + (th / 2)

Px(59) = 375 + spasi + lh: Py(59) = jrkbaris + th


Px(60) = 375 + spasi + lh: Py(60) = jrkbaris + (th / 2)

Px(61) = 375 + spasi: Py(61) = jrkbaris + th


Px(62) = 375 + spasi + lh: Py(62) = jrkbaris + th
Line (Px(53), Py(53))-(Px(54), Py(54))
Line (Px(55), Py(55))-(Px(56), Py(56))
Line (Px(57), Py(57))-(Px(58), Py(58))
Line (Px(59), Py(59))-(Px(60), Py(60))
Line (Px(61), Py(61))-(Px(62), Py(62))

End Sub

Private Sub Form_Load()


Form1.ScaleMode = 3
Form1.DrawWidth = 3
L = Form1.ScaleWidth
T = Form1.ScaleHeight
End Sub
Private Sub Form_Resize()
L = Form1.ScaleWidth
T = Form1.ScaleHeight
End Sub

b. Hasil
Nomor 2 (Latihan 4)
1. Latihan 4.1

a. Coding

Private Sub Form_Load()


WindowState = 2
End Sub
Private Sub Form_Click()
DrawWidth = 10
Line (100, 100)-(ScaleWidth / 2, ScaleHeight / 2), , B
Line (ScaleWidth / 2, ScaleHeight / 2)- _
(ScaleWidth - 100, ScaleHeight - 100), , B
End Sub
Private Sub Form_DblClick()
Cls
End Sub

b. Hasil
2. Latihan 4.2

a. Coding

Private Sub Form_Load()


WindowState = 2
End Sub
Private Sub Form_Click()
Dim I As Integer
Scale (0, 0)-(639, 199)
For I = 1 To 64 Step 5
ccode = QBColor(I Mod 16)
Line (5 * I, I)-(639 - 5 * I, 199 - I), ccode, BF
Next I
End Sub
Private Sub Form_DblClick()
Cls
End Sub

b. Hasil
3. Latihan 4.3

a. Coding

Private Sub Form_Load()


WindowState = 2
End Sub
Private Sub Form_Click()
Scale (0, 0)-(25, 25)
For I% = 0 To 7
FillStyle = I%
Line (0, 3 * I%)-(4, 3 * (I% + 0.8)), , B
CurrentX = 4.1: CurrentY = 3 * I% + 0.5
Print "This is FillStyle #"; I%
Next I%
End Sub
Private Sub Form_DblClick()
Cls
End Sub

b. Hasil
4. Latihan 4.4

a. Coding

Private Sub Form_Load()


WindowState = 2
End Sub
Private Sub Form_Click()
'Aspect ratio
Scale (-1, 1)-(1, -1)
Print
Print "Program ini mendemonstrasikan perbedaan Aspect Ratio."
Print "Setiap anda klik, mengakibatkan perubahan aspect ratio."
Print "Dimulai dari 0.5 kolom/baris dan penambahan 0.1"
Print "dengan increment sebesar 2 kolom/baris."
End Sub
Private Sub Form_DblClick()
Static Increment As Single
Dim Aspect As Single
Aspect = Increment
Cls
If Aspect > 1.5 Then End
Line (-0.5, 0.5)-(Aspect, -0.5), , BF
CurrentX = -1: CurrentY = -1
Print "Aspect Ratio #"; Format$(Aspect + 0.5, "0.00")
Increment = Increment + 0.1
End Sub
Private Sub Command1_Click()
Cls
End Sub
Private Sub Command2_Click()
Static Kolom, Baris As Single
Static CCode As Integer
DrawMode = 7
'baris ini untuk menghapus box dan me-restore background
Line (0, 0)-(Kolom, Baris), QBColor(CCode), BF
'baris ini memindahkan box secara random
Kolom = 100 * Rnd(1)
If Rnd(1) < 0.5 Then Kolom = -Kolom
Baris = 50 * Rnd(1)
If Rnd(1) < 0.5 Then Baris = -Baris
CCode = 15 * Rnd(1)
Line (0, 0)-(Kolom, Baris), QBColor(CCode), BF
End Sub
Private Sub Command3_Click()
DrawWidth = 10
DrawMode = 4
Line (-245, 134)-(245, -134)
DrawMode = 6
Line (245, 134)-(-245, -134)
End Sub

b. Hasil

 Clear Form

 Gambar Kotak
 Gambar Diagonal

Nomor 2 (Latihan 5)

1. Latihan 5.1

a. Coding

Dim I As Integer
Private Sub Form_Load()
I=1
End Sub
Private Sub Command1_Click()
If I > 7 Then I = 1
Form1.FillStyle = 0 + I
Line (1000 + (I * 50), 1000 + (I * 50))-Step(1000 + (I * 50), _
1000 + (I * 50)), , B
I=I+1
End Sub
b. Hasil

2. Latihan 5.2

a. Coding

Option Explicit
Const MINIMIZED = 1, NORMAL = 0, PI = 3.14
Const MARGIN = 10
Const OFFSET = PI / 2
Private Sub Command1_Click()
Form1.ScaleWidth = 100
Form1.ScaleHeight = 100
Circle (ScaleWidth / 2, ScaleHeight / 2), ScaleWidth / 4
End Sub
Private Sub Command2_Click()
Form1.ScaleWidth = 100
Form1.ScaleHeight = 100
Form1.PSet (Form1.ScaleWidth / 2, Form1.ScaleHeight / 2)
End Sub
Private Sub Command3_Click()
Form1.ScaleWidth = 100
Form1.ScaleHeight = 100
Form1.Line (50, 50)-(75, 75), RGB(255, 0, 0)
End Sub
Private Sub Command4_Click()
Form1.ScaleWidth = 100
Form1.ScaleHeight = 100
Form1.Line (25, 50)-(50, 55), RGB(255, 0, 0), BF
End Sub
Private Sub Command5_Click()
Form1.CurrentX = 70
Form1.CurrentY = 60
Print "Hello"
End Sub
Private Sub Command6_Click()
Form1.Cls
End Sub

b. Hasil
3. Latihan 5.3

a. Coding

Option Explicit
Dim X1 As Single, Y1 As Single, X2 As Single, Y2 As Single, I As
Single

Private Sub Form_Load()


I=1
End Sub

Private Sub Form_MouseDown(Button As Integer, _


Shift As Integer, X As Single, Y As Single)
'Refresh your start variables
X1 = X
Y1 = Y
X2 = X
Y2 = Y
End Sub

Private Sub Form_MouseMove(Button As Integer, _


Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Form1.DrawMode = 6
If Abs(X1 - X2) > 0 Then
Form1.Line ((X1 - 15) - Abs(X1 - X2), (Y1 - 15) - _
Abs(X1 - X2))-((X1 + 15) + Abs(X1 - X2), _
(Y1 + 15) + Abs(X1 - X2)), , B
Circle (X1, Y1), Abs(X2 - X1)
End If
X2 = X
Y2 = Y
If Abs(X1 - X2) > 0 Then Form1.Line ((X1 - 15) - _
Abs(X1 - X2), (Y1 - 15) - Abs(X1 - X2))-((X1 + 15) + _
Abs(X1 - X2), (Y1 + 15) + Abs(X1 - X2)), , B
Circle (X1, Y1), Abs(X1 - X2)
End If
End Sub
Private Sub Form_MouseUp(Button As Integer, Shift As Integer, X As
Single, Y As Single)
Form1.Line ((X1 - 15) - Abs(X1 - X2), (Y1 - 15) - _
Abs(X1 - X2))-((X1 + 15) + Abs(X1 - X2), (Y1 + 15) + _
Abs(X1 - X2)), , B
Form1.DrawMode = 13
Circle (X1, Y1), Abs(X - X1), RGB(215, 0, 0)
End Sub

b. Hasil

4. Latihan 5.4

a. Coding

Option Explicit
Dim lastX As Single, lastY As Single, centerX As Single, centerY As
Single
Dim ArcPoints(1 To 3) As Boolean, a(1 To 3) As Single, iL As Integer
Const PI = 3.14159265358979
Private Sub ClearPoints()
Cls
For iL = 1 To 3
ArcPoints(iL) = False
a(iL) = 0
Next
End Sub
Public Function ATan3(ByVal dy As Single, ByVal dx As Single) As
Single
Select Case lastY - centerY
Case Is < 0: ATan3 = (PI / 2) + Atn(dy / dx)
Case Is > 0: ATan3 = (PI * 1.5) + Atn(dy / dx)
Case Is = 0: ATan3 = IIf(lastX < centerX, PI, PI * 2)
End Select
End Function
Private Sub Command1_Click()
ClearPoints
End Sub
Private Sub Form_Load()
ClearPoints
End Sub
Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X
As Single, Y As Single)
If ArcPoints(2) And Not ArcPoints(3) Then
DrawMode = vbCopyPen
Line (centerX, centerY)-(lastX, lastY)
a(3) = ATan3(lastX - centerX, lastY - centerY)
Circle (centerX, centerY), a(1), vbBlack, a(2), a(3)
ArcPoints(3) = True
End If
If ArcPoints(1) And Not ArcPoints(2) Then
Line (centerX, centerY)-(lastX, lastY)
a(1) = Sqr((Abs(lastX - centerX) ^ 2) + (Abs(lastY - centerY) ^ 2))
a(2) = ATan3(lastX - centerX, lastY - centerY)
ArcPoints(2) = True
DrawMode = vbInvert
End If
If Not ArcPoints(1) Then
centerX = X
centerY = Y
Line (centerX - 50, centerY)-Step(100, 0), vbRed
Line (centerX, centerY - 50)-Step(0, 100), vbRed
ArcPoints(1) = True
DrawMode = vbInvert
End If
lastX = X
lastY = Y
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X
As Single, Y As Single)
If Not ArcPoints(1) Then Exit Sub
If ArcPoints(1) And Not ArcPoints(2) Then
Me.Line (centerX, centerY)-(lastX, lastY)
lastX = X
lastY = Y
Me.Line (centerX, centerY)-(lastX, lastY)
End If
If ArcPoints(2) And Not ArcPoints(3) Then
Me.Line (centerX, centerY)-(lastX, lastY)
If a(3) <> 0 Then Me.Circle (centerX, centerY), a(1), vbBlack, a(2),
a(3)
lastX = X
lastY = Y
a(3) = ATan3(lastX - centerX, lastY - centerY)
Me.Line (centerX, centerY)-(lastX, lastY)
Me.Circle (centerX, centerY), a(1), vbBlack, a(2), a(3)
End If
End Sub

b. Hasil