Solved

Color fade to white using Pset

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Macro which automatically sends attachment to Outlook 14 61
VBA error replacing data 6 37
VBA: Select SQL query based on a config Sheet v2 11 38
Problem to With line 4 43
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

867 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

21 Experts available now in Live!

Get 1:1 Help Now