Processing - Shape 안에 그라데이션 넣기
/ 1 min read
Table of Contents
PGraphics sourceImage;PGraphics maskImage;void setup() { size(512, 512);
// 그라데이션된 이미지 그리기 color startColor = #ff0000; color endColor = #0000ff; sourceImage = createGraphics(512, 512); sourceImage.beginDraw(); for (int i = 0; i < sourceImage.width; ++i) { color c = lerpColor(startColor, endColor, (float)i / sourceImage.width); sourceImage.stroke(c); println(sourceImage.width);
sourceImage.line(0, i, sourceImage.width, i); } sourceImage.endDraw();
// Shape 그리기 maskImage = createGraphics(512, 512); maskImage.beginDraw(); // 이 부분을 각자 원하는대로 바꿔야 한다. maskImage.triangle(30, 480, 256, 30, 480, 480); maskImage.endDraw();
// 그라데이션된 이미지에 Shape를 마스킹해서 Shape 밖의 부분은 보이지 않게 한다. sourceImage.mask(maskImage);}
void draw() { // 최종 완성된 이미지를 그린다. image(sourceImage, 0, 0);}결과물
참고
https://forum.processing.org/two/discussion/23886/masking-a-shape-with-another-shape.html