Solved

Color fade to white using Pset

Posted on 2004-03-21
4
2,219 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

770 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