TweetFollow Us on Twitter

Color Mixer
Volume Number:4
Issue Number:4
Column Tag:Basic School

Color Mixer Creates Custom Colors

By Dave Kelly, MadTutor Editorial Board, Ontario, California

ZBasic Does Mac II Color!

Yes, that’s right! The new ZBasic version 4.01 now supports the Mac II’s full 256 colors. There is no need to restrict yourself to the 8 colors of the old Quickdraw.

To use the 256 color mode, ZBasic now provides a LONG COLOR statement. The syntax is: LONG COLOR blue%, green%, red%, [ background]. LONG COLOR is used to set the colors and grey levels for subsequent graphic commands used on the Macintosh II. The command is ignored by other Macs.

The values of blue%, green% and red% may range from 0 to 65535. They may also be represented as long integers (65535 as a long integer is -32767 as a regular integer). The colors are used in RGBColor calls to the Mac II ROM where 0 is the darkest and 65535 is the lightest.

The background variable is used as a flag to indicate if the color should be set in the foreground or in the background. A background value of 0 causes the background color to be set to the blue%, green%, red% color indicated. Subsequent LONG COLOR statements that have no background variable or background is set to other than 0 will set the foreground color. The background color will be used the next time it is needed, when the screen gets updated or is cleared with CLS.

Inside Macintosh Volume V has the new color information we need to understand how the Mac II gets its color and how to use color in your applications. Before using color you should read the User Interface chapter of Inside Macintosh Vol. V. One of the most important thing you should try do is leave the selection and choices of color in the hands of the user. The study of color and how it affects people is not well defined. One of my co-workers is color-blind and has a totally different way of looking at color than I do. If color is not used carefully it could hinder instead of help to enhance your software.

Traditionally (and on that other computer) color has been used to help distinguish different things on the screen and show relationships between items on the screen. Some colors have special significance. For example: red means stop, green means go, yellow means caution. Colors can enhance in this way, however, remember that after the user has seen the same color combinations several dozen times, the color becomes commonplace and he might still make mistakes that the color was supposed to help him avoid. In fact, the bright colors used to warn a user may actually attract him to select that color.

Inside Mac encourages you to start out the design of your program in black and white and add color as a supplement to provide extra for people who have color capability. Color use should be limited to the content area of your windows. Let the user decide what color his menus, borders, controls etc. should be. The Colorizer application and CDEV let the user select his own colors for these items. If the user selects colors for somethings then your application comes along and changes part of these colors, there might be some pretty strange color combinations left over. Many suggestions are available in Inside Mac which you should know so that your applications will be consistent and won’t conflict with the user interface.

Fig. 1 Mixing colors, in this case white!

The blue%, green%, and red% that you specify in the LONG COLOR is used by the Color Manager to return the pixel value that best represents that color. The Color Manager searches through the color table for the RGB color that most closely matched the desired color. Color Quickdraw then places that color on the screen. The way that each pixel is assigned a color to display is by way of the Color Look-Up Table (CLUT). The video card takes each pixel and compares it to the CLUT to determine which RGB value that pixel represents. The RGB value is split off into three separate electrical signals (red, green, and blue) to the video monitor. By the way, when red=green=blue you get shades of gray. By using the Palette Manager (if you could from Basic) you could change the drawing environment to use a different palette.

Color Selection

Color Selection routines have been provided to the Macintosh II by Apple via the Color Picker routines. Here is the problem: ZBasic doesn’t support all the new calls for the Mac II yet. Zedcor has promised to send me format and structure information to add more calls to ZBasic as required, but Andy Gariepy has been to busy to send it to me. So that being the case I have no choice but to write my own color selection routines. Also the Color Picker is PACK_12 in system 4.2. I’m not sure it would be that easy to call a PACKage from ZBasic without it being defined by the language itself. Maybe we will have to wait for Zedcor to implement it. In the mean time I have made my own “quick and dirty” version of a “Color Picker”.

If you think about it, the Apple Color Picker routine really does do a lot! It allows you to type in the red, green, blue colors, but also will adjust these colors when you set the hue, saturation, and brightness. Proper adjustment of the red, green, and blue will result in the same hues, saturation, and brightness, but it just isn’t as convenient to setup.

The color wheel concept is interesting too. You can learn a lot about how colors can be mixed by watching the values of red, green, and blue while moving the mouse around the color wheel. Move more towards blue and watch how the numbers change! Amazing! The color wheel really is a good way to allow you to select colors. The only other good approach is to allow the user to pick from a color palette. The problem is how to decide which colors are defined in the palette.

My example suggests a simple way that colors could be selected by the user. By choosing the Pick Colors menu or button you are given a set of 3 scroll bars to adjust the amount of blue, green, and red. You can mix the amount of each color and see the effect of mixing each. This might even be useful for showing young children the effects of mixing colors. If you like the color then click on OK or else cancel to return to the original color setting.

The problem with my Color Selection demo is that because of the way ZBasic does event trapping it is difficult to make the routines be stand alone. My color mixer program provided here must become an integral part of the application because of the way that ZBasic “automatically” generates the event loop. I tried using separate ON DIALOG GOSUB traps, but it somehow didn’t work. I could only get one of the ON DIALOG statements to take effect.

There are a few problems that have shown up with my early version of ZBasic 4.01. First, the scroll bars don’t scroll properly when using the max and min values that are given in the ZBasic manual. If +32767 is used and you scroll to the right (or down) by clicking on the right (or down) arrow, when the bar reaches the max it will jump to the minimum! Also if you change the max value to between 32100 and 32766 and click in the scroll bar between the arrow and box, when the max is reached it also jumps down to the minimum. UGH! And if -32768 is used for the minimum the scroll bar returns a 0 when the box is set at the minimum. -32767 works fine. I am forced to adjust these values in the program, but it won’t matter much because the selected color will likely be the same anyway because we only have 256 possible.

Hierarchical Menu Notes

Using Hierarchical menus isn’t so simple with ZBasic. Hierarchical menus are stored as resources of the type MENU just as other menus may be stored. However, to use MENU resources with ZBasic AND have ZBasic be able to use them, you have to set up your own event loop using GETNEXTEVENT. Then you have to handle each event with the standard Macintosh way of programming and can’t use ZBasic’s event trapping routines (they get in the way). What we need is a way to use MENU, WINDOW, CONTROLs and other resources from ZBasic which can be invoked with ZBasic statements (which are integrated in with the ZBasic “automatic” event loop. It would also be useful to be able to automatically install a resource into an application when ZBasic compiles as an application. Maybe Zedcor can put these things on their “THINGS TO DO” list for version 4.02?

A submenu is associated with a menu item by using 2 fields of the MenuInfo data structure. When the itemCmd field is set to hex $1B, the itemMark field should contain the menuID (in hex) of the associated hierarchical menu. These values can be created/modified with ResEdit 1.1B3.

By using Menu Manager calls (pg. E-181 in ZBasic manual) you can find out which menu is selected in the GETNEXTEVENT loop as you would with regular type menus. More on this in a future column.

{1}
‘Professor Mac’s ZBasic Color Mixer
‘©MacTutor 1988
‘By Dave Kelly

WINDOW OFF
COORDINATE WINDOW
DIM Colorbox%(3)
red&=0
blue&=0
green&=0

DEF MOUSE=-1
false=0:true=NOT(false)
MENU 1,0,1,”File”
MENU 1,1,1,”Select Color”
MENU 1,2,1,”Quit”
EDIT MENU 2

‘Find out screen size.
CALL GETWMGRPORT(WMgrPort&)
PortTop=PEEK WORD(WMgrPort&+8)
PortLeft=PEEK WORD(WMgrPort&+10)
PortBottom=PEEK WORD(WMgrPort&+12)
PortRight=PEEK WORD(WMgrPort&+14)

WINDOW 1,”Main Window”,(10,44)-(PortRight-4,PortBottom-4)
TEXT ,,,0
BUTTON #6,1,”Quit”,(20,WINDOW(3)-50)-(85,                      
 WINDOW(3)-30),1
BUTTON #7,1,”Pick Color”,(120,WINDOW(3)-50)-(195,              
 WINDOW(3)-30),1
CALL SETRECT(Colorbox%(0),10,10,WINDOW(2)-10,                  
 WINDOW(3)-215)
PICTURE ON
LONG COLOR blue&,green&,red&
CALL PAINTRECT(Colorbox%(0))
CALL MOVETO(20,WINDOW(3)-100)
COLOR=7
PRINT “Blue:”;blue&;” Red:”;red&;” Green:”;green&;SPACE$(10)
PICTURE OFF,Pic1&
PICTURE, Pic1&
WINDOW PICTURE #1,Pic1&

ON DIALOG GOSUB “Event”
ON MENU GOSUB “MenuEvent”
DIALOG ON:MENU ON
“Loop”
GOTO “Loop”
DIALOG STOP:MENU STOP

“MenuEvent”
Menunumber=MENU(0)
Menuitem=MENU(1)
MENU
IF Menunumber<>1 THEN RETURN
SELECT Menuitem
 CASE 1
 GOSUB “ColorPick”
 CASE 2
 GOSUB “Quit”
END SELECT
RETURN

“Quit”
WINDOW PICTURE #1,0
KILL PICTURE Pic1&
END

“ColorPick”:’A Color Selection routine
done=false
min%=-32767:’Manual says that -32768 is Min. max%=32766:’Manual says 
that 32767 is Max. 
currentred&=red&
currentblue&=blue&
currentgreen&=green&
WINDOW 5,”Color Chooser”,(PortLeft+10,PortTop+30)-             (PortRight-10, 
PortBottom-10),-2
SCROLL BUTTON #1,currentblue&-32767,min%,max%,100,(20,
 WINDOW(3)-200)-(WINDOW(2)-20,WINDOW(3)-200+16),0
SCROLL BUTTON #2,currentgreen&-32767, min%, max%, 100,         (20, WINDOW(3)-150)-(WINDOW(2)-20, 
WINDOW(3)-150+16),0
SCROLL BUTTON #3,currentred&-32767, min%, max%, 100, (20,      
 WINDOW(3)-100)-(WINDOW(2)-20,WINDOW(3)-100+16),0
BUTTON #4,1,”OK”,(20,WINDOW(3)-50)-(85,WINDOW(3)-30),1
BUTTON #5,1,”Cancel”,(120,WINDOW(3)-50)-(185,                  
 WINDOW(3)-30),1
TEXT 0,12,0,0
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-200+30)
String$=”Blue: “+STR$(currentblue&)
COLOR=4
CALL DRAWSTRING(String$)
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-150+30)
String$=”Green: “+STR$(currentgreen&)
COLOR=2
CALL DRAWSTRING(String$)
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-100+30)
String$=”Red: “+STR$(currentred&)
COLOR=6
CALL DRAWSTRING(String$)
GOSUB “UpdateColorBox”
FLUSHEVENTS
RETURN

“ButtonEvent”
Buttonnumber=DIALOG(1)
Buttonvalue&=BUTTON(Buttonnumber)+32767
SELECT Buttonnumber
 CASE 1
 GOSUB “Button1”:’set blue
 CASE 2
 GOSUB “Button2”:’set green
 CASE 3
 GOSUB “Button3”:’set red
 CASE 4
 GOSUB “Button4”:’ OK button was pressed
 CASE 5
 GOSUB “Button5”:’ Cancel button was pressed
 CASE 6
 GOSUB “Quit”
 CASE 7
 GOSUB “ColorPick”
END SELECT
RETURN

“UpdateColorBox”
LONG COLOR currentblue&,currentgreen&,currentred&
CALL SETRECT(Colorbox%(0),10,10,WINDOW(2)-10,                  
 WINDOW(3)-215)
CALL PAINTRECT(Colorbox%(0))
RETURN

“Button1”:’blue scroll bar
currentblue&=Buttonvalue&
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-200+30)
String$=”Blue: “+STR$(currentblue&)+SPACE$(10)
COLOR=4:’set text color to blue
CALL DRAWSTRING(String$)
GOSUB “UpdateColorBox”
RETURN

“Button2”:’green scroll bar
currentgreen&=Buttonvalue&
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-150+30)
String$=”Green: “+STR$(currentgreen&)+SPACE$(10)
COLOR=2:’set text color to green
CALL DRAWSTRING(String$)
GOSUB “UpdateColorBox”
RETURN

“Button3”:’red scroll bar
currentred&=Buttonvalue&
CALL MOVETO(WINDOW(2)/2,WINDOW(3)-100+30)
String$=”Red: “+STR$(currentred&)+SPACE$(10)
COLOR=6:’set text color to red
CALL DRAWSTRING(String$)
GOSUB “UpdateColorBox”
RETURN

“Button4”:’OK button
red&=currentred&
blue&=currentblue&
green&=currentgreen&
GOSUB “Closestuff”
RETURN

“Button5”:’Cancel button
GOSUB “Closestuff”
RETURN

“Closestuff”
FOR J=1 TO 5
 BUTTON CLOSE J
NEXT J
WINDOW CLOSE 5
PICTURE ON
LONG COLOR blue&,green&,red&
CALL PAINTRECT(Colorbox%(0))
CALL MOVETO(20,WINDOW(3)-100)
COLOR=7
PRINT “Blue:”;blue&;” Red:”;red&;” Green:”;green&;SPACE$(10)
PICTURE OFF,Pic1&
PICTURE, Pic1&
WINDOW PICTURE #1,Pic1&
RETURN

“Event”
D=DIALOG(0)
SELECT D
 CASE 1
 GOSUB “ButtonEvent”
 CASE 4
 GOSUB “Quit”:’if close box selected
END SELECT
RETURN

Hypercard Tidbits

At MacWorld Expo in San Francisco someone asked if we knew a way to effectively mask out the command-option keys in HyperCard. The following information was given in WINOID issue #1, a newsletter for the Apple HyperCard Users Group. I hope that this will answer your question.

How can I hide buttons from command-option key peek?

When you don’t want people peeking at your buttons, it is necessary to trap the command and option keys. While there are several ways of doing this, here is one that is simple and works about 99% of the time.

The basic idea is to take the user to another card when the command and option keys are both pressed. This can be a “no peeking” card or a rules card or some other kind of card. When the user releases both keys, you then return to the card the user was viewing before trying to peek. Following are the two scripts that accomplish this. Put the top one in your stack script and the other in the “no peeking” card script.

For the stack script:

{2}
On Idle
  if the commandkey is down and the optionkey is down then
      push this card
      go card “no peeking”
  end if
end Idle

For the “no peeking” card script:

On Idle
  if the commandkey is up and the optionkey is up then
      pop card
  end if
End Idle
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Fresh From the Land Down Under – The Tou...
After a two week hiatus, we are back with another episode of The TouchArcade Show. Eli is fresh off his trip to Australia, which according to him is very similar to America but more upside down. Also kangaroos all over. Other topics this week... | Read more »
TouchArcade Game of the Week: ‘Dungeon T...
I’m a little conflicted on this week’s pick. Pretty much everyone knows the legend of Dungeon Raid, the match-3 RPG hybrid that took the world by storm way back in 2011. Everyone at the time was obsessed with it, but for whatever reason the... | Read more »
SwitchArcade Round-Up: Reviews Featuring...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for July 19th, 2024. In today’s article, we finish up the week with the unusual appearance of a review. I’ve spent my time with Hot Lap Racing, and I’m ready to give my verdict. After... | Read more »
Draknek Interview: Alan Hazelden on Thin...
Ever since I played my first release from Draknek & Friends years ago, I knew I wanted to sit down with Alan Hazelden and chat about the team, puzzle games, and much more. | Read more »
The Latest ‘Marvel Snap’ OTA Update Buff...
I don’t know about all of you, my fellow Marvel Snap (Free) players, but these days when I see a balance update I find myself clenching my… teeth and bracing for the impact to my decks. They’ve been pretty spicy of late, after all. How will the... | Read more »
‘Honkai Star Rail’ Version 2.4 “Finest D...
HoYoverse just announced the Honkai Star Rail (Free) version 2.4 “Finest Duel Under the Pristine Blue" update alongside a surprising collaboration. Honkai Star Rail 2.4 follows the 2.3 “Farewell, Penacony" update. Read about that here. | Read more »
‘Vampire Survivors+’ on Apple Arcade Wil...
Earlier this month, Apple revealed that poncle’s excellent Vampire Survivors+ () would be heading to Apple Arcade as a new App Store Great. I reached out to poncle to check in on the DLC for Vampire Survivors+ because only the first two DLCs were... | Read more »
Homerun Clash 2: Legends Derby opens for...
Since launching in 2018, Homerun Clash has performed admirably for HAEGIN, racking up 12 million players all eager to prove they could be the next baseball champions. Well, the title will soon be up for grabs again, as Homerun Clash 2: Legends... | Read more »
‘Neverness to Everness’ Is a Free To Pla...
Perfect World Games and Hotta Studio (Tower of Fantasy) announced a new free to play open world RPG in the form of Neverness to Everness a few days ago (via Gematsu). Neverness to Everness has an urban setting, and the two reveal trailers for it... | Read more »
Meditative Puzzler ‘Ouros’ Coming to iOS...
Ouros is a mediative puzzle game from developer Michael Kamm that launched on PC just a couple of months back, and today it has been revealed that the title is now heading to iOS and Android devices next month. Which is good news I say because this... | Read more »

Price Scanner via MacPrices.net

Amazon is still selling 16-inch MacBook Pros...
Prime Day in July is over, but Amazon is still selling 16-inch Apple MacBook Pros for $500-$600 off MSRP. Shipping is free. These are the lowest prices available this weekend for new 16″ Apple... Read more
Walmart continues to sell clearance 13-inch M...
Walmart continues to offer clearance, but new, Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBooks... Read more
Apple is offering steep discounts, up to $600...
Apple has standard-configuration 16″ M3 Max MacBook Pros available, Certified Refurbished, starting at $2969 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free,... Read more
Save up to $480 with these 14-inch M3 Pro/M3...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
Amazon has clearance 9th-generation WiFi iPad...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Apple is offering a $50 discount on 2nd-gener...
Apple has Certified Refurbished White and Midnight HomePods available for $249, Certified Refurbished. That’s $50 off MSRP and the lowest price currently available for a full-size Apple HomePod today... Read more
The latest MacBook Pro sale at Amazon: 16-inc...
Amazon is offering instant discounts on 16″ M3 Pro and 16″ M3 Max MacBook Pros ranging up to $400 off MSRP as part of their early July 4th sale. Shipping is free. These are the lowest prices... Read more
14-inch M3 Pro MacBook Pros with 36GB of RAM...
B&H Photo has 14″ M3 Pro MacBook Pros with 36GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 Pro MacBook Pro (... Read more
14-inch M3 MacBook Pros with 16GB of RAM on s...
B&H Photo has 14″ M3 MacBook Pros with 16GB of RAM and 512GB or 1TB SSDs in stock today and on sale for $150-$200 off Apple’s MSRP, each including free 1-2 day shipping: – 14″ M3 MacBook Pro (... Read more
Amazon is offering $170-$200 discounts on new...
Amazon is offering a $170-$200 discount on every configuration and color of Apple’s M3-powered 15″ MacBook Airs. Prices start at $1129 for models with 8GB of RAM and 256GB of storage: – 15″ M3... Read more

Jobs Board

*Apple* Systems Engineer - Chenega Corporati...
…LLC,** a **Chenega Professional Services** ' company, is looking for a ** Apple Systems Engineer** to support the Information Technology Operations and Maintenance Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
*Apple* / Mac Administrator - JAMF Pro - Ame...
Amentum is seeking an ** Apple / Mac Administrator - JAMF Pro** to provide support with the Apple Ecosystem to include hardware and software to join our team and Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.