VB icon

A Rainbow Generator

Email
Submitted on: 1/16/2015 2:22:00 PM
By: K. O. Thaha Hussain (from psc cd)  
Level: Intermediate
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 1576
 
     It is an extremly simple Rainbow Generator - the code which was always asked by the viewers. See how a rainbow is generated with the varaitions in the values of primary colors - Red, Green and Blue. No API's used. Interesting and Full of Fun! Easy even for beginners!

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: A Rainbow Generator
' Description:It is an extremly simple Rainbow Generator - the code which was always asked by the viewers. See how a rainbow is generated with the varaitions in the values of primary colors - Red, Green and Blue. No API's used. Interesting and Full of Fun! Easy even for beginners!
' By: K. O. Thaha Hussain (from psc cd)
'**************************************

'(C)2001 K. O. Thaha Hussain. India
' Analyst Programmer
' All Rights Reserved
' URL : www.bcity.com/thahahussain
' Company : www.induswareonline.com
Option Explicit
Private Sub Form_Load()
Me.AutoRedraw = True
Me.ScaleMode = vbTwips
Me.Caption = "Rainbow Generator by " & _
 "K. O. Thaha Hussain"
MsgBox "Resize the window to resize the Rainbow", , _
"Thaha Hussain's Rainbow Generator"
End Sub
Private Sub Form_Resize()
Call Rainbow
End Sub
Private Sub Rainbow()
On Error Resume Next
Dim Position As Integer, Red As Integer, Green As _
Integer, Blue As Integer
Dim ScaleFactor As Double, Length As Integer
ScaleFactor = Me.ScaleWidth / (255 * 6)
Length = Int(ScaleFactor * 255)
Position = 0
Red = 255
Blue = 1
'Purposfully avoided nested loops
 '------------- 1
 For Green = 1 To Length
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red, Green \ ScaleFactor, Blue)
 Position = Position + 1
 Next Green
'--------------- 2
For Red = Length To 1 Step -1
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red \ ScaleFactor, Green, Blue)
 Position = Position + 1
 Next Red
'---------------- 3
For Blue = 0 To Length
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red, Green, Blue \ ScaleFactor)
 Position = Position + 1
 Next Blue
 
 '----------------- 4
For Green = Length To 1 Step -1
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red, Green \ ScaleFactor, Blue)
 Position = Position + 1
 Next Green
 
 '------------------ 5
 For Red = 1 To Length
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red \ ScaleFactor, Green, Blue)
 Position = Position + 1
 Next Red
'------------------- 6
For Blue = Length To 1 Step -1
 Me.Line (Position, 0)-(Position, Me.ScaleHeight), _
 RGB(Red, Green, Blue \ ScaleFactor)
 Position = Position + 1
 Next Blue
End Sub


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.