Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
Sfera 3D - Form1.vb

Form1.vb

Caricato da: VB.NET_Program_91
Scarica il programma completo

  1. Public Class Form1
  2.     Dim g As System.Drawing.Graphics
  3.     Dim pen1 As New System.Drawing.Pen(Color.Red, 0.5)
  4.     Const PI = 3.14159
  5.     Dim flag, col, r, h, hl, n, n1 As Short
  6.     Dim x, y, z, cx, cy, cz, thx, thy, thz As Single
  7.     Dim ed, od, eh As Short
  8.     Dim point1, point2, point3, point4, point5 As System.Drawing.Point
  9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         PictureBox1.Refresh()
  11.         g = PictureBox1.CreateGraphics
  12.         Dim i, r As Integer
  13.         Dim x, y, z, s, q, p, px, py As Single
  14.         Dim mx(600), my(600) As Integer
  15.         s = PI / 4
  16.         r = 100
  17.         i = 1
  18.         q = -PI / 2 + 0.1
  19.         For p = 0 To 2 * PI Step 0.2
  20.             x = r * Math.Cos(q) * Math.Sin(p)
  21.             y = r * Math.Sin(q)
  22.             z = r * Math.Cos(q) * Math.Cos(p)
  23.             px = x * 1.2
  24.             py = y - z * Math.Sin(s)
  25.             mx(i) = px + 200
  26.             my(i) = 150 - py
  27.             i = i + 1
  28.         Next p
  29.         point1.X = mx(1) : point1.Y = my(1)
  30.         For q = -PI / 2 + 0.2 To PI / 2 Step 0.2
  31.             i = 1
  32.             For p = 0 To 2 * PI Step 0.2
  33.                 x = r * Math.Cos(q) * Math.Sin(p)
  34.                 y = r * Math.Sin(q)
  35.                 z = r * Math.Cos(q) * Math.Cos(p)
  36.                 px = x * 1.2
  37.                 py = y - z * Math.Sin(s)
  38.  
  39.                 point2.X = px + 200 : point2.Y = 150 - py
  40.                 g.DrawLine(pen1, point1, point2)
  41.  
  42.                 point1 = point2
  43.  
  44.                 point3.X = mx(i) : point3.Y = my(i)
  45.                 point4.X = px + 200 : point4.Y = 150 - py
  46.                 g.DrawLine(pen1, point3, point4)
  47.                 point3 = point4
  48.                 mx(i) = px + 200
  49.                 my(i) = 150 - py
  50.                 i = i + 1
  51.             Next p
  52.             p = 0
  53.             x = r * Math.Cos(q) * Math.Sin(p)
  54.             y = r * Math.Sin(q)
  55.             z = r * Math.Cos(q) * Math.Cos(p)
  56.             px = x * 1.2
  57.             py = y - z * Math.Sin(s)
  58.  
  59.             point5.X = px + 200 : point5.Y = 150 - py
  60.             g.DrawLine(pen1, point4, point5)
  61.             point4 = point5
  62.         Next q
  63.     End Sub
  64. End Class