Computer Science Canada

Fun with trig and drawfillpolygon

Author:  petree08 [ Mon Apr 07, 2008 10:35 am ]
Post subject:  Fun with trig and drawfillpolygon

I was just playing with turing's trig functions and made this
% may be useful for a paint type program


this program draws any polygon (with 1- 360 verticies)

the polygon is rotated by the mouse and the size is determined by the length of the mouse from the center of screen

Edit the number of points by changing the NUM_OF_POINTS constant

right now the program is configured for a pentagon

have fun!

code:


function Length_Find (X1, Y1, X2, Y2 : real4) : real
    result sqrt ((X1 - X2) ** 2 + (Y1 - Y2) ** 2)
end Length_Find

setscreen ("graphics:max,max,nobuttonbar,offscreenonly")
const NUM_OF_POINTS := 5
const MID_X := maxx div 2
const MID_Y := maxy div 2

var XP, YP : array 1 .. NUM_OF_POINTS of int

var XM, YM, Click : int
var Length : real4
var Angle : int2

Length := 100
Angle := 0

for I : 1 .. NUM_OF_POINTS
    XP (I) := round (cosd (I * (360 / NUM_OF_POINTS)) * Length) + MID_X
    YP (I) := round (sind (I * (360 / NUM_OF_POINTS)) * Length) + MID_Y
end for

loop
    cls
    mousewhere (XM, YM, Click)
    Length := Length_Find (MID_X, MID_Y, XM, YM)
    if (XM - MID_X) = 0 then
        if YM > MID_Y then
            Angle := 90
        else
            Angle := 270
        end if
    else
        Angle := round (arctand ((MID_Y - YM) / (MID_X - XM)))
        if XM < MID_X then

            Angle := Angle - 180

        end if
    end if
    for I : 1 .. NUM_OF_POINTS
        XP (I) := round (cosd (I * (360 / NUM_OF_POINTS) +
            Angle) * Length) + MID_X
        YP (I) := round (sind (I * (360 / NUM_OF_POINTS) +
            Angle) * Length) + MID_Y
    end for
    drawfillpolygon (XP, YP, NUM_OF_POINTS, 10)
    View.Update
end loop



Author:  repsoccer16 [ Tue Apr 08, 2008 8:03 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

amazing program...pretty cool and could be quite useful.

Author:  petree08 [ Tue Apr 08, 2008 8:10 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

I was thinking this could be useful for a paint type program. I'm sure there is a more efficient way to code this (i wrote it in like 5 minutes)

Author:  Tallguy [ Tue Apr 15, 2008 9:49 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

its really cool, but try to make the reaction time a bit faster

Author:  petree08 [ Tue Apr 15, 2008 10:14 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

wHaT dO yOU mEAn bY REaCtioN tImE?

Do you mean

- frame rate
- time required to compile
- reaction of the user

All of these are dependant on the speed of the computer. When i have this going on the crappy school computers it runs smoother than a baby's bottem

Author:  andrew. [ Fri Apr 18, 2008 9:04 pm ]
Post subject:  Re: Fun with trig and drawfillpolygon

I think he means the frame rate. I noticed that on my computer, it's a tad slow (like 0.5 FPS lag). No biggie though. It may be my OS though, I'm using Vista right now.

Author:  Tallguy [ Tue May 06, 2008 9:11 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

sorry for not being clear, i did meant frame rate

Author:  Michael516 [ Wed May 07, 2008 8:10 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

The speed is o.k. on my computer, mabye your computer is just slow.

Author:  repsoccer16 [ Thu May 08, 2008 7:39 am ]
Post subject:  RE:Fun with trig and drawfillpolygon

ya it is perfectly fine on my computer too so it is just your computer.

Good program Smile

Author:  nastynika [ Thu May 08, 2008 8:18 am ]
Post subject:  Re: Fun with trig and drawfillpolygon

very interesting good job


: