• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Challenge: Triangle Function KiZ Posting Freak     Posts: 2,771 Threads: 96 Joined: Oct 2003 01-30-2006, 03:25 AM Its still a 2d triangle. Just in a 3D environment. A triangle can have no more than 2 dimensions. Thus it is 2D. Foo! marzecTM Senior Member    Posts: 602 Threads: 27 Joined: Oct 2004 01-30-2006, 05:56 AM true it's surface is planar. so is the surface of the world to a certain precision level ( of course it is a curved planar surface ). d'oh? quote="NecrosIhsan"] [/quote] Ralph Senior Member    Posts: 544 Threads: 27 Joined: Jan 2005 01-30-2006, 09:48 AM Quote:Code:```sub EqTri (x as integer, y as integer, s as integer)     line (x,y-s*sqr(3)/2)-(x-s,y+s*sqr(3)/2)     line (x,y-s*sqr(3)/2)-(x+s,y+s*sqr(3)/2)     line (x-s,y+s*sqr(3)/2)-(x+s,y+s*sqr(3)/2) end sub screenres 640,480,32 EqTri(320,240,100) sleep``` Why not Code:```sub EqTri (x as integer, y as integer, s as integer)     line (x,y-s*sqr(3)/2)-(x-s,y+s*sqr(3)/2)     line -(x+s,y+s*sqr(3)/2)     line -(x,y-s*sqr(3)/2) end sub screenres 640,480,32 EqTri(320,240,100) sleep``` Or, even better Code:```sub EqTri (x as integer, y as integer, s as integer)     t=s*sqr(3)/2     line (x,y-t)-(x-s,y+t)     line -(x+s,y+t)     line -(x,y-t) end sub screenres 640,480,32 EqTri(320,240,100) sleep``` Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer. axipher Senior Member    Posts: 488 Threads: 19 Joined: Sep 2005 01-31-2006, 06:14 AM Quote:Code:```DECLARE SUB triangle (x!, y!, size!, angle!, c!) 'I assure you the triangles are equalateral. Your screen is just warped. defsng a-z SCREEN 13 FOR i = 10 TO 255   w = 0   FOR j = i - 10 TO i     OUT 968, j     OUT 969, w     OUT 969, w     OUT 969, w     w = w + 6.3   NEXT   x = SIN(i / 35) * 50 + 160   y = SIN(i / 25) * 50 + 100   triangle x, y, SIN(i / 100) * 50 + 10, i * 10, i   t = TIMER   DO: LOOP WHILE TIMER - t < .05 NEXT SLEEP SUB triangle (xoff, yoff, size, angle, c)   DIM x(2), y(2)   FOR i = 0 TO 2      x(i) = COS((i * 120 + angle) * 3.14159 / 180) * size + xoff      y(i) = SIN((i * 120 + angle) * 3.14159 / 180) * size + yoff   NEXT   FOR i = 0 TO 2     LINE (x(i), y(i))-(x((i + 1) MOD 3), y((i + 1) MOD 3)), c   NEXT END SUB``` I still like this one the most, the angle feature is the best. As well as it supports color.  Dr_Davenstein Posting Freak     Posts: 1,774 Threads: 62 Joined: Aug 2003 02-03-2006, 03:24 AM Hey, I made a weirdo! :lol: Code:```Screen 12 Type Vector2D     As Single X,Y End Type Dim As Vector2D P1=>(50,50),P2=>(150,150),P3=>(50,150) For y=0 to 479     For x=0 to 639                  If ((P2.X - X) * (P3.Y - Y) - (P3.X - X) * (P2.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 And _            ((P3.X - X) * (P1.Y - Y) - (P1.X - X) * (P3.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 And _            ((P1.X - X) * (P2.Y - Y) - (P2.X - X) * (P1.Y - Y)) / (P2.X - P1.X) * (P3.Y - P1.Y) - (P3.X - P1.X) * (P2.Y - P1.Y)>0 Then            Pset(X,Y),14         End If              Next Next Sleep``` stylin Senior Member    Posts: 324 Threads: 12 Joined: Nov 2005 02-03-2006, 04:10 AM I thought the contest was for a function. :o stylin: Dr_Davenstein Posting Freak     Posts: 1,774 Threads: 62 Joined: Aug 2003 02-03-2006, 04:26 AM blah... It was supposed to make an equilateral triangle too. hifty: Deleter Posting Freak     Posts: 1,025 Threads: 44 Joined: May 2005 02-03-2006, 11:02 AM Quote:Deleter Wrote:[my code] Why not [better code] Or, even better [even better code] Because I didn't feel like optimizing it, ntm I had never known of that way of doing gfx. I consider myself one step more experienced now :wink: « Next Oldest | Next Newest »

Forum Jump:

Users browsing this thread: 1 Guest(s) 