?
Solved

Color fade to white using Pset

Posted on 2004-03-21
4
Medium Priority
?
2,236 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 4

Accepted Solution

by:
Nazdor earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…
Suggested Courses
Course of the Month13 days, 6 hours left to enroll

777 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