Vai al contenuto

Freccia

  • Senza categoria

2013-03: Graphical 2

Write a program with an arrow that rotates to always point towards the mouse.

Scrivi un programma con una freccia rivolta sempre verso il puntatore del mouse


Soluzione

Da revisionare

La freccia segue il puntatore del mouse

GraphicsWindow.BackgroundColor="black"
GraphicsWindow.PenColor="blue"
GraphicsWindow.BrushColor="blue"
GraphicsWindow.PenWidth=5
xc=GraphicsWindow.Width/2
yc=GraphicsWindow.Height/2
GraphicsWindow.MouseMove=OnMouseMove
angoloFreccia=5/6*Math.Pi
baseFreccia=30

Sub OnMouseMove 
   xm=GraphicsWindow.MouseX
   ym=GraphicsWindow.MouseY
   dx=xm-xc
   dy=ym-yc
   angolo=Math.arctan(-dy/dx) 
   If(dx >= 0) Then
      c1=xm+baseFreccia*Math.Cos(angolo+angoloFreccia)
      s1=ym-baseFreccia*Math.Sin(angolo+angoloFreccia)
      s2=xm+baseFreccia*Math.Cos(angolo-angoloFreccia)
      s2=ym-baseFreccia*Math.Sin(angolo-angoloFreccia)
   Else 
      c1=xm-baseFreccia*Math.Cos(angolo+angoloFreccia)
      s1=ym+baseFreccia*Math.Sin(angolo+angoloFreccia)
      c2=xm-baseFreccia*Math.Cos(angolo-angoloFreccia)
      s2=ym+baseFreccia*Math.Sin(angolo-angoloFreccia) 
   EndIf
   GraphicsWindow.Clear()
   GraphicsWindow.DrawLine(xc,yc,xm,ym)
   GraphicsWindow.DrawTriangle(c1,s1,c2,s2,xm,ym)
   Program.Delay(50)
EndSub

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.