Page 1 of 1
Squares within squares make for strange borders
Posted: Mon Mar 09, 2009 12:33 pm
by Weisshaupt
This:
Code: Select all
rule B {
SQUARE { s 20 1 }
SQUARE { x -2.5 s 10 1 b .5 }
SQUARE { x -2.5 s 7 1 b .7 }
SQUARE { x -2.5 s 2.5 1 b 1 }
}
Produces this image:
Making a square within a square and shrinking it only x-wise seems to shrink it a pixel or so y-wise.
This makes for unsightly banding and moire artifacts, like with this code:
Code: Select all
startshape A
rule A {
50* { y 0.4 r -0.9 } B { }
}
rule B {
SQUARE { s 20 1 }
SQUARE { x -2.5 s 10 1 b .5 }
SQUARE { x -2.5 s 7 1 b .7 }
SQUARE { x -2.5 s 2.5 1 b 1 }
}
Which produces this:
Anyone have any thoughts on how I work around this?
Posted: Mon Mar 09, 2009 1:23 pm
by MtnViewJohn
This is caused by anti-aliasing of the edges of the squares. In addition to all of the opaque black, gray, and white pixels that you are drawing there are translucent pixels at the edges of the squares. If you draw a translucent white pixel on top of a gray pixel you get gray, not white. This code will show you what happens when the edges of these four squares stack on top of each other:
Code: Select all
startshape foo
rule foo {
SQUARE {a -0.5 b 0}
SQUARE {a -0.5 b 0.5}
SQUARE {a -0.5 b 0.7}
SQUARE {a -0.5 b 1}
}
The solution is to use seven non-overlapping squares instead of four overlapping squares.
Posted: Mon Mar 09, 2009 3:29 pm
by Weisshaupt
MtnViewJohn wrote:This is caused by anti-aliasing of the edges of the squares. In addition to all of the opaque black, gray, and white pixels that you are drawing there are translucent pixels at the edges of the squares. If you draw a translucent white pixel on top of a gray pixel you get gray, not white. This code will show you what happens when the edges of these four squares stack on top of each other:
Code: Select all
startshape foo
rule foo {
SQUARE {a -0.5 b 0}
SQUARE {a -0.5 b 0.5}
SQUARE {a -0.5 b 0.7}
SQUARE {a -0.5 b 1}
}
The solution is to use seven non-overlapping squares instead of four overlapping squares.
Thanks, that worked much better.
edge pixels
Posted: Wed Mar 11, 2009 12:01 am
by kipling
There are other strategies. For instance, you can force the drawing order so that all the blacks get laid down first, then greys, then whites. The "z" attribute is your friend here:
Code: Select all
startshape A
rule A {
50* { y 0.4 r -0.9 } B { }
}
rule B {
SQUARE { s 20 1 }
SQUARE { x -2.5 s 10 1 b .5 z 1 }
SQUARE { x -2.5 s 7 1 b .7 z 2 }
SQUARE { x -2.5 s 2.5 1 b 1 z 3 }
}
Re: edge pixels
Posted: Wed Mar 11, 2009 3:21 am
by Weisshaupt
kipling wrote:There are other strategies. For instance, you can force the drawing order so that all the blacks get laid down first, then greys, then whites. The "z" attribute is your friend here:
Code: Select all
startshape A
rule A {
50* { y 0.4 r -0.9 } B { }
}
rule B {
SQUARE { s 20 1 }
SQUARE { x -2.5 s 10 1 b .5 z 1 }
SQUARE { x -2.5 s 7 1 b .7 z 2 }
SQUARE { x -2.5 s 2.5 1 b 1 z 3 }
}
Actually, you're still going to have trouble there. Try calling B {} just once and you'll see it looks exactly like my first picture.
The key here is to scale them y-wise just slightly.