Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Display 360 angular cross section of an ellipse and a rectangle
- // Left click = ellipse
- // Right click = rectangle
- // Code for Processing 3
- PGraphics shapeGraphics;
- int shape = 0;
- void setup(){
- size(500, 500);
- shapeGraphics = createGraphics(1, height);
- }
- void draw(){
- // draw each x slices
- for(int i = 0; i < width; i ++){
- shapeGraphics.beginDraw();
- shapeGraphics.background(0);
- shapeGraphics.fill(128);
- shapeGraphics.stroke(0, 0);
- shapeGraphics.rectMode(RADIUS);
- // draw rotated shape
- shapeGraphics.rotate(2*PI * (float)i/width);
- drawShape(shapeGraphics, shape);
- shapeGraphics.endDraw();
- // paste drawn shape onto current context
- copy(
- shapeGraphics.get(),
- 0, 0, 1, height,
- i, 0, 1, height
- );
- }
- // draw shape for reference
- fill(0, 0);
- stroke(255);
- rectMode(RADIUS);
- drawShape(this.g, shape);
- }
- void drawShape(PGraphics context, int shape){
- if(shape == 0){
- context.ellipse(0, 0, mouseX*2, mouseY*2);
- } else {
- context.rect(0, 0, mouseX, mouseY);
- }
- }
- void mousePressed() {
- if (mouseButton == LEFT) {
- shape = 0;
- } else if (mouseButton == RIGHT) {
- shape = 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement