Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Polygon per-pixel control
Index -> Programming, Turing -> Turing Submissions
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
RaPsCaLLioN




PostPosted: Tue Mar 29, 2005 11:44 am   Post subject: Polygon per-pixel control

Might not look that impressive but OMG it was hard. Every time u run it generates a new random polygon. Each polygon is broken down to the pixel. And to prove; I randomly genearted a colour (1, 10) for display and added a delay so you can see each pixel drawn.
I did this in 137 lines.

It's not 100%. You'll occasionally see a break in the middle but I'll have that fixed soon. I'm this much closer now to true texture mapping.



polyscan.zip
 Description:

Download
 Filename:  polyscan.zip
 Filesize:  325.33 KB
 Downloaded:  254 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
jamonathin




PostPosted: Tue Mar 29, 2005 2:33 pm   Post subject: (No subject)

Pretty neat program. I know it would take away from the cool color effects but drawing lines would be faster, other than that, gj Smile
Flikerator




PostPosted: Tue Mar 29, 2005 3:10 pm   Post subject: (No subject)

I would comment on it but I don't have anything to open .rar files :/[/code]
[Gandalf]




PostPosted: Tue Mar 29, 2005 5:15 pm   Post subject: (No subject)

Pretty cool, I can see how it took some time Smile.

To open .rar files get WinRar - almost exactly the same as WinZip, WinAce.
jamonathin




PostPosted: Tue Mar 29, 2005 5:15 pm   Post subject: (No subject)

WinRar. Look it up on google or somthing or go to http://www.download.com/WinRAR/3000-2250_4-10350955.html?tag=lst-0-1
Mr. T




PostPosted: Tue Mar 29, 2005 6:03 pm   Post subject: (No subject)

too lazy Rolling Eyes ...convert it to an .exe
Mazer




PostPosted: Tue Mar 29, 2005 6:27 pm   Post subject: (No subject)

It is an exe. And as it was compiled for Turing, it's a very big exe. rar is a very common compression format for Windows (and oh hey, you can get it for Linux as well) so if you can't be bothered to use it I don't know what you're doing.
RaPsCaLLioN




PostPosted: Tue Mar 29, 2005 6:32 pm   Post subject: (No subject)

There ya go. Added .ZIP
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Tue Mar 29, 2005 7:52 pm   Post subject: (No subject)

How fast is it w/o the delay?
RaPsCaLLioN




PostPosted: Tue Mar 29, 2005 8:14 pm   Post subject: (No subject)

I just updated it. Click mouse to refresh. I took out the delay so... well for me it's as fast as I can click. Also no more errors (white lines). Try it out again.
Naveg




PostPosted: Wed Mar 30, 2005 12:12 am   Post subject: (No subject)

thats pretty cool, wonder what kind of awesome stuff can be done with that
GlobeTrotter




PostPosted: Wed Mar 30, 2005 5:22 pm   Post subject: (No subject)

I tried to code it, to see if I could, and I managed to get a very similar effect. The only real difference between mine and yours is that mine is a lot slower, even without a delay. Could you maybe post your source so I can compare?

code:

setscreen ("graphics:300,300")
fcn TripleMax (Num : array 0 .. 2 of int) : int
    for i : 0 .. 2
        if Num (i) > Num ((i + 1) mod 3) and Num (i) > Num ((i - 1) mod 3) then
            result Num (i)
        end if
    end for
end TripleMax

fcn TripleMin (Num : array 0 .. 2 of int) : int
    for i : 0 .. 2
        if Num (i) < Num ((i + 1) mod 3) and Num (i) < Num ((i - 1) mod 3) then
            result Num (i)
        end if
    end for
end TripleMin

fcn TriArea (x1 : int, y1 : int, x2 : int, y2 : int, x3 : int, y3 : int) : real
    result abs (x1 * y2 + x2 * y3 + x3 * y1 - x1 * y3 - x3 * y2 - x2 * y1) / 2
end TriArea

proc ShadeTriangle (var Pointx : array 0 .. 2 of int, var Pointy : array 0 .. 2 of int, col : int)
    for x : TripleMin (Pointx) .. TripleMax (Pointx)
        for y : TripleMin (Pointy) .. TripleMax (Pointy)
            if TriArea (Pointx (0), Pointy (0), Pointx (1), Pointy (1), Pointx (2), Pointy (2)) =
                    TriArea (x, y, Pointx (1), Pointy (1), Pointx (2), Pointy (2)) +
                    TriArea (Pointx (0), Pointy (0), x, y, Pointx (2), Pointy (2)) +
                    TriArea (Pointx (0), Pointy (0), Pointx (1), Pointy (1), x, y) then
                drawdot (x, y, col)
            end if

        end for
    end for
end ShadeTriangle

var TempPointx : array 0 .. 2 of int
var TempPointy : array 0 .. 2 of int

for i : 0 .. 2
    TempPointx (i) := Rand.Int (1, maxx - 1)
    TempPointy (i) := Rand.Int (1, maxy - 1)
    Draw.Oval (TempPointx (i), TempPointy (i), 2, 2, 1)
end for

ShadeTriangle (TempPointx, TempPointy, 2)
RaPsCaLLioN




PostPosted: Wed Mar 30, 2005 10:37 pm   Post subject: (No subject)

I'd rather not post source just yet. But... mine does not use any 'if' statements contained in loops. Nor does it use any multiplication and only 6 divides per polygon.

The only thing is my method is not self-contained. The two procedures that I used are both relying on an outside array. I need to fix this before I can progress.

Could you please explain what the 3 functions you created are calculating?
GlobeTrotter




PostPosted: Wed Mar 30, 2005 11:40 pm   Post subject: (No subject)

The first two are pretty useless. They just give the max or the min of three inputted numbers since turing's min function and max function only work w/ two numbers.

I basically do a for statement, checking every pixel in a box around the triangle, to see if that pixel is inside the triangle. It is kind of inefficient. The third function is to calculate the area of a triangle, given three points. By checking if the sum of the three triangles formed between the given pixel, and the corners, adds up to the area of the triangle, I can know if the pixel is indside the triangle. If it is, it draws the pixel.
zylum




PostPosted: Fri Apr 01, 2005 9:24 pm   Post subject: (No subject)

here's my attempt.. pretty fast, i think its the same way RaPsCaLLioN did his...

code:
setscreen ("offscreenonly")

var X : array 1 .. 3 of int
var Y : array 1 .. 3 of int

proc NewPoints
    for i : 1 .. 3
        X (i) := Rand.Int (maxx div 4, maxx div 4 * 3)
        Y (i) := Rand.Int (maxy div 4, maxy div 4 * 3)
    end for
    var temp : int
    for i : 1 .. 2
        for j : i + 1 .. 3
            if Y (i) < Y (j) then
                temp := X (i)
                X (i) := X (j)
                X (j) := temp
                temp := Y (i)
                Y (i) := Y (j)
                Y (j) := temp
            end if
        end for
    end for
end NewPoints

proc ShadeTriangle
    var b1, m1, b2, m2, b3, m3 : real
    m1 := (Y (1) - Y (3)) / (X (1) - X (3) + 0.0001) + 0.0001
    b1 := Y (1) - m1 * X (1)
    m2 := (Y (1) - Y (2)) / (X (1) - X (2) + 0.0001) + 0.0001
    b2 := Y (2) - m2 * X (2)
    m3 := (Y (2) - Y (3)) / (X (2) - X (3) + 0.0001) + 0.0001
    b3 := Y (3) - m3 * X (3)

    for decreasing y : Y (1) .. Y (2)
        for x : min (round ((y - b1) / m1), round ((y - b2) / m2)) .. max (round ((y - b1) / m1), round ((y - b2) / m2))
            drawdot (x, y, Rand.Int (1, 10))
        end for
    end for
    for decreasing y : Y (2) .. Y (3)
        for x : min (round ((y - b1) / m1), round ((y - b3) / m3)) .. max (round ((y - b1) / m1), round ((y - b3) / m3))
            drawdot (x, y, Rand.Int (1, 10))
        end for
    end for
    View.Update
end ShadeTriangle

var mx, my, md : int
loop
    NewPoints
    ShadeTriangle
    loop
        mousewhere (mx, my, md)
        exit when md = 1
    end loop
    cls
end loop


-57 lines and sometimes it draws a couple of polygons in a single mouse click (yes that fast). although some of the larger ones take a bit more time.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: