Forum

Welcome Guest 

Show/Hide Header

Welcome Guest, posting in this forum requires registration.





Pages: [1]
Author Topic: Variable Density Hilbert Curve Drawing
kongorilla
Pro
Posts: 362
Permalink
kongorilla
Post Variable Density Hilbert Curve Drawing
on: February 6, 2012, 02:22
Quote

Ran across this on the Planet RepRap blog aggregator, thought it might be of interest:

http://axrap.blogspot.com/2012/02/variable-density-hilbert-curve.html

lanthan
Newbie
Posts: 22
Permalink
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 21:01
Quote

Thank you for the link! This looks very nice, I hope he will post the code.

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 21:15
Quote

It does look rather cool. Does anybody care about whether this kind of "pixel drawing" is done in the arduino rather than being generated on a PC and sent as vectors?

lanthan
Newbie
Posts: 22
Permalink
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 22:27
Quote

I do not think it is that important given the way the controller works (no possibility to graphically edit the output before sending), it could be done in the arduino...

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 22:46
Quote

Its more of an issue about code space. There is hardly any left on the arduino, so not much room to play. What I'm thinking I might do is make a server that does vectors / curves only, very general purpose, and then see if I have room to fit in code to run from SD card while being able to fit into a regular arduino uno (32K). But to do that I'd probably need to sacrifice any "patterning" kinds of features. It could still be done in software in the client, but it would run much slower because each line would be one command. On the other hand, it could be buffered to SD card beforehand. Well it'd probably have to be.

I love the idea of this machine as being something more than just another output device, it's always been my goal to give it behaviour, give it the ability to interpret data rather than just do exactly as it's told, so this does very much dilute that aspect of it. However, those functions could be included in the mega version of course. It really depends whether folk want it to be just a big plotter, or a curious machine.

lanthan
Newbie
Posts: 22
Permalink
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 23:21
Quote

I do prefer the curious machine with a mood and an attitude too (hum, as long as it doesn't start drinking heavily and seeing criters...), since by its mere structure it is more slanted to be a performance artist rather than a drawing technician.
Some scavenged code somewhere to do shading with concentric circles, found in AS220.

void drawCurve(float x, float y, float fx, float fy, float cx, float cy) {
  // Draw a Quadratic Bezier curve from (x, y) to (fx, fy) using control pt
  // (cx, cy)
  float xt=0;
  float yt=0;

  for (float t=0; t<=1; t+=.0025) {
    xt = pow((1-t),2) *x + 2*t*(1-t)*cx+ pow(t,2)*fx;
    yt = pow((1-t),2) *y + 2*t*(1-t)*cy+ pow(t,2)*fy;
    moveTo(xt, yt);
  }  
}
                                                     

void drawCircle(int centerx, int centery, int radius) {
  // Estimate a circle using 20 arc Bezier curve segments
  int segments =20;
  int angle1 = 0;
  int midpoint=0;
   
   moveTo(centerx+radius, centery);

  for (float angle2=360/segments; angle2<=360; angle2+=360/segments) {

    midpoint = angle1+(angle2-angle1)/2;

    float startx=centerx+radius*cos(rads(angle1));
    float starty=centery+radius*sin(rads(angle1));
    float endx=centerx+radius*cos(rads(angle2));
    float endy=centery+radius*sin(rads(angle2));
    
    int t1 = rads(angle1)*1000 ;
    int t2 = rads(angle2)*1000;
    int t3 = angle1;
    int t4 = angle2;

    drawCurve(startx,starty,endx,endy,
              centerx+2*(radius*cos(rads(midpoint))-.25*(radius*cos(rads(angle1)))-.25*(radius*cos(rads(angle2)))),
              centery+2*(radius*sin(rads(midpoint))-.25*(radius*sin(rads(angle1)))-.25*(radius*sin(rads(angle2))))
    );
    
    angle1=angle2;
  }

}


              
void drawCircles(int number, int centerx, int centery, int r) {
   // Draw a certain number of concentric circles at the given center with
   // radius r
   int dr=0;
   if (number > 0) {
     dr = r/number;
     for (int k=0; k<number; k++) {
       drawCircle(centerx, centery, r);
       r=r-dr;
     }
   }
}

Have you tried it? you have some circle stuff commented out in the firmware...

optimizing the polargraph as a mere plotter would require some changes to the comm protocol, maybe a queue...

how many Ks is the accelstepper library eating?

sandy
Administrator
Posts: 1317
Permalink
sandy
Post Re: Variable Density Hilbert Curve Drawing
on: February 6, 2012, 23:41
Quote

Quick measurements:

Empty sketch: 674 bytes
With AFMotor: +1284
With SD Library: +6996
With Servo: +1376
With Accel: + 3368

So yes, dropping AFMotor and Accelstepper would probably make room for the SD library, and actually I don't need the full lib, a small subset would do in a pinch, as long as you didn't mind a few hoops to jump through for setup.

Ha, I'm surprised you didn't notice that the code you saw commented out in the server is the exact code you've posted here! I did get it working ages ago, when I was very first starting, so it's pretty straightforward, but at that point it used the native coords system, so everything was distorted lozenge shapes, and my machine was made of bulldog clips and tape so it didn't get results I was that excited by. Kept meaning to restore the functions, but never did, same with sawtooth shading algorithm. That never really worked, but should, now that I can do straight lines.

lanthan
Newbie
Posts: 22
Permalink
Post Re: Variable Density Hilbert Curve Drawing
on: February 7, 2012, 00:49
Quote

Hah was just too lazy to check (it is late), but yes, it had a familiar look 😉

Pages: [1]
Mingle Forum by cartpauj
Version: 1.0.34 ; Page loaded in: 0.021 seconds.