Flycatcher
06-20-02, 03:52 PM
I've been trying my first stab at ZScripting today, starting logically enough with Davey's Lesson 1. I enjoyed the very clear tutorial and found the first exercise easy, but... then made the confidence-eroding mistake of going into experimental mode.
:(
As is my wont with any new programming language, I added a little extra practice by setting myself related problems that required dipping into the Reference Guide for a bit of extra information. So having successfully completed the complementary colour exercise, I tried a slightly more ambitious one on the colour wheel theme. The script below is supposed to display a button which when clicked displays a colour swatch in the script window comprising the current main colour and the other two triadic colours from the colour wheel (i.e. the additional two colours equidistant from the main colour and each other). The user is also supposed to be able to then change the main colour if he wishes, and press the button again to see the new triadic set, ad infinitum.
[PenMoveLeft]
[VarDef, r(3)]
[VarDef, g(3)]
[VarDef, b(3)]
[IButton, "Triadic Colours", "Show the triadic colours based on the current colour",
[VarSet, r(0), [IGet, Color:Red Component]]
[VarSet, g(0), [IGet, Color:Green Component]]
[VarSet, b(0), [IGet, Color:Blue Component]]
[VarSet, r(1), g(0)]
[VarSet, r(2), b(0)]
[VarSet, g(1), b(0)]
[VarSet, g(2), r(0)]
[VarSet, b(1), r(0)]
[VarSet, b(2), g(0)]
[PenMoveLeft]
[PenMove, 160]
[PenSetColor, r(0), g(0), b(0)]
[PaintRect, 20, 20]
[PenSetColor, r(1), g(1), b(1)]
[PaintRect, 20, 20]
[PenSetColor, r(2), g(2), b(2)]
[PaintRect, 20, 20]
, , , shift+alt+'T'
]
I know I could have made this shorter by not using array variables, but I thought it would give me practice with a few extra commands, and anyway makes it easier to see what is going on - never a bad thing in my experience. They, however, were not what gave me difficulties; displaying the results did. I have three problems with this script, the first two obviously closely related and possibly indicating something I don't know about the PaintRect command:
1. When the button is first pressed, the colour swatch appears, but only displays approximately the bottom quarter of the squares. However, if I then Alt-Tab to switch windows to my text editor then straight back again to ZBrush, the 20x20 squares are now displayed in full.
2. On changing the main colour and pressing again, either just the bottom quarter or so of the new swatch similarly appears (overwriting the bottom of the original swatch), or more often nothing appears to change at all until I leave the ZBrush window then return to it, when either way once again the new triadic swatch appears perfectly overwriting the previous version as intended.
3. Finally, my original intention had been to display the colour swatch just to the right of the button with the tops of the button and the swatch aligned. No combination of pen movements that I was able to come up with achieved this, hence I settled in the end for what you see here - a vertical displacement as well as a horizontal one.
Any help with either the strange screen-refresh problem or my failure to understand the pen movements properly will be greatly appreciated. I feel really stupid at having so many problems with such a simple script, but then again it is my first attempt so please be kind.
In case it matters, I'm on a PC running Windows 98 SE.
:(
As is my wont with any new programming language, I added a little extra practice by setting myself related problems that required dipping into the Reference Guide for a bit of extra information. So having successfully completed the complementary colour exercise, I tried a slightly more ambitious one on the colour wheel theme. The script below is supposed to display a button which when clicked displays a colour swatch in the script window comprising the current main colour and the other two triadic colours from the colour wheel (i.e. the additional two colours equidistant from the main colour and each other). The user is also supposed to be able to then change the main colour if he wishes, and press the button again to see the new triadic set, ad infinitum.
[PenMoveLeft]
[VarDef, r(3)]
[VarDef, g(3)]
[VarDef, b(3)]
[IButton, "Triadic Colours", "Show the triadic colours based on the current colour",
[VarSet, r(0), [IGet, Color:Red Component]]
[VarSet, g(0), [IGet, Color:Green Component]]
[VarSet, b(0), [IGet, Color:Blue Component]]
[VarSet, r(1), g(0)]
[VarSet, r(2), b(0)]
[VarSet, g(1), b(0)]
[VarSet, g(2), r(0)]
[VarSet, b(1), r(0)]
[VarSet, b(2), g(0)]
[PenMoveLeft]
[PenMove, 160]
[PenSetColor, r(0), g(0), b(0)]
[PaintRect, 20, 20]
[PenSetColor, r(1), g(1), b(1)]
[PaintRect, 20, 20]
[PenSetColor, r(2), g(2), b(2)]
[PaintRect, 20, 20]
, , , shift+alt+'T'
]
I know I could have made this shorter by not using array variables, but I thought it would give me practice with a few extra commands, and anyway makes it easier to see what is going on - never a bad thing in my experience. They, however, were not what gave me difficulties; displaying the results did. I have three problems with this script, the first two obviously closely related and possibly indicating something I don't know about the PaintRect command:
1. When the button is first pressed, the colour swatch appears, but only displays approximately the bottom quarter of the squares. However, if I then Alt-Tab to switch windows to my text editor then straight back again to ZBrush, the 20x20 squares are now displayed in full.
2. On changing the main colour and pressing again, either just the bottom quarter or so of the new swatch similarly appears (overwriting the bottom of the original swatch), or more often nothing appears to change at all until I leave the ZBrush window then return to it, when either way once again the new triadic swatch appears perfectly overwriting the previous version as intended.
3. Finally, my original intention had been to display the colour swatch just to the right of the button with the tops of the button and the swatch aligned. No combination of pen movements that I was able to come up with achieved this, hence I settled in the end for what you see here - a vertical displacement as well as a horizontal one.
Any help with either the strange screen-refresh problem or my failure to understand the pen movements properly will be greatly appreciated. I feel really stupid at having so many problems with such a simple script, but then again it is my first attempt so please be kind.
In case it matters, I'm on a PC running Windows 98 SE.