Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- class Tocka {
- private double x;
- private double y;
- public Tocka(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public double getX() {
- return x;
- }
- public double getY() {
- return y;
- }
- public void setX(double x) {
- this.x = x;
- }
- public void setY(double y) {
- this.y = y;
- }
- }
- public class Naloga14 {
- static Tocka sredina(Tocka a, Tocka b) {
- return new Tocka(0.5 * (a.getX() + b.getX()), 0.5 * (a.getY() + b.getY()));
- }
- public static void main(String[] args) {
- StdDraw.setScale(0, 100);
- Tocka[] tocki = new Tocka[3];
- tocki[0] = new Tocka(10, 10);
- tocki[1] = new Tocka(90, 10);
- tocki[2] = new Tocka(50, 90);
- Random random = new Random();
- int x = random.nextInt(100);
- int y;
- if(x < 50) {
- y = 2 * x + 1;
- }
- else {
- y = 2 * (100 - x)+ 1;
- }
- Tocka tocka = new Tocka(x, y);
- for(int i = 0; i < 10000; i++) {
- int j = random.nextInt(3);
- Tocka sredisnaTocka = sredina(tocki[j], tocka);
- StdDraw.line(sredisnaTocka.getX(), sredisnaTocka.getY(), sredisnaTocka.getX(), sredisnaTocka.getY());
- tocka = sredisnaTocka;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement