Jump to content

Codelab: Rendering individual points...help?


Recommended Posts

Hi,

I'm attempting to create a "ribbon" type plug-in in CodeLab. When I say "ribbon" I mean, having two values U and V, with each ranging from 0-1 inclusive. The input values of U and V will modify the output value of X and Y, the pixel to modify.

I have all of my math in place, and Paint.NET renders the points in the right positions, but it doesn't give me the right effect when two points overlap each other.

#region UICode
int Amount1=0;    //[0,100]Slider 1 Description
int Amount2=0;    //[0,100]Slider 2 Description
int Amount3=0;    //[0,100]Slider 3 Description
#endregion

void Render(Surface dst, Surface src, Rectangle rect)
{
   //Rectangle?
   Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
   //Centers    
   long cX = (long)(((selection.Right - selection.Left) / 2)+selection.Left);
   long cY = (long)(((selection.Bottom - selection.Top) / 2)+selection.Top);
   double iR1,oR1,A1,D1; //Begin Vals (At 0)
   double iR2,oR2,A2,D2; //End vals (At 1)
   double iR,oR,An,D; //Middle Vals (At 0-1)
   double Q1,Q2,rev,p; //Quality, Quality, Revolutions, Percent
   iR1 = 100;iR2 = 40;
   oR1 = 25;oR2 = 10;
   A1 = 0;A2 = 0;
   D1 = 25;D2 = 10;
   Q1 = 360;Q2 = 100;
   //iR2 = iR1;oR2 = oR1;A2 = A1;D2 = D1;    
   rev = 1;
   ColorBgra col; //Color
   //Blank the cavas with visible black
   for (int y = rect.Top; y < rect.Bottom; y++)
   {
       for (int x = rect.Left; x < rect.Right; x++)
       {
           col = src[x,y];
           // TODO: Add pixel processing code here
           // Access RGBA values this way, for example:
           col.R = (byte)0;
           col.G = (byte)0;
           col.B = (byte)0;
           col.A = (byte)255;
           dst[x,y] = col;
       }
   }
   //Iterate tween   
   for (int V = 0;V <= Q2;V += 1)
   {
       p = V/Q2; //Percent tween
       An = (A2-A1)*p+A1; //Angle tween
       D = (D2-D1)*p+D1; //Distance tween
       iR = (iR2-iR1)*p+iR1; //Inside radius tween
       oR = (oR2-oR1)*p+oR1; //Outside radius tween
       //Spirograph
       for (int U = 0;U < Q1;U += 1)
       {
           double a,aa,iS,oS,iC,oC,X,Y;
           int x,y,R,G,B,A,i;
           a = U/Q1*360; //Angle tween            
           aa = (An+a)*(iR/oR); //Rotation
           iS = Math.Sin((a)*Math.PI/180);
           oS = Math.Sin((a+aa)*Math.PI/180);
           iC = Math.Cos((a)*Math.PI/180);
           oC = Math.Cos((a+aa)*Math.PI/180);
           X = iC*(iR+oR)+oC*(D);
           Y = iS*(iR+oR)+oS*(D);
           //Move center            
           x = (int)(Math.Floor(cX+X));
           y = (int)(Math.Floor(cY+Y));
           //Execute only if inside drawing area
           //if (x >= selection.Left && x < selection.Right && y >= selection.Top && y < selection.Bottom)
           {
             col = dst[x,y]; //Get color from destination
             R = col.R;
             G = col.G;
             B = col.B;
             A = col.A;

             //i = R+G*256+B*256*256+A*256*256*256;//Higher-Res
             //i += 1;
             //R = i/256/256/256;
             //G = i/256/256%256;
             //B = i/256%256;
             //A = i%256;

             //i = R+G*256+B*256*256;//Hi-Res
             //i += 1;
             //R = i/256/256;
             //G = i/256%256;
             //B = i%256;

             //i = 0;
             //R = R+1;
             //G = G+1;
             //B = B+1;
             //A = 255;

             i = 0;
             R = dst[x,y].R+1;
             G = dst[x,y].G+1;
             B = dst[x,y].B+1;
             A = 255;
             //Write back to destination
             col = ColorBgra.FromBgra(
             Utility.ClampToByte(,
             Utility.ClampToByte(G),
             Utility.ClampToByte(R),
             Utility.ClampToByte(A));
             dst[x,y] = col;
           }
       }    
   }
}

I was about to paste my CodeLab script in and I hit submit by mistake... >_>

Wii Friend Codes (PM me with yours if you use mine): Super Smash Bros. Brawl: 0087-3452-9356 Mario Kart Wii: 2234-8268-1808 Guitar Hero World Tour: 403891994256

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...