I'm trying to randomly draw lines... It produces 1 line :/
It's actually drawing the same line 10 times. This is because you are resetting the RNG after every iteration. See the System.Random constructor. The default constructor sets the seed to the current system time in seconds. Because it takes less than a second to draw those lines, you are getting the same seed, and consequently the same sequence of random numbers.
Sorry to worry again. I'm implementing the cohen clipping algorithm and in order to do this, I need to be able to show the parts of the line that are outside the viewport in a different colour. Firstly, how is it possible to show objects that aren't within the viewport?
My guess is define your own "viewport" that is smaller than the screen size. Then you just need to find the intersections of each line with your viewport rectangle and draw the segments of each line in the required colour based on the start point, intersection point(s) and end point.
Don't forget to draw the rectangle to show your viewport.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform.
You can accept analytics or continue with necessary cookies only.
Learn more