简体   繁体   English

我不明白为什么我的线要倾斜

[英]I don't understand why my line is going at an angle

I am in this AP class in highschool and we are using the program JAVA or OOP, I don't even know what it is. 我在高中的AP课程中,我们正在使用程序JAVA或OOP,我什至不知道它是什么。 In the class we don't have a teacher so we basically have to self teach our self from a packet. 在课堂上我们没有老师,所以我们基本上必须从小包中自我学习。 I am learning how to draw a face and i am kind off struggling. 我正在学习如何画脸,我很努力。

Well first off, the prompt here- http://mrlanda.com/ecs/unit%205/Happy%20Face.htm 好了第一关,提示这里- http://mrlanda.com/ecs/unit%205/Happy%20Face.htm

Look at the picture below to see how it looks like. 看下面的图片,看看它的样子。

MY QUESTION-- Well here is what i got so far and it is stressing me out so much, I DON'T KNOW WHY BUT MY LINE KEEPS GOING IN AN ANGLE. 我的问题-好吧,这是我到目前为止所取得的成就,它使我感到非常压力,我不知道为什么我的线保持倾斜。 Why does it go in an angle when I am not telling it too.. I am also having a problem with the nose i can't seem to find the spot i want to put it at it keeps going into an angle for some reason. 当我也没有告诉它时,为什么它会倾斜呢。我的鼻子也有问题,我似乎找不到我想要放置的位置,由于某种原因,它一直在倾斜。

My code so far 到目前为止我的代码

import apcslib.*; 
public class DrawSquare 
{ 
    public static void main(String[] args) 
    { 
        DrawingTool marker; 
        SketchPad poster; 

        poster= new SketchPad(600,600); 
        marker= new DrawingTool(poster); 

        //left side of box
        marker.up(); 
        marker.move(0,0); 
        marker.down(); 
        marker.turnRight(180); 
        marker.forward(200); 

        //mouth
        marker.up(); 
        marker.move(40,60); 
        marker.down(); 
        marker.turnRight(90); 
        marker.forward(100); 

        //nose
        marker.up(); 
        marker.move(100,100); 
        marker.down(); 
        marker.turnRight(90); 
        marker.forward(100); 

    }
}    

According to the API docs for DrawingTool the method move(double, double) changes the direction of your drawing tool. 根据DrawingTool的API文档,方法move(double, double)更改了绘图工具的方向。

Hence if you perform the move to (40,60) from the endpoint (-200,0) of your previous forward move your new direction vector will be (240,60) . 因此,如果你执行移动到(40,60)从端点(-200,0)你以前的forward移动你的新的方向向量会(240,60) When rotating this by 90 degrees you will head in direction of (60,-240) . 将其旋转90度时,您将朝(60,-240)方向前进。

I've made a sketch showing the behaviour (not exactly to scale - I hope I haven't mixed coordinates)... 我已经绘制了一个显示行为的草图(不完全是按比例绘制的-我希望我没有混合坐标)...

这就是你想要的

So you have the following options to fix this: 因此,您可以使用以下选项来解决此问题:

  1. instead moving to (40,60) directly you could move to a temporary point before forcing the move to have your desired direction: 而是直接移动到(40,60) ,您可以在强制移动达到所需方向之前移动到临时点:

     // mouth marker.up(); marker.move(40,50); marker.move(40,60); // now you have direction "up" marker.down(); marker.forward(100); 
  2. or you could just use move instead of `forward 或者您可以使用move而不是`forward

     // mouth marker.up(); marker.move(40,60); marker.down(); marker.move(40,160); // or whatever your expected target is... 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM