scripting color

hue shift

Saturday, June 14, 2008 by PuterDudeJim | Discussion: DesktopX Tutorials

Hello all. I am trying to create an object that will control the hue of 5 other objects. I have a script that will allow me to change each objects color individually. But I need to change them all at once. Can anyone help me? I will post the script I am using below.      Thanx.
'Called when L-click is released
Function Object_OnLButtonUp(x, y, dragged)
 If Not dragged Then
  'Store the current hue in variable
  hueshift = Object.hue
  'If current hue is equal to or greater than 255
  'reset to 0
  If hueshift => 255 Then
   hueshift = 0
  'If hue is not yet 255, keep adding
  Else
   hueshift = hueshift + 7
  End If
  'Set the object hue
  object.hue = hueshift
 End If
End Function
First Previous Page 1 of 2 Next Last
ArileenDesign
Reply #1 Sunday, June 15, 2008 6:31 AM
I use this script to change the hue of all objects i want.


Code: vbscript
  1. Sub Object_OnLbuttonUp(x,y,dragged)
  2. If Not dragged Then
  3. If DesktopX.Object("ObjectName1").States("").Hue => 255 Then
  4. DesktopX.Object("ObjectName1").States("").Hue = 0
  5. Else
  6. DesktopX.Object("ObjectName1").States("").Hue = DesktopX.Object("ObjectName1").States("").Hue + 15
  7. End If
  8. If DesktopX.Object("ObjectName2").States("").Hue => 255 Then
  9. DesktopX.Object("ObjectName2").States("").Hue = 0
  10. Else
  11. DesktopX.Object("ObjectName2").States("").Hue = DesktopX.Object("ObjectName2").States("").Hue + 15
  12. End If
  13. End If
  14. End Sub


Simply add any other elements like ObjectName3 before the last End If:

Code: vbscript
  1. If DesktopX.Object("ObjectName3").States("").Hue => 255 Then
  2. DesktopX.Object("ObjectName3").States("").Hue = 0
  3. Else
  4. DesktopX.Object("ObjectName3").States("").Hue = DesktopX.Object("ObjectName3").States("").Hue + 15
  5. End If


yeah i know when you have a theme it begins to be really crazy.

Vad_M
Reply #2 Sunday, June 15, 2008 8:02 AM
This is very easy! Just use this code:

Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
Dim objects
objects = Array("name1","name2","name3","name4","name5") '<== enter the names of your objects here
'Store the current hue in variable
hueshift = Object.hue
'If current hue is equal to or greater than 255
'reset to 0
If hueshift => 255 Then
hueshift = 0
'If hue is not yet 255, keep adding
Else
hueshift = hueshift + 7
End If
'Set the object hue
For Each item In objects
desktopx.object(item).states("").hue = hueshift
'or use this if you need change hue for current state only
'desktopx.object(item).hue = hueshift
Next
Set objects = nothing '<== clear memory
End If
End Function

Best Regards.   
ArileenDesign
Reply #3 Sunday, June 15, 2008 10:19 AM
Good! I used this on my old work, but since i'm learning script (yeah before i knew nothing about it, was just missing around)
I should have thought about Array, way better and easier.
ArileenDesign was sure he needed to rewrite all his codes... 
SirSmiley
Reply #4 Sunday, June 15, 2008 10:27 AM
If all the items are in a group, let me throw another one out there.
Same as Vlad's but, without array, etc.
Code: vbscript
  1. Function Object_OnLButtonUp(x, y, dragged)
  2. If Not dragged Then
  3. 'Store the current hue in variable
  4. hueshift = Object.hue
  5. 'If current hue is equal to or greater than 255
  6. 'reset to 0
  7. If hueshift => 255 Then
  8. hueshift = 0
  9. 'If hue is not yet 255, keep adding
  10. Else
  11. hueshift = hueshift + 7
  12. End If
  13. ' Set the Object Hue
  14. For Each Item In DesktopX.GroupObjects("grpMyObjects")
  15. Item.states("").hue = hueshift
  16. 'or use this if you need change hue for current state only
  17. 'Item.hue = hueshift
  18. Next
  19. Set objects = nothing '<== clear memory
  20. End If
  21. End Function
PuterDudeJim
Reply #5 Sunday, June 15, 2008 7:00 PM
Thanx all! I need to know how to script to toggle all sounds in a theme. Is that doable? Thanx again?
SirSmiley
Reply #6 Sunday, June 15, 2008 7:45 PM
I use boolean variables in the Birthday Widget that's in the works. The main question is does each object have a different sound.

This will work if all objects have the same sound.

Code: vbscript
  1. ' Declare Boolean Variable & Set
  2. Dim blnMute : blnMute = False
  3. ' Declare & Set Sound File
  4. Dim oSndFile : oSndFile = "C:\mysoundfile.wav"
  5. Function Object_OnLButtonUp(x, y, dragged)
  6. If Not dragged Then
  7. For Each Item In DesktopX.GroupObjects("grpMyObjects")
  8. If blnMute=False Then
  9. Ext=Right(oSndFile ,3)
  10. ' Verify correct extension
  11. If Ext="wav" Or Ext="WAV" Or Ext="mp3" Or Ext="MP3" Or Ext="Mp3" Then
  12. Item.Sound=oSndFile
  13. Else
  14. msgbox "Not a Valid Sound File"
  15. End If
  16. ElseIf blnMute=True Then
  17. Item.Sound=""
  18. End If
  19. Next
  20. End If
  21. End Function
PuterDudeJim
Reply #7 Sunday, June 15, 2008 9:20 PM
I use boolean variables in the Birthday Widget that's in the works. The main question is does each object have a different sound.

This will work if all objects have the same sound.


4 different sets of sounds. Does this script go in the button to toggle the sounds? I assume that the C:\mysoundfile.wav needs to be changed to the name of the wav file?
SirSmiley
Reply #8 Monday, June 16, 2008 12:00 AM
Yeah that would go into the sound toggle button. I'm going to break the script down easier. If you're going to package a theme then make sure the sound files are attached via the custom files option.

This should do the job.
Code: vbscript
  1. ' Declare Boolean
  2. Dim blnMute
  3. Function Object_OnLButtonUp(x, y, dragged)
  4. If Not dragged Then
  5. If blnMute=False Then
  6. ' Turn on Sounds
  7. blnMute=True
  8. DesktopX.Object("object1").Sound="C:\mysoundfile.wav"
  9. ' If you use custom files then you just need to enter the name
  10. DesktopX.Object("object2").Sound="mysoundfile.wav"
  11. ' Use this for a specific state sound
  12. DesktopX.Object("object3").States("Mouse down").Sound= "somesound.wav"
  13. DesktopX.Object("object4").Sound=
  14. ElseIf blnMute=True Then
  15. ' Disable Sounds
  16. blnMute=False
  17. DesktopX.Object("object1").Sound=""
  18. DesktopX.Object("object2").Sound=""
  19. ' Use this for a specific state sound
  20. DesktopX.Object("object3").States("Mouse down").Sound=""
  21. DesktopX.Object("object4").Sound=""
  22. End If
  23. End If
  24. End Function
PuterDudeJim
Reply #9 Monday, June 16, 2008 3:49 PM
Used this, did not work. Getting an error message.

' Declare Boolean
Dim blnMute

Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
If blnMute=False Then
' Turn on Sounds
blnMute=True
DesktopX.Object("object1").Sound="Windows Restore.wav"
' If you use custom files then you just need to enter the name
DesktopX.Object("object2").Sound="Windows Battery Low.wav"
' Use this for a specific state sound
DesktopX.Object("object3").States("Mouse down").Sound= "Windows Critical Stop.wav"
DesktopX.Object("object4").Sound="Windows Logon Sound.wav"
DesktopX.Object("object5").Sound="Windows Minimize.wav"
ElseIf blnMute=True Then
' Disable Sounds
blnMute=False
DesktopX.Object("object1").Sound=""
DesktopX.Object("object2").Sound=""
' Use this for a specific state sound
DesktopX.Object("object3").States("Mouse down").Sound=""
DesktopX.Object("object4").Sound=""
DesktopX.Object("object5").Sound=""
End If
End Function



Vad_M
Reply #10 Monday, June 16, 2008 4:14 PM
DesktopX.Object("object1").Sound="Windows Restore.wav"
' If you use custom files then you just need to enter the name
DesktopX.Object("object2").Sound="Windows Battery Low.wav"
' Use this for a specific state sound
DesktopX.Object("object3").States("Mouse down").Sound= "Windows Critical Stop.wav"
DesktopX.Object("object4").Sound="Windows Logon Sound.wav"
DesktopX.Object("object5").Sound="Windows Minimize.wav"


Hmmm... I see that you tried to play 5 sounds simultaneously.    Seems this is impossible...

What the error message have you received?
PuterDudeJim
Reply #11 Monday, June 16, 2008 9:14 PM
All the sounds should be when mouse down, and not all at the same time.But 5 different sounds.


Error = Object required: 'DesktopX.Object(...)'
Line: 9
Code:
(not available)
SirSmiley
Reply #12 Monday, June 16, 2008 9:15 PM
Hmmm... I see that you tried to play 5 sounds simultaneously. Seems this is impossible...

What the error message have you received?


Ha ha...guess I spent to much time on the computer. Forgot that there is no "set sound" option and it only plays. I'm dead tired but, should have something for you soon.

Edit: PS you also didn't close off all the If Statements; so, add another "End If" on a line above the End Function
PuterDudeJim
Reply #13 Monday, June 16, 2008 9:18 PM
Oops...double post. Darn it!
SirSmiley
Reply #14 Monday, June 16, 2008 9:42 PM
Do the objects you want to change the sounds on have the same parent object?

Actually, if you just want to turn the object sounds on/off then object.volume might be better. Was looking and hoping for an object.mute namespace but, it's actually just object.volume=0
PuterDudeJim
Reply #15 Monday, June 16, 2008 9:48 PM
Do the objects you want to change the sounds on have the same parent object?


The first set of buttons have the same parent object. The second set of buttons share a different parent object, etc.
SirSmiley
Reply #16 Monday, June 16, 2008 9:58 PM
Forget the question about the parent objects. Using the object.volume makes more sense.

This should work

Code: vbscript
  1. ' Declare Boolean
  2. Dim blnMute
  3. Function Object_OnLButtonUp(x, y, dragged)
  4. If Not dragged Then
  5. If blnMute=False Then' Turn on Sounds
  6. blnMute=True
  7. DesktopX.Object("object1").Volume=100
  8. DesktopX.Object("object2").Volume=100
  9. DesktopX.Object("object3").Volume= 100
  10. DesktopX.Object("object4").Volume=100
  11. DesktopX.Object("object5").Volume=100
  12. ElseIf blnMute=True Then' Disable Sounds
  13. blnMute=False
  14. DesktopX.Object("object1").Volume=0
  15. DesktopX.Object("object2").Volume=0
  16. DesktopX.Object("object3").Volume=0
  17. DesktopX.Object("object4").Volume=0
  18. DesktopX.Object("object5").Volume=0
  19. End If
  20. End If
  21. End Function
PuterDudeJim
Reply #17 Monday, June 16, 2008 10:07 PM
I put this in:

' Declare Boolean
Dim blnMute
Function Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
If blnMute=False Then' Turn on Sounds
blnMute=True
DesktopX.Object("Windows Restore.wav").Volume=100
DesktopX.Object("Windows Battery Low.wav").Volume=100
DesktopX.Object("Windows Critical Stop.wav").Volume= 100
DesktopX.Object("Windows Logon Sound.wav").Volume=100
DesktopX.Object("Windows Minimize.wav").Volume=100
ElseIf blnMute=True Then' Disable Sounds
blnMute=False
DesktopX.Object("Windows Restore.wav").Volume=0
DesktopX.Object("Windows Battery Low.wav").Volume=0
DesktopX.Object("Windows Critical Stop.wav").Volume=0
DesktopX.Object("Windows Logon Sound.wav").Volume=0
DesktopX.Object("Windows Minimize.wav").Volume=0
End If
End If
End Function



Got this:


Object required: 'DesktopX.Object(...)'
Line: 7
Code:
(not available)   
PuterDudeJim
Reply #18 Monday, June 16, 2008 10:08 PM
Do I just put this script into a button?
SirSmiley
Reply #19 Monday, June 16, 2008 11:16 PM
Yep, just put this script into the button you want to control the sounds with.

You need to put the object names in the quotation marks not the sound files. You can just add those through the DesktopX Gui like you normally would.
PuterDudeJim
Reply #20 Tuesday, June 17, 2008 12:32 AM
I did what you said, no error messages, just didn't work. Hmmm....

Please login to comment and/or vote for this skin.

Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:

  • Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
  • Access to a great community, with a massive database of many, many areas of interest.
  • Access to contests & subscription offers like exclusive emails.
  • It's simple, and FREE!



web-wc01