Vai al contenuto

Figure casuali

Disegna dei tratti consecutivi con colore e spessore casuale

GraphicsWindow.Height=GraphicsWindow.Width
Turtle.Speed=10

SPAZIO =25
SPAZIO2=2*spazio
xm=GraphicsWindow.Width -SPAZIO2
ym=GraphicsWindow.Height-SPAZIO2

While "true"
   x=Math.GetRandomNumber(xm)+SPAZIO
   y=Math.GetRandomNumber(ym)+SPAZIO
   GraphicsWindow.PenColor=GraphicsWindow.GetRandomColor()
   GraphicsWindow.PenWidth=Math.GetRandomNumber(10)
   Turtle.MoveTo(x,y) 
   Program.Delay(500)
EndWhile

Disegna dei tratti staccati

...
While "true"
   x1=Math.GetRandomNumber(xm)+SPAZIO
   y1=Math.GetRandomNumber(ym)+SPAZIO
   x2=Math.GetRandomNumber(xm)+SPAZIO
   y2=Math.GetRandomNumber(ym)+SPAZIO
   Turtle.PenUp()
   Turtle.MoveTo(x1,y1) 
   GraphicsWindow.PenColor=GraphicsWindow.GetRandomColor()
   GraphicsWindow.PenWidth=Math.GetRandomNumber(10)
   Turtle.PenDown()
   Turtle.MoveTo(x2,y2)
   Program.Delay(500)
EndWhile

Per disegnare triangoli sono necessari

  • 3 punti
  • 6 coordinate
...
x1=Math.GetRandomNumber(xm)+SPAZIO
y1=Math.GetRandomNumber(ym)+SPAZIO
x2=Math.GetRandomNumber(xm)+SPAZIO
y2=Math.GetRandomNumber(ym)+SPAZIO
x3=Math.GetRandomNumber(xm)+SPAZIO
y3=Math.GetRandomNumber(ym)+SPAZIO
...
Turtle.MoveTo(x2,y2)
Turtle.MoveTo(x3,y3)
Turtle.MoveTo(x1,y1)
...


Rettangoli?

  • 2 punti (vertici opposti)
  • 4 coordinate
...
x1=Math.GetRandomNumber(xm)+SPAZIO
y1=Math.GetRandomNumber(ym)+SPAZIO
x2=Math.GetRandomNumber(xm)+SPAZIO
y2=Math.GetRandomNumber(ym)+SPAZIO
...
Turtle.MoveTo(x1,y2)
Turtle.MoveTo(x2,y2)
Turtle.MoveTo(x2,y1)
Turtle.MoveTo(x1,y1)
...

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.