Version 1.2 experimental color build is now available

New releases, news, and anything else important.

Moderators: MtnViewJohn, chris, mtnviewmark

Locked
User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Version 1.2 experimental color build is now available

Post by MtnViewJohn »

By popular demand, a color version of Context Free/CFDG has been put on the download page. Special thanks to aaronstj and Stephen Deken for their patches. Mark (the curmudgeon) says "Please, no garish rainbows!"

The new version is considered experimental and is put along-side version 1.1. The reason behind this is that we are not sure that the color manipulation model is right. Not that there are bugs (never!), but that the whole way of handling color may need rework. Be warned, scripts written for the experimental builds might be broken by changes made to the color model.

The documentation for color is pretty sketchy. Its just this post and what can be gleaned from welcome.cfdg and rose.cfdg. Sorry. Improved documentation is probably the next important thing to do for Context Free/CFDG.

The color model is the hue-saturation-brightness-alpha color space. In addition to the existing brightness adjustment we have added hue(h), saturation(sat), and alpha(a) adjustments. Saturation and alpha work just like brightness. Hue is like a rotation: 0 is red, 120 is green, and 240 is blue. So 'sat 0.5' moved the saturation 50% closer to 1 while 'hue 5' simply adds 5 to the hue value.

You can also set color values absolutely. For example, 'hue =180' sets the hue to cyan, and 'b =0.75' sets the brightness to 75%. Here is an example:

Code: Select all

// We have to declare the color parameter in the startshape
// or else a grayscale canvas will be created.
startshape GarishRainbow {color}

rule rainbow {
	// this draws the actual bow, as a full circle
	CIRCLE { }
	// this chops off the bottom half to make the "bow"
	SQUARE {sat =0 y -0.5}
	// rotate the color and fade to white
	rainbow {s 0.99 hue 10 sat -0.04}
}

rule GarishRainbow {
	rainbow { b 1 sat 1 }
}
You will notice that there is stuff at the end of the startshape line. This is a new piece of syntax called a parameter. The 'color' parameter tells Context Free/CFDG to create a color canvas. There is also an 'alpha' parameter that should be used when alpha is used. The current version provides color+alpha if either parameter is present. With no parameters the old 8-bit grayscale canvas is used. We felt that it was important to keep the 8-bit canvas for people who want to create very large images.

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Color Picker / Calculator

Post by MtnViewJohn »

I forgot to mention the color picker / calculator tool. This is a dialog box on the Windows and Mac clients that helps you set color values in your cfdg files. The Windows color picker and the Mac color calculator are slightly different, but we will try to harmonize their features soon. The Windows color picker is a single custom dialog while the Mac color calculator is two dialogs: the calculator dialog and the standard MacOS color picker.

The Windows color picker lets you pick a color in HSB space or pick any color on the screen using a dropper tool. You can copy either of these colors onto the clipboard, in the form of 'hue =x sat =y b =z'. Or you can copy the difference between them onto the clipboard, in the form 'hue x sat y b z'.

The Mac color calculator gives you two color swatches, either of which can be set by a color picker or by a dropper tool. It also computes the difference between the two colors. The Mac colorc calculator also lets you edit the difference fields and recomputes the final color based on the change to the difference. The Windows color picker doesn't let you do this (yet).

User avatar
MtnViewJohn
Site Admin
Posts: 882
Joined: Fri May 06, 2005 2:26 pm
Location: Mountain View, California
Contact:

Post by MtnViewJohn »

A new release of the experimental color version of Context Free is out. As you were warned, the new release will break existing color scripts because two features have been removed:
  • The '=' syntax {hue =60 b =0.75 etc}
  • The startshape parameters: startshape foo {color alpha}
The '=' syntax was taken out because it was merely convenient, but it violated the tenets of a context-free grammar, as set down by Chris. The startshape parameters were taken out because they weren't actually needed. The parser now remembers if there have been any hue, saturation, or alpha adjustments and enables a color canvas if there has been. It would have been easy to leave the parameters in and ignore them, but then if we needed to add stuff to the startshape declaration at a later date our hands would be tied.

New features:
  • A new limit syntax has been added that allows you to approach a hue, saturation, brightness, or alpha asymptotically without shooting past it.
  • A new background declaration for setting the color and alpha of the background to something other than solid white.
In addition to a current color (hue, saturation, brightness, and alpha) there is a current color limit. Color adjustments (hue -15 sat 0.3 b -0.1) work the way they did before. But now there are also color adjustments relative to the color limit:

Code: Select all

sat 0.5|    # set saturation 50% CLOSER to limit
sat -0.5|   # set saturation 50% AWAY from limit (thus towards 0 or 1 depending on the relative positions of saturation and its limit)
hue 0.5|   # set hue 50% closer to limit, in the counter-clock-wise direction
hue -0.5|  # set hue 50% closer to limit, in the clock-wise direction
Brightness and alpha work just like saturation with respect to the limit. The color limits are adjusted the same way that the color is adjusted (except that there is no color limit limit :) ):

Code: Select all

|sat 0.5    # move saturation limit 50% closer to 1
|sat -0.5   # move saturation limit 50% closer to 0
|hue 30    # add 30 to hue limit
|hue -30   # substract 30 from hue limit
The initial color limit at the startshape is the same as the initial color: opaque black (hue = 0 saturation = 0 brightness = 0 alpha = 1).

Setting the background color is pretty simple:

Code: Select all

startshape foo
background { alpha -1 }   # transparent background

or

startshape foo
background { hue -128.2 sat 0.5341 b -0.0945 }   # sky-blue background
Remember, the default background is opaque white (hue = 0 saturation = 0 brightness = 1 alpha = 1). The background color is relative to opaque white, not opaque black. This is why the sky-blue example has the color adjustment 'b -0.0945'. Using the color picker/calculator: set the start color to white, set the finish color to what you want, and copy the difference into your background declaration.

Have fun!

Locked