代码:
$p->set_graphics_option('fillcolor={rgb 0 1 0} strokecolor={rgb 1 0 0} linewidth=2');
$p->rect(100, 300, 300, 200);
$p->fill_stroke();
$p->set_graphics_option('linewidth=1 strokecolor={rgb 1 0 0} linewidth=2');
$p->rect(100, 600, 100, 100);
$p->fill_stroke();
这将渲染两个矩形,两个矩形都带有红色轮廓(描边)并填充有绿色。
问题在于,第二个矩形仍“记住”先前set_graphics_option()
调用设置的填充颜色-尽管最近的调用未定义fillcolor
。
问题:
set_graphics_option('fillcolor=none')
的东西可以绘制仅作为轮廓的第二个矩形?setcolor()
相反的命令-会取消设置当前颜色? 重要:
我想使用fill_stroke()
来渲染两个矩形。我知道我可以使用fill()
或stroke()
。
答案 0 :(得分:1)
您应该使用保存还原对其进行封装:
$p->save();
$p->set_graphics_option('fillcolor={rgb 0 1 0} strokecolor={rgb 1 0 0} linewidth=2');
$p->rect(100, 300, 300, 200);
$p->fill_stroke();
$p->restore();
$p->save();
$p->set_graphics_option('linewidth=1 strokecolor={rgb 1 0 0} linewidth=2');
$p->rect(100, 600, 100, 100);
$p->fill_stroke();
$p->restore();
当您在单个选项列表中多次设置相同的选项时,最后一个赢。在此示例中,您首先设置了linewidth=1
,然后设置了linewidth=2
,所以当前的线宽是2。
在重置它或相关范围停止之前,该选项始终有效。
有没有类似于set_graphics_option('fillcolor = none')的东西来绘制仅作为轮廓的第二个矩形?
当您不想填充矩形时,请改用stroke()。填充时,始终获得当前颜色。而且都不是有效的颜色。