Message Boards Message Boards

1
|
1720 Views
|
4 Replies
|
6 Total Likes
View groups...
Share
Share this post:

Difficulty with Blend: how to Blend a Color with a Table of Colors?

Hello,

I'm brand new to Wolfram, and I'm struggling on one of the practice problems in the tutorial. Problem 7.7 asks : "Make a list of colors obtained by blending yellow with hues from 0 to 1 in steps of 0.05."

This seems very simple, but everything I try seems to fail:

If someone could tell me what I am doing wrong, it would be greatly appreciated!

POSTED BY: Orion Strayer
4 Replies
Posted 10 months ago

Thanks for your answers, Rohit. You consistently provide great responses here.

I was thrown off by this question, because Blend doesn't take a list as an argument. I finally figured out to run FullForm on the statement to see what was really happening. Aha! Table is just semantic sugar -- a "macro" in other programming languages. Blend doesn't really exist, either. It's now as clear as black and white -- or maybe RGBColor -- what's going on with this exercise. I increased the interval size to decrease the clutter:

FullForm[Table[Blend[{Yellow,Hue[x]}],{x,0,1,.20}]]

List [RGBColor [1., 0.5, 0.],
      RGBColor [0.8999999999999999, 1. , 0.],
      RGBColor [0.5, 1., 0.20000000000000018],
      RGBColor [0.5, 0.6999999999999997, 0.5],
      RGBColor [0.9000000000000004, 0.5, 0.5],
      RGBColor [1., 0.5, 0. ]]

The two takeaways I got from this:

Any sort of assumptions you have mapping other languages onto the Wolfram Language are probably wrong. The WL is a different beast.

I do not understand all the ways that mappings work in this language. Once I do, I may be on my way to being a WL Wizard. Going through many exercises is quite valuable. Stephen's "Elementary Introduction [...]" is my new favorite tutorial.

POSTED BY: Phil Earnhardt
Posted 10 months ago

Hi Phil,

You are welcome.

Table is just semantic sugar -- a "macro" in other programming languages. Blend doesn't really exist, either.

Actually, it is not semantic sugar and they both do exist as functions (pattern -> replacement). The reason they do not appear in the FullForm is that its argument has been evaluated before passing it to FullForm. It does not hold its arguments

Attributes@FullForm
(* {Protected} *)

So it is the FullForm of the evaluated expression.

1 + 1 // FullForm
(* 2 *)

1 + 1 // Hold // FullForm
(* Hold[Plus[1, 1]] *)

At its core, the WL is a term rewriting system. Watch the 3 video presentations by Professor Richard J. Gaylord for an overview of how WL uses term rewriting. This is also worth a read.

POSTED BY: Rohit Namjoshi
Posted 10 months ago

Going back to this homework exercise:

Table[Blend[{Yellow, Hue[x]}], {x, 0, 1, .20}] // Hold // FullForm

Returns:

Hold [Table [Blend [List[Yellow, Hue [x]]], List[x, 0, 1, 0.2` ]]]

Blend will take a list of 2 colors and a value x, which determines the weighting of the 2 colors to blend. I presume that providing that list with no 2nd argument gives a default blending-value of .5 -- and it's just a bug in the documentation that this one-argument option is not listed. I'll report that bug in the docs.

The real value of your comment is learning when to apply Hold to see what's going on under the hood. I see the obvious error in my interpretation of what was happening. Much more to learn! I will put those videos on my list to study, but it will take some time (and probably lots of popcorn) to get through them. Thank you again.

POSTED BY: Phil Earnhardt

Hi Orion,

You were close with Attempt 3, just misplaced parenthesis

Table[Blend[{Yellow, Hue[x]}], {x, 0, 1, 0.05}]
POSTED BY: Rohit Namjoshi
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract