VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



A Rainbow Generator

by K. O. Thaha Hussain (5 Submissions)
Category: Graphics
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (6 Votes)

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!

Rate A Rainbow Generator

'(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

Download this snippet    Add to My Saved Code

A Rainbow Generator Comments

No comments have been posted about A Rainbow Generator. Why not be the first to post a comment about A Rainbow Generator.

Post your comment

Subject:
Message:
0/1000 characters