Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 9th, 2012  |  syntax: None  |  size: 0.97 KB  |  hits: 4  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. void setup() {
  2.   smooth();
  3.   size(542, 475, P3D);
  4.   background(255);
  5.   stroke(0);
  6.   strokeWeight(3);
  7.  
  8.   superQuad(new PVector(364.0, 235.0),
  9.             new PVector(314.0, 295.0),
  10.             new PVector(114.0, 272.0),
  11.             new PVector(169.0, 123.0));
  12. }
  13.  
  14. void superQuad(PVector a, PVector b, PVector c, PVector d) {
  15.   PGraphics pattern = generatePattern(atan(slope(a, b)));  
  16.   beginShape();  
  17.   texture(pattern);
  18.   vertex(a.x, a.y, a.x, a.y);
  19.   vertex(b.x, b.y, b.x, b.y);
  20.   vertex(c.x, c.y, c.x, c.y);
  21.   vertex(d.x, d.y, d.x, d.y);
  22.   endShape(CLOSE);
  23. }
  24.  
  25. float slope(PVector i, PVector f) {
  26.   float dy = f.y - i.y;
  27.   float dx = f.x - i.x;
  28.   return dy / dx;
  29. }
  30.  
  31. PGraphics generatePattern(float rotation) {
  32.   PGraphics pattern = createGraphics(width, height, P2D);
  33.   pattern.beginDraw();
  34.   pattern.rotate(rotation);
  35.   pattern.stroke(0);
  36.   pattern.strokeWeight(3);
  37.   for(int y = 0; y < height; y += 10) {
  38.     pattern.line(0, y, width, y);
  39.   }
  40.   pattern.endDraw();
  41.   return pattern;
  42. }