Message Boards Message Boards


Graphics question on code in "Adventures of a Computational Explorer" book?

Posted 4 months ago
6 Replies
0 Total Likes

I have a question about the code on page 10 of Wolfram's new book "Adventures of a Computational Explorer". When I enter the code

Row[Graphics[{RandomColor[], Disk[]}, ImageSize > 5 #] & /@ %7]

I get all the disks to be the same size! ImageSize >5 has no effect? So, my question is: why are the disks in the output on page 10 all different sizes?

6 Replies

Disregard my previous statement! You are correct! I left out the "-" in the "->"!

When I input the statement in the book (allowing for the previous input number) the output has all the disks are the same size, not random sizes?

It doesn’t need RandomReal. The %7 in that statement refers to the output of the previous statement, which is a list of the decimal digits of pi. So the size of each disk is 5 times a decimal digit of pi. That’s where the randomness comes in.

Posted 4 months ago

Hi Jay,

I do not have the book, so I have no idea what %7 is. As I said in my reply "Or, use another list of numbers to specify the size e.g." I chose to use RandomReal.

I'm totally aware that one must use the Input number of the previous output, but as it is written in my copy of the book it does NOT have "RandomReal" in the input! Does your copy of the book have this in the input statement?

Posted 4 months ago

The %7 refers to the 7'th output value, Out[7]. It is usually a bad idea to reference output by number since the numbers can change depending on the order in which cells are evaluated. That is probably why it is not working as expected.You can fix it by evaluating the cells in the order they are evaluated in the book. Or, use another list of numbers to specify the size e.g.

Row[Graphics[{RandomColor[], Disk[]}, ImageSize -> 5 #] & /@ RandomReal[{1, 15}, 10]]

enter image description here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract