Solved

Color fade to white using Pset

Posted on 2004-03-21
4
2,213 Views
Last Modified: 2007-12-19
Hi

I need help with the logic to use pset to draw a color bar that fades from a given RGB to white over the scalewidth of a form.

Private Sub Command1_Click()

Dim r As Integer
Dim g As Integer
Dim b As Integer

r = 14
g = 67
b = 146

For i = 1 To Me.ScaleWidth Step 1
  For j = 1 To CInt(Me.ScaleHeight / 10) Step 10
     ' how do I increment the values of r,g,b to 255 relative to the ScaleWidth?
     ' if that makes sense?
     ' The idea is that r,g,b should arrive at 255 at about the same time.
    PSet (i, j), RGB(r, g, b)
  Next j
Next i


End Sub


Alan
0
Comment
Question by:Alan Warren
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Nazdor earned 250 total points
ID: 10647575
Increment by: the difference / number of steps

ie:

dim rd as integer, gd as integer, bd as integer

rd = (255 - r) \ (me.scaleheight \ 10)
gd = (255 - g) \ (me.scaleheight \ 10)
bd = (255 - b) \ (me.scaleheight \ 10)

...
   r = r + rd
   g = g + gd
   b = b + bd

I've used "\" instead of "/" as "\" is integer divide, so you don't need CInt(), but you may find it works better using single for the colours + deltas (rd,gd,bd) then CInt ing them at the time of PSet


As a side, PSet is not going to be the quickest way to do this (it might be very slow) - you'll have to look into making API calls, but that's another subject.
0
 
LVL 26

Author Comment

by:Alan Warren
ID: 10653669
Hi Nazdor,

Thanks for that mate.

The speed is not an issue, it's just a tool for creating some background jpegs to be used for style switching with css.
So I hope to have half a dozen jpegs that fade from left to right 800px wide * 1px high that I can apply with Cascading Style Sheets like this. So achieving maximum impact with very little data transfer accross the WAN

body.standard
  {
    margin-top:0px;
    margin-left:0px;
    margin-right:0px;
    margin-bottom:0px;
    font-weight:normal;
    font:9pt Verdana, Tahoma, Arial, swiss, sans-serif;
    color:#FFFFFF;
    background: url("../images/header-background.jpg");
    background-repeat: repeat-y;   //* the repeat-y is like a fill down *//
  }
 

Anyway after a bit of mucking around this is close enough to what I wanted.

Private Sub Command1_Click()
Me.Refresh
Dim r As Integer
Dim g As Integer
Dim b As Integer
Dim x As Integer

Dim iIncR As Integer
Dim iIncG As Integer
Dim iIncB As Integer

' 37,47,90
r = 37
g = 47
b = 90

x = CInt(Me.ScaleWidth / 156)

iIncR = CInt((255 - r))
iIncG = CInt((255 - g))
iIncB = CInt((255 - b))

For i = 1 To Me.ScaleWidth Step 1
  If (i + iIncR) Mod x = 0 Then: r = r + 1: 'Debug.Print r, g, b
  If (i + iIncG) Mod x = 0 Then: g = g + 1: 'Debug.Print r, g, b
  If (i + iIncB) Mod x = 0 Then: b = b + 1: 'Debug.Print r, g, b
  'If Me.ScaleWidth - i = 150 Then: Debug.Print Hex(r) & Hex(g) & Hex(b)
  For j = 1 To CInt(Me.ScaleHeight / 8)
    PSet (i, j), RGB(r, g, b)
  Next j
Next i

End Sub


Alan
0
 
LVL 4

Expert Comment

by:Nazdor
ID: 10662613
Sorry, should have looked quite a bit closer at your example - just assumed it was a kind of picture fades to white type of thing.  There are some cool api functions that might do what you want, just can't think of them off the top of my head.  But if you've got what you want, then there's no worry.
0
 
LVL 26

Author Comment

by:Alan Warren
ID: 10662657
Hi Nazdor,

Thanks for your help, it looks good, check it out.
Using binary large objects with Microsoft Access
  http://www26.brinkster.com/alzowze/blobs.asp

Alan
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now