How to draw a line that changes

This is the simplest version of what I am trying to do. I want to use mouseX or data from serial to control where on a PImage a line is drawn, I want the line to change location and I only want one line visible. What I have now just keeps adding lines to the PImage until its a solid.

import shapes3d.utils.*;
import shapes3d.animation.*;
import shapes3d.*;


import processing.opengl.*;





PImage original;

PGraphics texture;

Ellipsoid starBall;

//float zoom = 0.5;
float zoom = 0.8;
//float zoom = 1.5;
 float y, delta_y; 





public void setup() {

  size(1275, 750, P3D);
   hint(DISABLE_DEPTH_TEST);
  //  hint(ENABLE_DEPTH_TEST);

  original = loadImage("alphatest.png");
  texture = createGraphics(original.width, original.height); 

  starBall = new Ellipsoid(this, 64, 64);
  starBall.setTexture(texture);
  starBall.setRadius(401);
  starBall.drawMode(Shape3D.TEXTURE);








noLoop(); 
}







public void draw() {



  background(0,0,0);  

  translate(width/2, height/2); 
  stroke(0, 255, 0);

  strokeWeight(2);
 y = map(radians(y),radians(mouseX),radians(texture.width),texture.height/2,texture.height - texture.height);


  texture.beginDraw();
  texture.image(original,0,0);

  texture.stroke(0,255,0);
  texture.strokeWeight(2);


  texture.line(0,y,texture.width,y); 
  texture.endDraw();







  scale(zoom, -zoom, zoom);

  y += delta_y;



  rotateZ(radians(90-53.5933333f));
  rotateX(radians(41.17/2));
  starBall.draw();


  }           

void mousePressed() {
  if (mouseX < width/2){

   delta_y = 0.00; 
   delta_y += 0.03;
  }
    if (mouseX > width/2){
   delta_y = 0.00;   
   delta_y -= 0.03;
  }
  redraw();
}
Tagged:

Answers

  • Answer ✓

    What is original? Does it contain a solid color, or is it transparent?

    It sounds like you just want to call texture.background() before drawing the next frame.

  • original is PImage that's just a transparent .png. I can give the code that makes a transparent image, found in the archives somewhere.

    I just tried it, thank you @KevinWorkman, awesome. The only hangup is depth of the image, about half gets blacked out. I ran into a similar issue before and is why I have thehint(DISABLE_DEPTH_TEST);

  • Thanks again, @KevinWorkman. No depth problems now. I used texture.background(original); instead of just (0,0,0) and all is visible and the

Sign In or Register to comment.