home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / ch_code / ch06 / clrgrads / clrgrads.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-02-20  |  6.4 KB  |  189 lines

  1. VERSION 5.00
  2. Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
  3. Begin VB.Form Form1 
  4.    BorderStyle     =   4  'Fixed ToolWindow
  5.    Caption         =   "Gradients"
  6.    ClientHeight    =   5415
  7.    ClientLeft      =   45
  8.    ClientTop       =   285
  9.    ClientWidth     =   6075
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    PaletteMode     =   1  'UseZOrder
  14.    ScaleHeight     =   5415
  15.    ScaleWidth      =   6075
  16.    ShowInTaskbar   =   0   'False
  17.    StartUpPosition =   3  'Windows Default
  18.    Begin VB.CommandButton Command1 
  19.       Caption         =   "Linear Gradient"
  20.       BeginProperty Font 
  21.          Name            =   "Times New Roman"
  22.          Size            =   9.75
  23.          Charset         =   0
  24.          Weight          =   400
  25.          Underline       =   0   'False
  26.          Italic          =   0   'False
  27.          Strikethrough   =   0   'False
  28.       EndProperty
  29.       Height          =   360
  30.       Left            =   750
  31.       TabIndex        =   4
  32.       Top             =   210
  33.       Width           =   1665
  34.    End
  35.    Begin VB.PictureBox EndColor 
  36.       AutoRedraw      =   -1  'True
  37.       BackColor       =   &H0000FFFF&
  38.       Height          =   5205
  39.       Left            =   5505
  40.       ScaleHeight     =   5145
  41.       ScaleWidth      =   390
  42.       TabIndex        =   3
  43.       Top             =   120
  44.       Width           =   450
  45.    End
  46.    Begin VB.PictureBox StartColor 
  47.       AutoRedraw      =   -1  'True
  48.       BackColor       =   &H00FFFF00&
  49.       Height          =   5220
  50.       Left            =   105
  51.       ScaleHeight     =   5160
  52.       ScaleWidth      =   390
  53.       TabIndex        =   2
  54.       Top             =   90
  55.       Width           =   450
  56.    End
  57.    Begin VB.PictureBox Picture2 
  58.       AutoRedraw      =   -1  'True
  59.       BackColor       =   &H00404040&
  60.       Height          =   2385
  61.       Left            =   2145
  62.       Picture         =   "ClrGrads.frx":0000
  63.       ScaleHeight     =   155
  64.       ScaleMode       =   3  'Pixel
  65.       ScaleWidth      =   197
  66.       TabIndex        =   1
  67.       Top             =   2775
  68.       Width           =   3015
  69.       Begin VB.CommandButton Command2 
  70.          BackColor       =   &H8000000A&
  71.          Caption         =   "Circular Gradient"
  72.          BeginProperty Font 
  73.             Name            =   "Times New Roman"
  74.             Size            =   9.75
  75.             Charset         =   0
  76.             Weight          =   400
  77.             Underline       =   0   'False
  78.             Italic          =   0   'False
  79.             Strikethrough   =   0   'False
  80.          EndProperty
  81.          Height          =   375
  82.          Left            =   75
  83.          TabIndex        =   5
  84.          Top             =   1890
  85.          Width           =   1890
  86.       End
  87.    End
  88.    Begin VB.PictureBox Picture1 
  89.       AutoRedraw      =   -1  'True
  90.       Height          =   5175
  91.       Left            =   675
  92.       Picture         =   "ClrGrads.frx":0446
  93.       ScaleHeight     =   341
  94.       ScaleMode       =   3  'Pixel
  95.       ScaleWidth      =   309
  96.       TabIndex        =   0
  97.       Top             =   120
  98.       Width           =   4695
  99.    End
  100.    Begin MSComDlg.CommonDialog CommonDialog1 
  101.       Left            =   4740
  102.       Top             =   4005
  103.       _ExtentX        =   847
  104.       _ExtentY        =   847
  105.       FontSize        =   2.54052e-29
  106.    End
  107. Attribute VB_Name = "Form1"
  108. Attribute VB_GlobalNameSpace = False
  109. Attribute VB_Creatable = False
  110. Attribute VB_PredeclaredId = True
  111. Attribute VB_Exposed = False
  112. Option Explicit
  113. Function GetRed(colorVal As Long) As Integer
  114.      GetRed = colorVal Mod 256
  115.         
  116. End Function
  117. Function GetGreen(colorVal As Long) As Integer
  118.     GetGreen = ((colorVal And &HFF00FF00) / 256&)
  119. End Function
  120. Function GetBlue(colorVal As Long) As Integer
  121.     GetBlue = (colorVal And &HFF0000) / (256& * 256&)
  122. End Function
  123. Private Sub Command1_Click()
  124. Dim newColor As Long
  125. Dim ipixel, PWidth As Integer
  126. Dim redInc, greenInc, blueInc As Single
  127. Dim color1 As Long, color2 As Long
  128. Dim startRed, startGreen, startBlue As Integer
  129. Dim endRed, endGreen, endBlue As Integer
  130.     color1 = StartColor.BackColor
  131.     color2 = EndColor.BackColor
  132.     startRed = GetRed(color1)
  133.     endRed = GetRed(color2)
  134.     startGreen = GetGreen(color1)
  135.     endGreen = GetGreen(color2)
  136.     startBlue = GetBlue(color1)
  137.     endBlue = GetBlue(color2)
  138.         
  139.     PWidth = Picture1.ScaleWidth
  140.     redInc = (endRed - startRed) / PWidth
  141.     greenInc = (endGreen - startGreen) / PWidth
  142.     blueInc = (endBlue - startBlue) / PWidth
  143.     For ipixel = 0 To PWidth - 1
  144.         newColor = RGB(startRed + redInc * ipixel, startGreen + greenInc * ipixel, startBlue + blueInc * ipixel)
  145.         Picture1.Line (ipixel, 0)-(ipixel, Picture1.Height - 1), newColor
  146.     Next
  147. End Sub
  148. Private Sub Command2_Click()
  149. Dim newColor As Long
  150. Dim radius, ipixel, PWidth As Integer
  151. Dim redInc, greenInc, blueInc As Single
  152. Dim color1 As Long, color2 As Long
  153. Dim startRed, startGreen, startBlue As Integer
  154. Dim endRed, endGreen, endBlue As Integer
  155.     color1 = StartColor.BackColor
  156.     color2 = EndColor.BackColor
  157.     startRed = color1 Mod 256
  158.     endRed = color2 Mod 256
  159.     startGreen = ((color1 And &HFF00) / 256&) Mod 256&
  160.     endGreen = ((color2 And &HFF00) / 256&) Mod 256&
  161.     startBlue = (color1 And &HFF0000) / (256& * 256&)
  162.     endBlue = (color2 And &HFF0000) / (256& * 256&)
  163.         
  164.     PWidth = Picture1.ScaleWidth / 2
  165.     redInc = (endRed - startRed) / PWidth
  166.     greenInc = (endGreen - startGreen) / PWidth
  167.     blueInc = (endBlue - startBlue) / PWidth
  168.     Picture2.DrawWidth = 2
  169.     ipixel = 0
  170.     For radius = PWidth / 2 To 1 Step -1
  171.         newColor = RGB(startRed + redInc * ipixel, startGreen + greenInc * ipixel, startBlue + blueInc * ipixel)
  172.         Picture2.Circle (Picture2.ScaleWidth / 2, Picture2.ScaleHeight / 2), radius, newColor
  173.         ipixel = ipixel + 2
  174.         'Picture2.Refresh
  175.     Next
  176. End Sub
  177. Private Sub EndColor_Click()
  178.     CommonDialog1.Color = EndColor.BackColor
  179.     CommonDialog1.ShowColor
  180.     EndColor.BackColor = CommonDialog1.Color
  181. End Sub
  182. Private Sub Picture4_Click()
  183. End Sub
  184. Private Sub StartColor_Click()
  185.     CommonDialog1.Color = StartColor.BackColor
  186.     CommonDialog1.ShowColor
  187.     StartColor.BackColor = CommonDialog1.Color
  188. End Sub
  189.