public void printPicture(PictureJson pic) { //call each array of shaps in pic and draw by type if (pic.Lines != null) { foreach (line l in pic.Lines) { drawLine(l.first, l.second); } } if (pic.Circles != null) { foreach (circle c in pic.Circles) { MyCircle((int)c.center.x, (int)c.center.y, (int)c.radius); } } if (pic.Curves != null) { foreach (curve c in pic.Curves) { DrawBazia(c); } } if (pic.Poligon != null) { foreach (poligon p in pic.Poligon) { myPoli(p); } } }
public PictureJson parseJson(string jsonString, string name) { var root = JObject.Parse(jsonString); var serializer = new JsonSerializer(); PictureJson userObject = serializer.Deserialize <PictureJson>(root.CreateReader()); return(userObject); }
public PictureJson(PictureJson other) { // Points = other.Points; Lines = other.Lines; Circles = other.Circles; Curves = other.Curves; Poligon = other.Poligon; }
public void move(double x1, double y1, double x2, double y2) { //move the entire picture from point (x1,y1) to point (x2,y2) double calculateX = x2 - x1; double calculateY = y2 - y1; picture = addValueToPictureJson(picture, calculateX, calculateY); draw(); }
public void rotate(double x, double y, double choosenX, double choosenY, double angle) { //rotate picture "angle" angles around choosen point (choosenX,choosenY) PictureJson tranform = picture; //get the angle in radians double angleInRad = angle / 180.0 * Math.PI; //pre calculate the cos and sin double cos = Math.Cos(angleInRad); double sin = Math.Sin(angleInRad); centerPoint.x = (((centerPoint.x - choosenX) * cos) - ((centerPoint.y - choosenY) * sin) + choosenX); centerPoint.y = (((centerPoint.y - choosenY) * cos) + ((centerPoint.x - choosenX) * sin) + choosenY); if (tranform.Lines != null) { for (int i = 0; i < tranform.Lines.Length; ++i) { tranform.Lines[i].first.x = (((tranform.Lines[i].first.x - choosenX) * cos) - ((tranform.Lines[i].first.y - choosenY) * sin) + choosenX); tranform.Lines[i].first.y = (((tranform.Lines[i].first.y - choosenY) * cos) + ((tranform.Lines[i].first.x - choosenX) * sin) + choosenY); tranform.Lines[i].second.x = (((tranform.Lines[i].second.x - choosenX) * cos) - ((tranform.Lines[i].second.y - choosenY) * sin) + choosenX); tranform.Lines[i].second.y = (((tranform.Lines[i].second.y - choosenY) * cos) + ((tranform.Lines[i].second.x - choosenX) * sin) + choosenY); } } if (tranform.Circles != null) { for (int i = 0; i < tranform.Circles.Length; ++i) { tranform.Circles[i].center.x = (((tranform.Circles[i].center.x - choosenX) * cos) - ((tranform.Circles[i].center.y - choosenY) * sin) + choosenX); tranform.Circles[i].center.y = (((tranform.Circles[i].center.y - choosenY) * cos) + ((tranform.Circles[i].center.x - choosenX) * sin) + choosenY); } } if (tranform.Curves != null) { for (int i = 0; i < tranform.Curves.Length; ++i) { tranform.Curves[i].first.x = (((tranform.Curves[i].first.x - choosenX) * cos) - ((tranform.Curves[i].first.y - choosenY) * sin) + choosenX); tranform.Curves[i].first.y = (((tranform.Curves[i].first.y - choosenY) * cos) + ((tranform.Curves[i].first.x - choosenX) * sin) + choosenY); tranform.Curves[i].second.x = (((tranform.Curves[i].second.x - choosenX) * cos) - ((tranform.Curves[i].second.y - choosenY) * sin) + choosenX); tranform.Curves[i].second.y = (((tranform.Curves[i].second.y - choosenY) * cos) + ((tranform.Curves[i].second.x - choosenX) * sin) + choosenY); tranform.Curves[i].thired.x = (((tranform.Curves[i].thired.x - choosenX) * cos) - ((tranform.Curves[i].thired.y - choosenY) * sin) + choosenX); tranform.Curves[i].thired.y = (((tranform.Curves[i].thired.y - choosenY) * cos) + ((tranform.Curves[i].thired.x - choosenX) * sin) + choosenY); tranform.Curves[i].fourth.x = (((tranform.Curves[i].fourth.x - choosenX) * cos) - ((tranform.Curves[i].fourth.y - choosenY) * sin) + choosenX); tranform.Curves[i].fourth.y = (((tranform.Curves[i].fourth.y - choosenY) * cos) + ((tranform.Curves[i].fourth.x - choosenX) * sin) + choosenY); } } if (tranform.Poligon != null) { for (int i = 0; i < tranform.Poligon.Length; ++i) { tranform.Poligon[i].center.x = (((tranform.Poligon[i].center.x - choosenX) * cos) - ((tranform.Poligon[i].center.y - choosenY) * sin) + choosenX); tranform.Poligon[i].center.y = (((tranform.Poligon[i].center.y - choosenY) * cos) + ((tranform.Poligon[i].center.x - choosenX) * sin) + choosenY); tranform.Poligon[i].radius.x = (((tranform.Poligon[i].radius.x - choosenX) * cos) - ((tranform.Poligon[i].radius.y - choosenY) * sin) + choosenX); tranform.Poligon[i].radius.y = (((tranform.Poligon[i].radius.y - choosenY) * cos) + ((tranform.Poligon[i].radius.x - choosenX) * sin) + choosenY); } } draw(); }
public PictureJson moveToZero(PictureJson tempPicture) { //move the entire picture to point (0,0) double calculateX = 0 - centerPoint.x; double calculateY = 0 - centerPoint.y; tempPicture = addValueToPictureJson(tempPicture, calculateX, calculateY); return(tempPicture); }
public PictureJson addValueToPictureJson(PictureJson pic, double calculateX, double calculateY) { //Add calculateX to each x and calculateY to each y to each point in the picture shaps centerPoint.x += calculateX; centerPoint.y += calculateY; if (pic.Lines != null) { for (int i = 0; i < pic.Lines.Length; ++i) { pic.Lines[i].first.x += calculateX; pic.Lines[i].first.y += calculateY; pic.Lines[i].second.x += calculateX; pic.Lines[i].second.y += calculateY; } } if (pic.Circles != null) { for (int i = 0; i < pic.Circles.Length; ++i) { pic.Circles[i].center.x += calculateX; pic.Circles[i].center.y += calculateY; } } if (pic.Curves != null) { for (int i = 0; i < pic.Curves.Length; ++i) { pic.Curves[i].first.x += calculateX; pic.Curves[i].first.y += calculateY; pic.Curves[i].second.x += calculateX; pic.Curves[i].second.y += calculateY; pic.Curves[i].thired.x += calculateX; pic.Curves[i].thired.y += calculateY; pic.Curves[i].fourth.x += calculateX; pic.Curves[i].fourth.y += calculateY; } } if (pic.Poligon != null) { for (int i = 0; i < pic.Poligon.Length; ++i) { pic.Poligon[i].center.x += calculateX; pic.Poligon[i].center.y += calculateY; pic.Poligon[i].radius.x += calculateX; pic.Poligon[i].radius.y += calculateY; } } return(pic); }
public void OpenBackGroundFile() { try { // Open the text file using a stream reader. using (StreamReader sr = new StreamReader("backgroundJsonFile.json")) { // Read the stream to a string, and write the string to the console. String line = sr.ReadToEnd(); JToken root = JObject.Parse(line); JToken pictureJson = root["pictureJson"]; backgroundPicture = JsonConvert.DeserializeObject <PictureJson>(pictureJson.ToString()); //creating PictureJson obj and setting it in the var } } catch (Exception e) { Console.WriteLine("The picture file could not be read:"); Console.WriteLine(e.Message); } }
public void scale(int newX, int newY) { PictureJson tranform = new PictureJson(picture); point refrence = centerPoint; double scaleRatio = 1.0; if (action == 3) { scaleRatio = 1.2; } else if (action == 10) { scaleRatio = 0.8; } picture = moveToZero(picture); if (picture.Lines != null) { for (int i = 0; i < picture.Lines.Length; ++i) { picture.Lines[i].first.x = picture.Lines[i].first.x * scaleRatio; picture.Lines[i].second.x = picture.Lines[i].second.x * scaleRatio; picture.Lines[i].first.y = picture.Lines[i].first.y * scaleRatio; picture.Lines[i].second.y = picture.Lines[i].second.y * scaleRatio; } } if (picture.Circles != null) { for (int i = 0; i < picture.Circles.Length; ++i) { picture.Circles[i].radius = picture.Circles[i].radius * scaleRatio; picture.Circles[i].center.x = picture.Circles[i].center.x * scaleRatio; picture.Circles[i].center.y = picture.Circles[i].center.y * scaleRatio; } } if (picture.Curves != null) { for (int i = 0; i < picture.Curves.Length; ++i) { //need to check - had no curves picture.Curves[i].first.x = picture.Curves[i].first.x * scaleRatio; picture.Curves[i].first.y = picture.Curves[i].first.y * scaleRatio; picture.Curves[i].second.x = picture.Curves[i].second.x * scaleRatio; picture.Curves[i].second.y = picture.Curves[i].second.y * scaleRatio; picture.Curves[i].thired.x = picture.Curves[i].thired.x * scaleRatio; picture.Curves[i].thired.y = picture.Curves[i].thired.y * scaleRatio; picture.Curves[i].fourth.x = picture.Curves[i].fourth.x * scaleRatio; picture.Curves[i].fourth.y = picture.Curves[i].fourth.y * scaleRatio; } } if (picture.Poligon != null) { for (int i = 0; i < picture.Poligon.Length; ++i) { picture.Poligon[i].center.x = picture.Poligon[i].center.x * scaleRatio; picture.Poligon[i].center.y = picture.Poligon[i].center.y * scaleRatio; picture.Poligon[i].radius.x = picture.Poligon[i].radius.x * scaleRatio; picture.Poligon[i].radius.y = picture.Poligon[i].radius.y * scaleRatio; } } move(centerPoint.x, centerPoint.y, refrence.x, refrence.y); draw(); }
public JObject createPictureJson(PictureJson json) { JObject jsonObject = (JObject)JToken.FromObject(json); return(jsonObject); }