private void testDraw(Graphics g) { log("this is a test..."); double size = 50; int i; drawStr(g, "A", new MyPoint(size, size), (float)size * 2, Color.Black); ArrayOfPoints lines = new ArrayOfPoints(); lines.push(new MyPoint(0, 0)); lines.push(new MyPoint(size, 0)); lines.push(new MyPoint(size, size)); lines.push(new MyPoint(0, size)); lines.push(new MyPoint(0, 0)); for (i = 0; i < lines.Length - 1; i++) { drawLine(g, lines[i], lines[i + 1], Color.Red); } lines = arrayMulti(lines, 2); for (i = 0; i < lines.Length - 1; i++) { drawLine(g, lines[i], lines[i + 1], Color.Red); } }
// private ArrayOfPoints createLoop(int num) { ArrayOfPoints a = new ArrayOfPoints(); if (num < 2) { log("createLoop error num must >=2,now num:" + num); } double angle = (double)(num - 2) * Math.PI / (double)(num); // MyPoint p = new MyPoint(-1, 0); a.push(p); int i; for (i = 1; i < num; i++) { p = a[i - 1]; a.push(rotateMyPoint(new MyPoint(-p.X, -p.Y), angle)); } a[0] = new MyPoint(0, 0); for (i = 1; i < num; i++) { MyPoint tempP = a[i]; a[i] = tempP.add(a[i - 1]); } return(a); }
private ArrayOfPoints createLine(int num) { //not conatin the first one (0,0); //return a array with len of num-1 ArrayOfPoints a = new ArrayOfPoints(); for (int i = 0; i < num - 1; i++) { a.push(new MyPoint(i + 1, 0)); } return(a); }
// Summary: // Create and save the result as a file named fileName (of which the type is gif). // This should be invoked after the init(). // // Parameters: // fileName: // Just as it looks like,it is the name of file you want to save as. // // args: // A structure used to specify your own style image.Also,you can use a default // one without passing it. // Properties of Args: // size:The length between two character. // fontSize: The size of font,specified in pixel. // spaceLen:The length from the end point of line to center of corresponding // character.(spaceLen a little bit smaller than fontSize is recommended,e.g. // fontSize=10,spaceLen=8.) // basicLineColor:The color of line connected the consecutive characters. // pairLineColor:The color of line between '1' and '1'. // fontColor:The color of font. public void create(string fileName, Args args = null) { if (args == null) { args = new Args(); } //passing args.... double size = args.size; double fontSize = args.fontSize; double spaceLen = args.spaceLen; Color basicLineColor = args.basicLineColor; Color pairLineColor = args.pairLineColor; Color fontColor = args.fontColor; // log("going..."); //creating the original points base on seqs and matches ArrayOfPoints points = createPoints(seqs, matches); //generate the accurate drawPoints which will be draw on device from original points. ArrayOfPoints drawPoints = arrayMultiP(points, new MyPoint(size, -size)); RectangleF rect = arrayGetRect(drawPoints); drawPoints = arrayAdd(drawPoints, new MyPoint(-rect.Left, -rect.Top)); drawPoints = arrayAdd(drawPoints, new MyPoint(fontSize / 2, fontSize / 2)); drawPoints.push(drawPoints[drawPoints.Length - 1]); //inflate the rect to contain all the graphics,and will be used as the size of bitmap. rect.Inflate((float)fontSize, (float)fontSize); // //create a bitmap and draw graph in it Bitmap bp; Graphics g; bp = new Bitmap((int)rect.Width, (int)rect.Height, PixelFormat.Format64bppArgb); g = Graphics.FromImage(bp); g.SmoothingMode = SmoothingMode.HighQuality; ///g.InterpolationMode = InterpolationMode.HighQualityBicubic; //g.CompositingQuality = CompositingQuality.HighQuality;/**/ g.Clear(Color.White); if (isTest) { testDraw(g); } else { //now start drawing base on drawPoints,with argument specified by user. draw(g, drawPoints, spaceLen, (float)fontSize, basicLineColor, pairLineColor, fontColor); } //save the bitmap as fileName bp.Save(fileName, ImageFormat.Gif); bp.Dispose(); g.Dispose(); }
private ArrayOfPoints createSideLoop(int num) { //not contain the first one (0,0) //return a array with len of num-1 ArrayOfPoints a = new ArrayOfPoints(); switch (num) { case 2: a.push(new MyPoint(0, -1)); break; case 3: a.push(new MyPoint(Math.Sqrt(3) / 2, -0.5)); a.push(new MyPoint(0, -1)); break; case 4: a.push(new MyPoint(Math.Sqrt(3) / 2, -0.5)); a.push(new MyPoint(Math.Sqrt(3) / 2, -1.5)); a.push(new MyPoint(0, -2)); break; default: int numLen = 2 * (num - 1); ArrayOfPoints loop = createLoop(numLen); loop = loop.splice(0, 1); double angle = Math.PI * (1 - (double)(numLen - 2) / (double)numLen) / 2.0; for (int i = 0; i < loop.Length; i++) { loop[i] = rotateMyPoint(loop[i], angle); } arrayFill(loop, a, 0, num - 1); a = arrayMulti(a, -1); break; } return(a); }