rendering to 1000x1000 produces white image

If you're having trouble using Context Free or don't understand the language, ask for help here.

Moderators: MtnViewJohn, chris, mtnviewmark

Post Reply
momo
Posts: 53
Joined: Tue Jul 19, 2005 5:08 am

rendering to 1000x1000 produces white image

Post by momo »

i have been looking into this one and i really don't know why i'm getting a white image when i render to 1000x1000.

Rendering to 500x500 produces the image as expected. I tryed to disable the color and brightness rules, but i still get a white image on 1000x1000.

The cfdg file is:

Code: Select all

startshape SCENE { color }

rule SCENE {
   ASHAPE { }
   SCENE { x -0.25 y -0.25 s 0.5 alpha -0.2}
   SCENE { x -0.25 y 0.25  s 0.5 alpha -0.2}
   SCENE { x 0.25 y 0.25 s 0.5 alpha -0.2}
   SCENE { x 0.25 y -0.25 s 0.5 alpha -0.2}
}

rule SCENE {
   ASHAPE { }
   SCENE { x -0.25 y -0.25 s 0.5 alpha -0.1}
   SCENE { x -0.25 y 0.25  s 0.5 alpha -0.1}
   SCENE { x 0.25 y 0.25 s 0.5 alpha 0.05}
   SCENE { x 0.25 y -0.25 s 0.5 alpha -0.01}
}

rule ASHAPE { BSHAPE{hue 100}}
rule ASHAPE { BSHAPE{hue 110}}
rule ASHAPE { BSHAPE{hue 120}}
rule ASHAPE { BSHAPE{hue 130}}
rule ASHAPE { BSHAPE{hue 140}}
rule ASHAPE { BSHAPE{hue 150}}

rule BSHAPE 0.05 { CSHAPE{sat 0}}
rule BSHAPE { CSHAPE{sat 0.7}}
rule BSHAPE { CSHAPE{sat 0.8}}
rule BSHAPE { CSHAPE{sat 0.9}}
rule BSHAPE { CSHAPE{sat 1}}
rule BSHAPE 0.05 { CSHAPE{sat -0.4}}
rule BSHAPE 0.05 { CSHAPE{sat -0.5}}

rule CSHAPE { DSHAPE {}}
rule CSHAPE { DSHAPE{alpha -0.7}}
rule CSHAPE { DSHAPE{alpha -0.8}}
rule CSHAPE { DSHAPE{alpha -0.9}}
rule CSHPAE { DSHAPE{alpha 0.5}}

rule DSHAPE { ESHAPE{s 1 0.8} }
rule DSHAPE { ESHAPE{s 0.8 1} }
rule DSHAPE { ESHAPE{s 0.9 0.5} }
rule DSHAPE { ESHAPE{s 0.8 0.7} }
rule DSHAPE { ESHAPE{s 0.8 0.9} }
rule DSHAPE { ESHAPE{s 0.7 1} }

rule ESHAPE 0.05 { FSHAPE{b 0}}
rule ESHAPE 0.09 { FSHAPE{b 0.2}}
rule ESHAPE { FSHAPE{b 0.4}}
rule ESHAPE { FSHAPE{b 0.6}}
rule ESHAPE 0.05 { FSHAPE{b 1}}

rule FSHAPE { GSHAPE { r 3 }}
rule FSHAPE { GSHAPE { r -3 }}
rule FSHAPE { GSHAPE { r 1 }}
rule FSHAPE { GSHAPE { r -1 }}
rule FSHAPE { GSHAPE { r 90 }}
rule FSHAPE { GSHAPE { r -90 }}
rule FSHAPE { GSHAPE { }}

rule GSHAPE { SQUARE { }} 
help will be apreciated since i would like to render this one to a larger file for printing.

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

Post by MtnViewJohn »

You are running out of virtual memory. Because of the algorithm that Context Free uses to evaluate your rules it tends to leave 10s of millions of rules sitting in a queue, waiting to be evaluated. Context Free evealuates a rule and puts all the squares, circles, and triangles in the finished shapes list and everything else in the unfinished shapes list. The unfinished shapes list is a queue. But every once and a while Context Free sorts the queue to bring the biggest shapes to the front.

The queue-with-sorting algorithm is fine for evaluating your SCENE rules, but it is terrible for evaluating your xSHAPE rules. A better algorithm would evaluate the ASHAPE to a BSHAPE to a CSHAPE ... to a GSHAPE to a SQUARE before getting the next unfinished shape. But instead the ASHAPE gets put in the queue. When it gets to the front it causes a BSHAPE to be put in the queue. This means the queue gets clogged with huge numbers of xSHAPE rules. Disabling sorting helps, although I don't know why. I was able to produce this after two hours of rendering without sorting: Image I thought that changing the unfinished shapes list from a queue to a stack would fix the problem, but it broke the size based stopping rule and resulted in infinite recursion.

I can think of a number of ways to fix this cfdg file:
  1. In this case it would be nice to have a random number syntax like 'hue 100:150' to set the hue to a random number between 100 and 150. This would work fine for color changes, but size and rotation changes are computed at parse time, not render time, so this would be hard.
  2. Some sort of hint like

    Code: Select all

    rule SCENE {
       *ASHAPE { }
       SCENE { x -0.25 y -0.25 s 0.5 alpha -0.2}
       ...
    that tells Context Free to evaluate ASHAPE sooner, rather than later.
  3. Fix whatever is broken with stack-ordered evaluation and let the user choose the evaluation algorithm.

momo
Posts: 53
Joined: Tue Jul 19, 2005 5:08 am

Post by momo »

thanks for your help MtnViewJohn, now i see why my code was displaying a white image.

Anyway, i don't know how will help the random number syntax you proposed, as i understand the color, size and rotation does not affect the unfinished shapes queue.

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

Post by MtnViewJohn »

A random syntax would allow you to eliminate all of the xSHAPE rules that are clogging up the unfinished shapes queue. Your code would look like this:

Code: Select all

rule SCENE {
   SQUARE { hue <100:150> sat <-0.5:1> b <0:1> alpha <-0.9:0.5> s <0.7:1> <0.5:1> r <-3:3> }
   SCENE { x -0.25 y -0.25 s 0.5 alpha -0.2}
   ...
But this would be very hard and it is a point solution for your problem.

I fixed the stack-ordered shape expansion code and it was able to generate a 1000x1000 image in 3 minutes on my 1.8GHz Pentium M. The unfinished shape stack never had more than 25 shapes in it, down from ~10 million in the queue-ordered case. I think that giving people the ability to use the stack-ordered expansion algorithm might be a good feature to add to CFDG/Context Free. But it is very easy to get in an infinite loop with the stack algorithm, so we will need to put in some safeguards.

Post Reply