|
Post by bluatigro on Apr 27, 2018 19:25:46 GMT
b+ : this on the edge what i can code if you find some of my code useful go ahead and use it and if you find a inpromend i like to know i been coding in basic for +-33y but i do not know everything i want to know jet and this not al what is out there of knowlige the last wil take several livetime's so i stick on what i want to know
|
|
|
Post by B+ on Apr 27, 2018 23:27:56 GMT
Yep! on the edge for me as well but it is very exciting.
|
|
|
Post by B+ on Apr 29, 2018 1:22:29 GMT
I think I am getting close to proper Boid Watching:
'Boid Watching.txt for JB 2.0 B+ 2018-04-28
'from 'networking.bas SmallBASIC 0.12.9 [B+=MGA] 2017-04-14 ' combined with 'Mouse school critter attract or repell.txt for JB 2.0 B+ 2018-04-26 ' plus what I picked up generally from the videos
NoMainWin global xmax, ymax, pi, mx, my, boidRadius xmax = 1200 : ymax = 700 : pi = acs(-1)
'using mouse as predator
Boids = 20 boidRadius = 13
''''''''''''''''''''''''''''''''''''''' You control the NeighborBoid Here ''''''''''''''''''''''''' 'Boid behavior based on several modes
centerMode = 1 ' on / off cf = .05 'centering factor how strong a pull from 0 to 1 .01 is week .1 pretty strong!
headMode = 1 ' on / off sway = pi/6 'just turn neighbor towards neighbor hf = .2 'heading factor how strong an influence 0 to 1
spaceMode = 1 ' on / off spacing = 15 'space amount approx
noise = 0 'general randomness added to movements individualism
WindowWidth = xmax + 8 WindowHeight = ymax + 32 UpperLeftX = 100 UpperLeftY = 40 Open "Boid Watching v 2018-04-27 by B+ for JB v2 click or keypress quits" For Graphics_nsb_nf As #g #g "trapclose quit" #g "setfocus" #g "when leftButtonUp lButtonUp" #g "when characterInput charIn" #g "when mouseMove move" #g "down" #g "fill black"
dim x(Boids), y(Boids), a(Boids), c$(Boids) '< pseudo OOP object each index ie object.x, object.y...
for i = 0 to Boids call newCritter i next
while 1 scan #g "discard" #g "fill black" for i = 0 to Boids 'big show of points and triangle scan for j = i + 1 to Boids scan if distance(x(i), y(i), x(j), y(j)) < 6 * boidRadius then
'sway the neighbors towards each other if headMode then if a(i) > a(j) then a(i) = a(i) - sway * hf a(j) = a(j) + sway * hf else a(i) = a(i) + sway * hf a(j) = a(j) - sway * hf end if end if
'stickiness stay close to neighbors, close distance between if centerMode then if x(i) > x(j) then x(i) = x(i) - cf * (x(i) - x(j)) x(j) = x(j) + cf * (x(i) - x(j)) else x(i) = x(i) + cf * (x(j) - x(i)) x(j) = x(j) - cf * (x(j) - x(i)) end if if y(i) > y(j) then y(i) = y(i) - cf * (y(i) - y(j)) y(j) = y(j) + cf * (y(i) - y(j)) else y(i) = y(i) + cf * (y(j) - y(i)) y(j) = y(j) - cf * (y(j) - y(i)) end if end if
'don't let them bunch up if spaceMode then ' The following is STATIC's adjustment of ball positions if overlapping ' before calcultion of new positions from collision ' Displacement vector and its magnitude. Thanks STxAxTIC ! nx = x(j) - x(i) ny = y(j) - y(i) nm = SQR(nx ^ 2 + ny ^ 2) IF nm < spacing + 2*boidRadius THEN nx = nx / nm ny = ny / nm ' Regardless of momentum exchange, separate the balls along the lone connecting them. WHILE nm < spacing + 2*boidRadius scan x(j) = x(j) + .3 * spacing * nx y(j) = y(j) + .3 * spacing * ny x(i) = x(i) - .3 * spacing * nx y(i) = y(i) - .3 * spacing * ny nx = x(j) - x(i) ny = y(j) - y(i) nm = SQR(nx ^ 2 + ny ^ 2) nx = nx / nm ny = ny / nm wend end if 'spacer end if 'space Mode end if 'distance next 'edit add some containment of critters, swirl them around at borders IF x(i) < 30 OR x(i) > xmax - 30 OR y(i) < 30 OR y(i) > ymax - 30 THEN a(i) = a(i) + sway 'out of sight if x(i) < -1 * boidRadius or x(i) > xmax + 80 or y(i) < -1*boidRadius or y(i) > ymax + boidRadius then 'start new call newCritter i end if if distance(x(i), y(i), mx, my) < 6 * boidRadius then a(i) = atan2(my - y(i), mx - x(i)) + pi predatorMode = 1 else predatorMode = 0 end if
'update points x(i) = x(i) + 10 * cos(a(i)) + rnd(0) * noise - .5 * noise y(i) = y(i) + 10 * sin(a(i)) + rnd(0) * noise - .5 * noise
call critter i
'mouse predator #g "color brown" #g "backcolor red" #g "place ";mx;" ";my;"; circlefilled ";boidRadius*2 next #g "flush" call pause 100 wend
'---------------- windows setup calls
sub quit H$ close #H$ end end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y call quit H$ end sub
sub charIn H$, c$ call quit H$ end sub
sub move H$, MouseX, MouseY mx = MouseX my = MouseY end sub
'--------------- important subs for this program
sub newCritter index '< psuedo OOP new Object x(index) = rand(0, xmax) y(index) = rand(0, ymax) a(index) = -2 * pi * rnd(0) c$(index) = str$(rand(64, 155));" ";str$(rand(64, 155));" ";str$( rand(64, 155)) end sub
sub critter i #g "color ";c$(i) #g "backcolor ";c$(i) #g "place ";x(i);" ";y(i);"; circlefilled ";boidRadius if predatorMode then x1 = x(i) + .75 * boidRadius * cos(a(i) - pi/9 + pi) y1 = y(i) + .75 * boidRadius * sin(a(i) - pi/9 + pi) x2 = x(i) + .75 * boidRadius * cos(a(i) + pi/9 + pi) y2 = y(i) + .75 * boidRadius * sin(a(i) + pi/9 + pi) else x1 = x(i) + .75 * boidRadius * cos(a(i) - pi/9) y1 = y(i) + .75 * boidRadius * sin(a(i) - pi/9) x2 = x(i) + .75 * boidRadius * cos(a(i) + pi/9) y2 = y(i) + .75 * boidRadius * sin(a(i) + pi/9) end if #g "color white" #g "backcolor white" #g "place ";x1;" ";y1;"; circlefilled ";.25 * boidRadius #g "place ";x2;" ";y2;"; circlefilled ";.25 * boidRadius if predatorMode then x3 = x1 + .125 * boidRadius * cos(a(i) + pi) y3 = y1 + .125 * boidRadius * sin(a(i) + pi) x4 = x2 + .125 * boidRadius * cos(a(i) + pi) y4 = y2 + .125 * boidRadius * sin(a(i) + pi) else x3 = x1 + .125 * boidRadius * cos(a(i)) y3 = y1 + .125 * boidRadius * sin(a(i)) x4 = x2 + .125 * boidRadius * cos(a(i)) y4 = y2 + .125 * boidRadius * sin(a(i)) end if #g "color black" #g "backcolor black" #g "place ";x3;" ";y3;"; circlefilled ";.125*boidRadius #g "place ";x4;" ";y4;"; circlefilled ";.125*boidRadius end sub
Function atan2(y, x) 'thanks Andy Amaya 'atan2 is a function which determines the angle between points 'x1, y1 and x2, y2. The angle returned is in radians 'The angle returned is always in the range of '-PI to PI radians (-180 to 180 degrees) '============================================================== 'NOTE the position of Y and X arguments 'This keeps atan2 function same as other language versions '============================================================== If x = 0 Then If y < 0 Then atan2 = -1.5707963267948967 Else atan2 = 1.5707963267948967 End If Else chk = atn(y/x) If x < 0 Then If y < 0 Then chk = chk - 3.1415926535897932 Else chk = chk + 3.1415926535897932 End If End If atan2 = chk End If if atan2 < 0 then atan2 = atan2 + 2 * pi End Function
'----------------- supplementary handy subs
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
function rand(lo, hi) rand = int((hi - lo + 1) * rnd(0)) + lo end function
function distance(x1, y1, x2, y2) distance = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5 end function
function rdir() if rnd(0) < .5 then rdir = -1 else rdir = 1 end function
|
|
|
Post by bluatigro on Apr 29, 2018 7:44:33 GMT
b+ : i added a automatic predator
error : the predator is not moving as expected
'Boid Watching.txt for JB 2.0 B+ 2018-04-28
'from 'networking.bas SmallBASIC 0.12.9 [B+=MGA] 2017-04-14 ' combined with 'Mouse school critter attract or repell.txt for JB 2.0 B+ 2018-04-26 ' plus what I picked up generally from the videos ''bluatigro 29 apr 2018 : i added a atomatic predator
NoMainWin global xmax, ymax, pi, mx, my, boidRadius pi = acs(-1)
'predator global predator.state$ , predator.tel , state$ state$ = "forwart left right" predator.state$ = word$( state$ , rand( 1 , 3 ) ) predator.tel = rand( 1 , 10 )
Boids = 20 boidRadius = 13
''''''''''''''''''''''''''''''''''''''' You control the NeighborBoid Here ''''''''''''''''''''''''' 'Boid behavior based on several modes
centerMode = 1 ' on / off cf = .05 'centering factor how strong a pull from 0 to 1 .01 is week .1 pretty strong!
headMode = 1 ' on / off sway = pi/6 'just turn neighbor towards neighbor hf = .2 'heading factor how strong an influence 0 to 1
spaceMode = 1 ' on / off spacing = 15 'space amount approx
noise = 0 'general randomness added to movements individualism
WindowWidth = DisplayWidth WindowHeight = DisplayHeight xmax = WindowWidth ymax = WindowHeight
UpperLeftY = 40 Open "Boid Watching v 2018-04-27 by B+ for JB v2 click or keypress quits" For Graphics_nsb_nf As #g #g "trapclose quit" #g "setfocus" #g "when leftButtonUp lButtonUp" #g "when characterInput charIn" #g "when mouseMove move" #g "down" #g "fill black"
dim x(Boids), y(Boids), a(Boids), c$(Boids) '< pseudo OOP object each index ie object.x, object.y...
call newCritter 0 , "red" for i = 1 to Boids call newCritter i , "green" next
while 1 scan #g "discard" #g "fill black" for i = 1 to Boids 'big show of points and triangle scan for j = i + 1 to Boids scan if distance(x(i), y(i), x(j), y(j)) < 6 * boidRadius then 'sway the neighbors towards each other if headMode then if a(i) > a(j) then a(i) = a(i) - sway * hf a(j) = a(j) + sway * hf else a(i) = a(i) + sway * hf a(j) = a(j) - sway * hf end if end if 'stickiness stay close to neighbors , 'close distance between if centerMode then if x(i) > x(j) then x(i) = x(i) - cf * (x(i) - x(j)) x(j) = x(j) + cf * (x(i) - x(j)) else x(i) = x(i) + cf * (x(j) - x(i)) x(j) = x(j) - cf * (x(j) - x(i)) end if if y(i) > y(j) then y(i) = y(i) - cf * (y(i) - y(j)) y(j) = y(j) + cf * (y(i) - y(j)) else y(i) = y(i) + cf * (y(j) - y(i)) y(j) = y(j) - cf * (y(j) - y(i)) end if end if 'don't let them bunch up if spaceMode then ' The following is STATIC's adjustment ' of ball positions if overlapping ' before calcultion of new positions ' from collision ' Displacement vector and its magnitude. ' Thanks STxAxTIC ! nx = x(j) - x(i) ny = y(j) - y(i) nm = SQR( nx ^ 2 + ny ^ 2) IF nm < spacing + 2 * boidRadius THEN nx = nx / nm ny = ny / nm ' Regardless of momentum exchange, separate the balls along the lone connecting them. WHILE nm < spacing + 2 * boidRadius scan x(j) = x(j) + .3 * spacing * nx y(j) = y(j) + .3 * spacing * ny x(i) = x(i) - .3 * spacing * nx y(i) = y(i) - .3 * spacing * ny nx = x(j) - x(i) ny = y(j) - y(i) nm = SQR( nx ^ 2 + ny ^ 2 ) nx = nx / nm ny = ny / nm wend end if 'spacer end if 'space Mode end if 'distance next j 'edit add some containment of critters, 'swirl them around at borders IF x(i) < 30 _ OR x(i) > xmax - 30 _ OR y(i) < 30 _ OR y(i) > ymax - 30 THEN a(i) = a(i) + sway 'out of sight if x(i) < -1 * boidRadius or x(i) > xmax + 80 or y(i) < -1*boidRadius or y(i) > ymax + boidRadius then 'start new call newCritter i , "green" end if if distance( x(i) , y(i) ,x(0) , y(0) ) < 6 * boidRadius then a(i) = atan2( x(0) - x(i) , y(0) - x(i) ) + pi predatorMode = 1 else predatorMode = 0 end if 'update points x(i) = x(i) + 10 * cos(a(i)) + rnd(0) * noise - .5 * noise y(i) = y(i) + 10 * sin(a(i)) + rnd(0) * noise - .5 * noise call critter i next i ''predator stering ''move predator whit finite state machine predator.tel = predator.tel - 1 if predator.tel < 0 then predator.tel = rand( 1 , 10 ) predator.state$ = word$( state$ , rand( 1 , 3 ) ) end if dx = 0 dy = 10 select case predator.state$ case "left" a(0) = a(0) + sway case "right" a(0) = a(0) - sway case else end select call rotate dx , dy , a(0)
IF x(0) + dx < 30 _ OR x(0) + dx > xmax - 30 _ OR y(0) + dy < 30 _ OR y(0) + dy > ymax - 30 THEN a(0) = a(0) + sway dx = 0 dy = 10 call rotate dx , dy , a(0) x(0) = x(0) + dx y(0) = y(0) + dy
call critter 0 #g "flush" call pause 100 wend
'---------------- windows setup calls
sub quit H$ close #H$ end end sub
sub lButtonUp H$, mx, my 'must have handle and mouse x,y call quit H$ end sub
sub charIn H$, c$ call quit H$ end sub
sub move H$, MouseX, MouseY mx = MouseX my = MouseY end sub
'--------------- important subs for this program
sub newCritter index , clr$ '< psuedo OOP new Object x( index ) = rand( 0 , xmax ) y( index ) = rand( 0 , ymax ) a( index ) = -2 * pi * rnd(0) c$( index ) = clr$ end sub
sub critter i #g "color " ; c$(i) #g "backcolor " ; c$(i) #g "place " ; x(i) ; " " ; y(i) #g "circlefilled "; boidRadius if predatorMode then x1 = x(i) + .75 * boidRadius * cos(a(i) - pi/9 + pi) y1 = y(i) + .75 * boidRadius * sin(a(i) - pi/9 + pi) x2 = x(i) + .75 * boidRadius * cos(a(i) + pi/9 + pi) y2 = y(i) + .75 * boidRadius * sin(a(i) + pi/9 + pi) else x1 = x(i) + .75 * boidRadius * cos(a(i) - pi/9) y1 = y(i) + .75 * boidRadius * sin(a(i) - pi/9) x2 = x(i) + .75 * boidRadius * cos(a(i) + pi/9) y2 = y(i) + .75 * boidRadius * sin(a(i) + pi/9) end if #g "color white" #g "backcolor white" #g "place " ; x1 ; " " ; y1 #g "circlefilled " ; .25 * boidRadius #g "place " ; x2 ; " " ; y2 #g "circlefilled " ; .25 * boidRadius if predatorMode then x3 = x1 + .125 * boidRadius * cos(a(i) + pi) y3 = y1 + .125 * boidRadius * sin(a(i) + pi) x4 = x2 + .125 * boidRadius * cos(a(i) + pi) y4 = y2 + .125 * boidRadius * sin(a(i) + pi) else x3 = x1 + .125 * boidRadius * cos(a(i)) y3 = y1 + .125 * boidRadius * sin(a(i)) x4 = x2 + .125 * boidRadius * cos(a(i)) y4 = y2 + .125 * boidRadius * sin(a(i)) end if #g "color black" #g "backcolor black" #g "place ";x3;" ";y3;"; circlefilled ";.125*boidRadius #g "place ";x4;" ";y4;"; circlefilled ";.125*boidRadius end sub
Function atan2(y, x) 'thanks Andy Amaya 'atan2 is a function which determines the angle between points 'x1, y1 and x2, y2. The angle returned is in radians 'The angle returned is always in the range of '-PI to PI radians (-180 to 180 degrees) '============================================================== 'NOTE the position of Y and X arguments 'This keeps atan2 function same as other language versions '============================================================== If x = 0 Then If y < 0 Then atan2 = -1.5707963267948967 Else atan2 = 1.5707963267948967 End If Else chk = atn(y/x) If x < 0 Then If y < 0 Then chk = chk - 3.1415926535897932 Else chk = chk + 3.1415926535897932 End If End If atan2 = chk End If if atan2 < 0 then atan2 = atan2 + 2 * pi End Function
'----------------- supplementary handy subs
sub pause mil 'tsh version has scan built-in t0 = time$("ms") while time$("ms") < t0 + mil : scan : wend end sub
function rand(lo, hi) rand = int( ( hi - lo + 1 ) * rnd(0) ) + lo end function
function distance(x1, y1, x2, y2) distance = ( (x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ .5 end function
function rdir() if rnd(0) < .5 then rdir = -1 else rdir = 1 end function
sub rotate byref k , byref l , r s = sin( r ) c = cos( r ) hk = k * c - l * s hl = k * s + l * s k = hk l = hl end sub
|
|
|
Post by B+ on Apr 29, 2018 14:00:05 GMT
I think we should try and stick with boid as Object paradigm ie when we create a new boid give it a social or anti-social = predator setting.
Also we can give the critters move-ability or NOT st that along edges we can set up stationary + predator boids to keep all the moving creatures in bounds (as best we can) the moving predators may or may not avoid each other? probably avoid each other as easier to implement.
So if we want all the social critters green and predators red, say so in the new object creation sub.
Hmm... we might want to control certain factors at the creation of a new object, like in the youtube video, the guy was clicking in new barriers or moving predators? (no? not that) or new social critters.
|
|
|
Post by bluatigro on Apr 29, 2018 16:01:00 GMT
update : lets go 3D !!
first step : drawing predator [ red ] + prey [ green ] whit sprite3d [ light's ] linked to main sprite3d
the light's are there to show the orientation of the animal's
i do not know if the light's color's are the same as whit a plane
error : my prey do not spred al over the screen
''bluatigro 29 apr 2018 ''boids 3d world JB VESION
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , pi , s.max , s.tel , key$ global p.x , p.y , p.z dim g.x( 4 ) , g.y( 4 ) , g.z( 4 ) p.x = 6 p.y = 0 p.z = 6 for i = 0 to 4 g.x( i ) = 2 g.y( i ) = 0 g.z( i ) = 2 next i winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 100 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) dim s.pan( s.max ) , s.tilt( s.max ) , s.rol( s.max ) dim s.name$( s.max ) , ry( s.max ) dim maze$( 20 , 20 ) , s.state$( s.max ) nomainwin gosub [sprite] open "isometric game demo" for graphics as #m #m "trapclose [quit]" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 30,30 , "black" , "green" , 2 call sprite.getbmp "prey" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 30,30 , "black" , "red" , 2 call sprite.getbmp "predator" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 10,10 , "black" , "green" , 2 call sprite.getbmp "green" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 10,10 , "black" , "red" , 2 call sprite.getbmp "red" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 10,10 , "black" , "blue" , 2 call sprite.getbmp "blue" call sprite.clear 64 , 64 call sprite.ellipse 32,32 , 10,10 , "black" , "yellow" , 2 call sprite.getbmp "yellow"
call sprite3d.add 0 , "predator" call sprite3d.add 1 , "red" call sprite3d.add 2 , "green" call sprite3d.add 3 , "blue" call sprite3d.add 4 , "yellow" for i = 5 to s.max - 5 step 5 call sprite3d.add 0 + i , "prey" call sprite3d.add 1 + i , "red" call sprite3d.add 2 + i , "green" call sprite3d.add 3 + i , "blue" call sprite3d.add 4 + i , "yellow" next i for i = 0 to s.max call sprite3d.xyz i , range( -200 , 200 ) _ , range( -200 , 200 ) , range( -200 , 200 ) s.pan( i ) = range( 0 , 360 ) s.tilt( i ) = range( -30 , 30 ) s.rol( i ) = range( -30 , 30 ) ry( i ) = i next i #m "when characterInput [key]" #m "setfocus"
''while key$ = "" scan ''set xyz of predator and boids + light's for i = 0 to s.max - 5 step 5 call sprite3d.get.xyz i , x , y , z dx = 0 : dy = 0 : dz = -40 call rotate dx , dz , s.pan( i ) call rotate dx , dy , s.tilt( i ) call rotate dy , dz , s.rol( i ) call sprite3d.xyz i + 1 , x + dx , y + dy , z + dz dx = 0 : dy = 40 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dx , dy , s.tilt( i ) call rotate dy , dz , s.rol( i ) call sprite3d.xyz i + 2 , x + dx , y + dy , z + dz dx = 40 : dy = -40 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dx , dy , s.tilt( i ) call rotate dy , dz , s.rol( i ) call sprite3d.xyz i + 3 , x + dx , y + dy , z + dz dx = -40 : dy = -40 : dz = -40 call rotate dx , dz , s.pan( i ) call rotate dx , dy , s.tilt( i ) call rotate dy , dz , s.rol( i ) call sprite3d.xyz i + 4 , x + dx , y + dy , z + dz next i
''TODO : 3d swarming
''sort sprite3d for high = 1 to s.tel - 1 for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''draw world for i = 0 to s.tel - 1 #m "spritetoback spr" ; ry( i ) call sprite3d.get.xyz ry( i ) , x , y , z #m "spritexy spr" ; ry( i ) ; " " _ ; int( winx / 2 + x ) ; " " _ ; int( winy / 2 - y - y / 4 ) next i #m "drawsprites" ''wend notice "GAME OVER" end [key] key$ = right$( Inkey$ , 1 ) if key$ <> chr$( _VK_ESCAPE ) then wait [quit] close #m end ''bluatigro 21 apr 2017 ''sprite module [sprite] global sprite.width , sprite.height return sub sprite.clear w , h #m "fill white" #m "goto 0 " ; h #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled " ; w ; " " ; h * 2 #m "up" sprite.width = w sprite.height = h end sub sub sprite.rectangle x1,y1,x2,y2,clr$ #m "goto " ; x1 ; " " ; y1 #m "size 1" #m "color black" #m "backcolor black" #m "down" #m "boxfilled " ; x2 ; " " ; y2 #m "up" #m "goto " ; x1 ; " " ; y1 + sprite.height #m "color " ; clr$ #m "backcolor " ; clr$ #m "down" #m "boxfilled " ; x2 ; " " ; y2 + 60 #m "up" end sub sub sprite.ellipse x,y,dx,dy,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "ellipsefilled " ; dx ; " " ; dy #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "ellipsefilled " ; dx ; " " ; dy #m "up" end sub sub sprite.pie x,y,dx,dy,a,b,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" end sub sub sprite.line x1,y1 , x2,y2 , clr$ , size #m "color black" #m "size " ; size #m "down" #m "line " ; x1 ; " " ; y1 _ ; " " ; x2 ; " " ; y2 #m "up" #m "color " ; clr$ #m "down" #m "line " ; x1 ; " " ; y1 + sprite.height _ ; " " ; x2 ; " " ; y2 + sprite.height #m "up" end sub sub sprite.getbmp bmp$ #m "getbmp " ; bmp$ ; " 0 0 " _ ; sprite.width ; " " ; sprite.height * 2 end sub ''end sprite_draw module ''sprite3d module sub sprite3d.add no , i$ #m "addsprite spr" ; no ; " " ; i$ s.name$( no ) = word$( i$ , 1 ) end sub sub sprite3d.xyz no , x , y , z s.x( no ) = x s.y( no ) = y s.z( no ) = z end sub sub sprite3d.get.xyz no , byref x , byref y , byref z x = s.x( no ) y = s.y( no ) z = s.z( no ) end sub ''end sprite3d module function range( l , h ) range = rnd(0) * ( h - l ) * l end function function rad( deg ) rad = deg * pi / 180 end function function degrees( r ) degrees = r * 180 / pi end function sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
|
|
|
Post by B+ on Apr 29, 2018 17:34:31 GMT
3D! A man after my own goat! Hi bluatigro, Get some code working and show me something compelling to motivate me to try 3D! Right now I am neck deep into an Objects sim makeover.
|
|
|
Post by bluatigro on Apr 30, 2018 12:21:06 GMT
by this it is working as expected this are NOT boid's but it is 3D !!
''bluatigro 15 apr 2018 ''pecspertive 3d sprites
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , angle , pi , s.max winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 40 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) , ry( s.max ) nomainwin open "isometric game demo" for graphics as #m #m "trapclose [quit]" #m "size 10" #m "goto 50 50" #m "down" #m "color black" #m "backcolor black" #m "circle 30" #m "up" for i = 0 to s.max #m "goto 0 100" #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled 100 200" #m "up" #m "size 10" #m "goto 50 150" #m "down" #m "color " ; rainbow$( i * 360 / s.max ) #m "backcolor " ; rainbow$( i * 360 / s.max ) #m "circle 30" #m "up" #m "getbmp bmp" ; i ; " 0 0 100 200" #m "addsprite spr" ; i ; " bmp" ; i '' #m "centersprite spr" ; i ry( i ) = i ''create world s.x( i ) = range( -200 , 200 ) s.y( i ) = range( -200 , 200 ) s.z( i ) = range( -200 , 200 ) next i #m "fill black" #m "getbmp back 0 0 1 1" #m "background back" timer 40 , [timer] wait [timer] s = sin( rad( 5 ) ) c = cos( rad( 5 ) ) ''rotate the world for i = 0 to s.max x = s.x( i ) * c - s.z( i ) * s z = s.x( i ) * s + s.z( i ) * c s.x( i ) = x s.z( i ) = z next i ''do not change below this line ''sort sphere's for high = 1 to s.max for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''put spehere's on screen for i = 0 to s.max factor = s.z( ry( i ) ) + 1000 x = int( winx / 2 + s.x( ry( i ) ) / factor * 1000 ) y = int( winy / 2 - s.y( ry( i ) ) / factor * 1000 ) size = int( 100 / factor * 1000 ) #m "spritescale spr" ; ry( i ) ; " " ; size #m "spritetoback spr" ; ry( i ) #m "spritexy spr" ; ry( i ) ; " " ; x ; " " ; y next i #m "drawsprites" angle = angle + 5 wait [quit] close #m end function range( l , h ) range = rnd(0) * ( h - l ) + l end function function rad( deg ) rad = deg * pi / 180 end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
|
|
|
Post by B+ on Apr 30, 2018 13:22:25 GMT
Hi bluatigro,
That is exactly perfect compelling motivation! THANKS!
|
|
|
Post by bluatigro on May 2, 2018 11:06:29 GMT
update : moving 3D boid's
error : they just are kept in 1 state of the finite state machine somtimes i boid escapes and somethimes the code crashes
''bluatigro 2 may 2018 ''boid's whit pecspertive 3d sprites
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , angle , pi , s.max winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 79 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) , ry( s.max ) dim s.pan( s.max ) , s.tilt( s.max ) , s.rol( s.max ) dim s.state$( s.max ) , s.tel( s.max ) nomainwin gosub [sprite] open "isometric game demo" for graphics as #m #m "trapclose [quit]" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "black" , "green" , 1 call sprite.getbmp "prey" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "black" , "red" , 1 call sprite.getbmp "predator" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "red" , 1 call sprite.getbmp "red" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "green" , 1 call sprite.getbmp "green" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "yellow" , 1 call sprite.getbmp "yellow" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "blue" , 1 call sprite.getbmp "blue" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "cyan" , 1 call sprite.getbmp "cyan" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "pink" , 1 call sprite.getbmp "magenta" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "black" , 1 call sprite.getbmp "black" bmp$ = "predator red green yellow blue cyan magenta black" for i = 0 to 7 call sprite3d.add i , word$( bmp$ , ( i and 7 ) + 1 ) next i bmp$ = "prey red green yellow blue cyan magenta" for i = 8 to s.max call sprite3d.add i , word$( bmp$ , ( i and 7 ) + 1 ) next i for i = 0 to s.max ry( i ) = i ''create world s.x( i ) = range( -200 , 200 ) s.y( i ) = range( -200 , 200 ) s.z( i ) = range( -200 , 200 ) s.pan( i ) = range( 0 , 360 ) s.tilt( i ) = range( -30 , 30 ) s.rol( i ) = range( -30 , 30 ) next i #m "fill black" #m "getbmp screen 0 0 1 1" #m "background screen" timer 40 , [timer] wait [timer] for i = 0 to s.max - 7 step 8 call sprite3d.get.xyz i , x , y , z dx = 30 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 1 , x + dx , y + dy , z + dz dx = 0 : dy = 30 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 2 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 3 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 4 , x + dx , y + dy , z + dz dx = -30 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 5 , x + dx , y + dy , z + dz dx = 0 : dy = -30 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 6 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -5 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) s.tel( i ) = s.tel( i ) - 1 if s.tel( i ) < 0 then s.tel( i ) = range( 3 , 9 ) s.state$( i ) = _ word$( "left right up down q" , int( range( 1 , 5 ) ) ) end if if x + dx < -200 or x + dx > 200 _ or z + dz < 200 or z + dz > 200 then s.state$( i ) = "left" end if if y + dy < -200 then s.state$( i ) = "up" end if if y + dy > 200 then s.state$( i ) = "down" end if select case s.state$( i ) case "left" s.pan( i ) = s.pan( i ) + 5 case "right" s.pan( i ) = s.pan( i ) - 5 case "up" if s.tilt( i ) < 30 then s.tilt( i ) = s.tilt( i ) + 5 end if case "down" if s.tilt( i ) > 30 then s.tilt( i ) = s.tilt( i ) + 5 end if case else end select call sprite3d.xyz i , x + dx , y + dy , z + dz next i scan ''do not change below this line ''sort sphere's for high = 1 to s.max for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''put spehere's on screen for i = 0 to s.max factor = s.z( ry( i ) ) + 1000 x = int( winx / 2 + s.x( ry( i ) ) / factor * 1000 ) y = int( winy / 2 - s.y( ry( i ) ) / factor * 1000 ) size = int( 100 / factor * 1000 ) dx = int( sprite.width / 2 / factor * 1000 ) dy = int( sprite.height / 2 / factor * 1000 ) #m "spritescale spr" ; ry( i ) ; " " ; size #m "spritetoback spr" ; ry( i ) #m "spritexy spr" ; ry( i ) ; " " ; x ; " " ; y next i #m "drawsprites" angle = angle + 5 wait [quit] close #m end sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function range( l , h ) range = rnd(0) * ( h - l ) + l end function function rad( deg ) rad = deg * pi / 180 end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
''bluatigr 2 may 2018 ''sprite3d module
sub sprite3d.add no , bmp$ #m "addsprite spr" ; no ; " " ; bmp$ end sub
sub sprite3d.xyz no , x , y , z s.x( no ) = x s.y( no ) = y s.z( no ) = z end sub
sub sprite3d.get.xyz no , byref x , byref y , byref z x = s.x( no ) y = s.y( no ) z = s.z( no ) end sub ''bluatigro 26 apr 2018 ''sprite module
[sprite] global sprite.width , sprite.height return
sub sprite.clear w , h #m "fill white" #m "goto 0 " ; h #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled " ; w ; " " ; h * 2 #m "up" sprite.width = w sprite.height = h end sub
sub sprite.triangle x1 , y1 , x2 , y2 , x3 , y3 , clr$ if y1 = y2 then y1 = y1 - 1e-10 if y2 = y3 then y3 = y3 + 1e-10 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if call sprite.line a , i + sprite.height _ , b , i + sprite.height , clr$ , 1 call sprite.line a , i , b , i , "black" , 1 next i #m "flush" end sub
sub sprite.rectangle x1,y1,x2,y2,clr$ #m "goto " ; x1 ; " " ; y1 #m "size 1" #m "color black" #m "backcolor black" #m "down" #m "boxfilled " ; x2 ; " " ; y2 #m "up" #m "goto " ; x1 ; " " ; y1 + sprite.height #m "color " ; clr$ #m "backcolor " ; clr$ #m "down" #m "boxfilled " ; x2 ; " " ; y2 + 60 #m "up" end sub
sub sprite.ellipse x,y,dx,dy,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "ellipsefilled " ; dx ; " " ; dy #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "ellipsefilled " ; dx ; " " ; dy #m "up" end sub
sub sprite.pie x,y,dx,dy,a,b,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" end sub
sub sprite.line x1,y1 , x2,y2 , clr$ , size #m "color black" #m "size " ; size #m "down" #m "line " ; x1 ; " " ; y1 _ ; " " ; x2 ; " " ; y2 #m "up" #m "color " ; clr$ #m "down" #m "line " ; x1 ; " " ; y1 + sprite.height _ ; " " ; x2 ; " " ; y2 + sprite.height #m "up" end sub
sub sprite.getbmp bmp$ #m "getbmp " ; bmp$ ; " 0 0 " _ ; sprite.width ; " " ; sprite.height * 2 end sub
|
|
|
Post by bluatigro on May 2, 2018 11:48:23 GMT
update : i tryed it whitout tilt and a better finite state machine
that virtual machine error is verry anoing it chashes my code and kicks mout of JB
''bluatigro 2 may 2018 ''boid's whit pecspertive 3d sprites
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , angle , pi , s.max winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 79 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) , ry( s.max ) dim s.pan( s.max ) , s.tilt( s.max ) , s.rol( s.max ) dim s.state$( s.max ) , s.tel( s.max ) nomainwin gosub [sprite] open "isometric game demo" for graphics as #m #m "trapclose [quit]" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "green" , "green" , 1 call sprite.getbmp "prey" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "red" , "red" , 1 call sprite.getbmp "predator" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "red" , "red" , 1 call sprite.getbmp "red" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "green" , "green" , 1 call sprite.getbmp "green" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "yellow" , "yellow" , 1 call sprite.getbmp "yellow" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "blue" , "blue" , 1 call sprite.getbmp "blue" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "cyan" , "cyan" , 1 call sprite.getbmp "cyan" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "pink" , "pink" , 1 call sprite.getbmp "magenta" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "black" , "black" , 1 call sprite.getbmp "black" bmp$ = "predator red green yellow blue cyan magenta black" for i = 0 to 7 call sprite3d.add i , word$( bmp$ , ( i and 7 ) + 1 ) next i bmp$ = "prey red green yellow blue cyan magenta black" for i = 8 to s.max call sprite3d.add i , word$( bmp$ , ( i and 7 ) + 1 ) next i for i = 0 to s.max ry( i ) = i ''create world s.x( i ) = range( 0-winx/3 , winx/3 ) s.y( i ) = range( 0-winy/3 , winy/3 ) s.z( i ) = range( 0-winx/3 , winx/3 ) s.pan( i ) = range( 0 , 360 ) '' s.tilt( i ) = range( -30 , 30 ) '' s.rol( i ) = range( -30 , 30 ) next i #m "fill black" #m "getbmp screen 0 0 1 1" #m "background screen" timer 40 , [timer] wait [timer] for i = 0 to s.max - 7 step 8 call sprite3d.get.xyz i , x , y , z dx = 30 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 1 , x + dx , y + dy , z + dz dx = 0 : dy = 30 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 2 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 3 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 4 , x + dx , y + dy , z + dz dx = -30 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 5 , x + dx , y + dy , z + dz dx = 0 : dy = -30 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 6 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -3 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) s.tel( i ) = s.tel( i ) - 1 if x + dx < winx / 3 and x + dx > 0 - winx / 3 _ and y + dy < winy / 3 and y + dy > 0 - winy / 3 _ and z + dz < winx / 3 and z + dz > 0 - winx / 3 then if s.tel( i ) < 0 then s.tel( i ) = range( 3 , 9 ) s.state$( i ) = _ word$( "left right up down q" , int( range( 1 , 5 ) ) ) end if end if if x + dx < 0-winx/3 or x + dx > winx/3 _ or z + dz < 0-winx/3 or z + dz > winx/3 then s.state$( i ) = "left" s.tel( i ) = 0 end if if y + dy < 0-winy/3 then s.state$( i ) = "up" s.tel( i ) = 0 end if if y + dy > winy/3 then s.state$( i ) = "down" s.tel( i ) = 0 end if select case s.state$( i ) case "left" s.pan( i ) = s.pan( i ) + 3 case "right" s.pan( i ) = s.pan( i ) - 3 case "up" if s.tilt( i ) < 30 then '' s.tilt( i ) = s.tilt( i ) + 5 end if case "down" if s.tilt( i ) > 30 then '' s.tilt( i ) = s.tilt( i ) - 5 end if case else end select call sprite3d.xyz i , x + dx , y + dy , z + dz next i scan ''do not change below this line ''sort sphere's for high = 1 to s.max for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''put spehere's on screen for i = 0 to s.max factor = s.z( ry( i ) ) + 1000 x = int( winx / 2 + s.x( ry( i ) ) / factor * 1000 ) y = int( winy / 2 - s.y( ry( i ) ) / factor * 1000 ) size = int( 100 / factor * 1000 ) dx = int( sprite.width / 2 / factor * 1000 ) dy = int( sprite.height / 2 / factor * 1000 ) #m "spritescale spr" ; ry( i ) ; " " ; size #m "spritetoback spr" ; ry( i ) #m "spritexy spr" ; ry( i ) ; " " ; x - dx ; " " ; y - dy next i #m "drawsprites" angle = angle + 5 wait [quit] close #m end sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function range( l , h ) range = rnd(0) * ( h - l ) + l end function function rad( deg ) rad = deg * pi / 180 end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
''bluatigr 2 may 2018 ''sprite3d module
sub sprite3d.add no , bmp$ #m "addsprite spr" ; no ; " " ; bmp$ end sub
sub sprite3d.xyz no , x , y , z s.x( no ) = x s.y( no ) = y s.z( no ) = z end sub
sub sprite3d.get.xyz no , byref x , byref y , byref z x = s.x( no ) y = s.y( no ) z = s.z( no ) end sub
''bluatigro 26 apr 2018 ''sprite module
[sprite] global sprite.width , sprite.height return
sub sprite.clear w , h #m "fill white" #m "goto 0 " ; h #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled " ; w ; " " ; h * 2 #m "up" sprite.width = w sprite.height = h end sub
sub sprite.triangle x1 , y1 , x2 , y2 , x3 , y3 , clr$ if y1 = y2 then y1 = y1 - 1e-10 if y2 = y3 then y3 = y3 + 1e-10 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if call sprite.line a , i + sprite.height _ , b , i + sprite.height , clr$ , 1 call sprite.line a , i , b , i , "black" , 1 next i #m "flush" end sub
sub sprite.rectangle x1,y1,x2,y2,clr$ #m "goto " ; x1 ; " " ; y1 #m "size 1" #m "color black" #m "backcolor black" #m "down" #m "boxfilled " ; x2 ; " " ; y2 #m "up" #m "goto " ; x1 ; " " ; y1 + sprite.height #m "color " ; clr$ #m "backcolor " ; clr$ #m "down" #m "boxfilled " ; x2 ; " " ; y2 + 60 #m "up" end sub
sub sprite.ellipse x,y,dx,dy,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "ellipsefilled " ; dx ; " " ; dy #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "ellipsefilled " ; dx ; " " ; dy #m "up" end sub
sub sprite.pie x,y,dx,dy,a,b,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" end sub
sub sprite.line x1,y1 , x2,y2 , clr$ , size #m "color black" #m "size " ; size #m "down" #m "line " ; x1 ; " " ; y1 _ ; " " ; x2 ; " " ; y2 #m "up" #m "color " ; clr$ #m "down" #m "line " ; x1 ; " " ; y1 + sprite.height _ ; " " ; x2 ; " " ; y2 + sprite.height #m "up" end sub
sub sprite.getbmp bmp$ #m "getbmp " ; bmp$ ; " 0 0 " _ ; sprite.width ; " " ; sprite.height * 2 end sub
|
|
|
Post by bluatigro on May 2, 2018 19:04:14 GMT
update : fish like boid's
WARNING : activating the timer wil somtimes crash the code !!
''bluatigro 2 may 2018 ''boid's whit pecspertive 3d sprites
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , angle , pi , s.max winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 8 * 20 - 1 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) , ry( s.max ) dim s.pan( s.max ) , s.tilt( s.max ) , s.rol( s.max ) dim s.state$( s.max ) , s.tel( s.max ) nomainwin gosub [sprite] open "fish scool boid's 3D sim 0.5" for graphics as #m #m "trapclose [quit]" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "green" , "green" , 1 call sprite.getbmp "prey" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "red" , "red" , 1 call sprite.getbmp "predator" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "red" , "red" , 1 call sprite.getbmp "red" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "green" , "green" , 1 call sprite.getbmp "green" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "yellow" , "yellow" , 1 call sprite.getbmp "y" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "blue" , "blue" , 1 call sprite.getbmp "blue" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "cyan" , "cyan" , 1 call sprite.getbmp "cyan" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "pink" , "pink" , 1 call sprite.getbmp "magenta" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 15,15 , "black" , "black" , 1 call sprite.ellipse 47,47 , 5,5 , "white" , "white" , 1 call sprite.getbmp "eye" bmp$ = "predator red green y eye cyan magenta eye y y " for i = 0 to 9 call sprite3d.add i , word$( bmp$ , ( i mod 10 ) + 1 ) next i bmp$ = "prey red green y eye cyan magenta eye y y" for i = 10 to s.max call sprite3d.add i , word$( bmp$ , ( i mod 10 ) + 1 ) next i for i = 0 to s.max ry( i ) = i ''create world s.x( i ) = range( 0-winx/3 , winx/3 ) s.y( i ) = range( 0-winy/3 , winy/3 ) s.z( i ) = range( 0-winx/3 , winx/3 ) s.pan( i ) = range( 0 , 360 ) s.tilt( i ) = range( -30 , 30 ) s.rol( i ) = range( -30 , 30 ) next i #m "fill blue" #m "getbmp screen 0 0 1 1" #m "background screen" '' timer 40 , [timer] ''wait ''[timer] for i = 0 to s.max - 9 step 10 call sprite3d.get.xyz i , x , y , z dx = 25 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 1 , x + dx , y + dy , z + dz dx = 0 : dy = 25 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 2 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = 25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 3 , x + dx , y + dy , z + dz dx = 0 : dy = 7 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 8 , x + dx , y + dy , z + dz dx = 0 : dy = -7 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 9 , x + dx , y + dy , z + dz dx = 10 : dy = 0 : dz = -25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 7 , x + dx , y + dy , z + dz dx = -10 : dy = 0 : dz = -25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 4 , x + dx , y + dy , z + dz dx = -25 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 5 , x + dx , y + dy , z + dz dx = 0 : dy = -25 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 6 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -3 call rotate dx , dz , s.pan( i ) '' call rotate dy , dz , s.tilt( i ) s.tel( i ) = s.tel( i ) - 1 if x + dx < winx / 3 and x + dx > 0 - winx / 3 _ and y + dy < winy / 3 and y + dy > 0 - winy / 3 _ and z + dz < winx / 3 and z + dz > 0 - winx / 3 then if s.tel( i ) < 0 then s.tel( i ) = range( 3 , 9 ) s.state$( i ) = _ word$( "left right up down q" , int( range( 1 , 5 ) ) ) end if end if if x + dx < 0-winx/3 or x + dx > winx/3 _ or z + dz < 0-winx/3 or z + dz > winx/3 then s.state$( i ) = "left" end if if y + dy < 0-winy/3 then s.state$( i ) = "up" end if if y + dy > winy/3 then s.state$( i ) = "down" end if select case s.state$( i ) case "left" s.pan( i ) = s.pan( i ) + 3 case "right" s.pan( i ) = s.pan( i ) - 3 case "up" if s.tilt( i ) < 30 then '' s.tilt( i ) = s.tilt( i ) + 5 end if case "down" if s.tilt( i ) > 30 then '' s.tilt( i ) = s.tilt( i ) - 5 end if case else end select call sprite3d.xyz i , x + dx , y + dy , z + dz next i scan ''do not change below this line ''sort sphere's for high = 1 to s.max for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''put spehere's on screen for i = 0 to s.max factor = s.z( ry( i ) ) + 1000 x = int( winx / 2 + s.x( ry( i ) ) / factor * 1000 ) y = int( winy / 2 - s.y( ry( i ) ) / factor * 1000 ) size = int( 100 / factor * 1000 ) dx = int( sprite.width / 2 / factor * 1000 ) dy = int( sprite.height / 2 / factor * 1000 ) #m "spritescale spr" ; ry( i ) ; " " ; size #m "spritetoback spr" ; ry( i ) #m "spritexy spr" ; ry( i ) ; " " ; x - dx ; " " ; y - dy next i #m "drawsprites" angle = angle + 5 wait [quit] close #m end sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function range( l , h ) range = rnd(0) * ( h - l ) + l end function function rad( deg ) rad = deg * pi / 180 end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
''bluatigr 2 may 2018 ''sprite3d module
sub sprite3d.add no , bmp$ #m "addsprite spr" ; no ; " " ; bmp$ end sub
sub sprite3d.xyz no , x , y , z s.x( no ) = x s.y( no ) = y s.z( no ) = z end sub
sub sprite3d.get.xyz no , byref x , byref y , byref z x = s.x( no ) y = s.y( no ) z = s.z( no ) end sub
''bluatigro 26 apr 2018 ''sprite module
[sprite] global sprite.width , sprite.height return
sub sprite.clear w , h #m "fill white" #m "goto 0 " ; h #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled " ; w ; " " ; h * 2 #m "up" sprite.width = w sprite.height = h end sub
sub sprite.triangle x1 , y1 , x2 , y2 , x3 , y3 , clr$ if y1 = y2 then y1 = y1 - 1e-10 if y2 = y3 then y3 = y3 + 1e-10 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if call sprite.line a , i + sprite.height _ , b , i + sprite.height , clr$ , 1 call sprite.line a , i , b , i , "black" , 1 next i #m "flush" end sub
sub sprite.rectangle x1,y1,x2,y2,clr$ #m "goto " ; x1 ; " " ; y1 #m "size 1" #m "color black" #m "backcolor black" #m "down" #m "boxfilled " ; x2 ; " " ; y2 #m "up" #m "goto " ; x1 ; " " ; y1 + sprite.height #m "color " ; clr$ #m "backcolor " ; clr$ #m "down" #m "boxfilled " ; x2 ; " " ; y2 + 60 #m "up" end sub
sub sprite.ellipse x,y,dx,dy,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "ellipsefilled " ; dx ; " " ; dy #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "ellipsefilled " ; dx ; " " ; dy #m "up" end sub
sub sprite.pie x,y,dx,dy,a,b,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" end sub
sub sprite.line x1,y1 , x2,y2 , clr$ , size #m "color black" #m "size " ; size #m "down" #m "line " ; x1 ; " " ; y1 _ ; " " ; x2 ; " " ; y2 #m "up" #m "color " ; clr$ #m "down" #m "line " ; x1 ; " " ; y1 + sprite.height _ ; " " ; x2 ; " " ; y2 + sprite.height #m "up" end sub
sub sprite.getbmp bmp$ #m "getbmp " ; bmp$ ; " 0 0 " _ ; sprite.width ; " " ; sprite.height * 2 end sub
|
|
|
Post by bluatigro on May 3, 2018 12:01:46 GMT
update : i changed the keep in screen code
rem : it shoot not crash but it does somtimes
''bluatigro 3 may 2018 ''boid's whit pecspertive 3d sprites
WindowWidth = DisplayWidth WindowHeight = DisplayHeight global winx , winy , angle , pi , s.max winx = WindowWidth winy = WindowHeight pi = atn( 1 ) * 4 s.max = 8 * 20 - 1 dim s.x( s.max ) , s.y( s.max ) , s.z( s.max ) , ry( s.max ) dim s.pan( s.max ) , s.tilt( s.max ) , s.rol( s.max ) dim s.state$( s.max ) , s.tel( s.max ) nomainwin gosub [sprite] open "fish scool boid's 3D sim 0.5" for graphics as #m #m "trapclose [quit]" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "green" , "green" , 1 call sprite.getbmp "prey" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 40,40 , "red" , "red" , 1 call sprite.getbmp "predator" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "red" , "red" , 1 call sprite.getbmp "red" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "green" , "green" , 1 call sprite.getbmp "green" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "yellow" , "yellow" , 1 call sprite.getbmp "y" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "blue" , "blue" , 1 call sprite.getbmp "blue" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "cyan" , "cyan" , 1 call sprite.getbmp "cyan" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 10,10 , "pink" , "pink" , 1 call sprite.getbmp "magenta" call sprite.clear 100 , 100 call sprite.ellipse 50,50 , 15,15 , "black" , "black" , 1 call sprite.ellipse 47,47 , 5,5 , "white" , "white" , 1 call sprite.getbmp "eye" bmp$ = "predator red green y eye cyan magenta eye y y " for i = 0 to 9 call sprite3d.add i , word$( bmp$ , ( i mod 10 ) + 1 ) next i bmp$ = "prey red green y eye cyan magenta eye y y" for i = 10 to s.max call sprite3d.add i , word$( bmp$ , ( i mod 10 ) + 1 ) next i for i = 0 to s.max ry( i ) = i ''create world s.x( i ) = range( 0-winx/3 , winx/3 ) s.y( i ) = range( 0-winy/3 , winy/3 ) s.z( i ) = range( 0-winx/3 , winx/3 ) s.pan( i ) = range( 0 , 360 ) s.tilt( i ) = range( -30 , 30 ) s.rol( i ) = range( -30 , 30 ) next i #m "fill blue" #m "getbmp screen 0 0 1 1" #m "background screen" timer 40 , [timer] wait [timer] for i = 0 to s.max - 9 step 10 call sprite3d.get.xyz i , x , y , z dx = 25 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 1 , x + dx , y + dy , z + dz dx = 0 : dy = 25 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 2 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = 25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 3 , x + dx , y + dy , z + dz dx = 0 : dy = 7 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 8 , x + dx , y + dy , z + dz dx = 0 : dy = -7 : dz = 30 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 9 , x + dx , y + dy , z + dz dx = 10 : dy = 0 : dz = -25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 7 , x + dx , y + dy , z + dz dx = -10 : dy = 0 : dz = -25 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 4 , x + dx , y + dy , z + dz dx = -25 : dy = 0 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 5 , x + dx , y + dy , z + dz dx = 0 : dy = -25 : dz = 0 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) call sprite3d.xyz i + 6 , x + dx , y + dy , z + dz dx = 0 : dy = 0 : dz = -3 call rotate dx , dz , s.pan( i ) call rotate dy , dz , s.tilt( i ) call rotate dx , dy , s.rol( i ) s.tel( i ) = s.tel( i ) - 1 if s.tel( i ) < 0 then s.tel( i ) = range( 3 , 9 ) s.state$( i ) = _ word$( "left right up down q" , int( range( 1 , 5 ) ) ) end if if x < 0 - winx / 3 then x = winx / 3 if x > winx / 3 then x = 0 - winx / 3 if y < 0 - winy / 3 then y = winy / 3 if y > winy / 3 then y = 0 - winy / 3 if z < 0 - winx / 3 then z = winx / 3 if z > winx / 3 then z = 0 - winx / 3 select case s.state$( i ) case "left" s.pan( i ) = s.pan( i ) + 3 case "right" s.pan( i ) = s.pan( i ) - 3 case "up" if s.tilt( i ) < 30 then '' s.tilt( i ) = s.tilt( i ) + 5 end if case "down" if s.tilt( i ) > 30 then '' s.tilt( i ) = s.tilt( i ) - 5 end if case else end select call sprite3d.xyz i , x + dx , y + dy , z + dz next i scan ''do not change below this line ''sort sphere's for high = 1 to s.max for low = 0 to high - 1 if s.z( ry( high ) ) < s.z( ry( low ) ) then help = ry( high ) ry( high ) = ry( low ) ry( low ) = help end if next low next high ''put spehere's on screen for i = 0 to s.max factor = s.z( ry( i ) ) + 1000 x = int( winx / 2 + s.x( ry( i ) ) / factor * 1000 ) y = int( winy / 2 - s.y( ry( i ) ) / factor * 1000 ) size = int( 100 / factor * 1000 ) dx = int( sprite.width / 2 / factor * 1000 ) dy = int( sprite.height / 2 / factor * 1000 ) #m "spritescale spr" ; ry( i ) ; " " ; size #m "spritetoback spr" ; ry( i ) #m "spritexy spr" ; ry( i ) ; " " ; x - dx ; " " ; y - dy next i #m "drawsprites" angle = angle + 5 wait [quit] close #m end sub rotate byref k , byref l , deg s = sin( rad( deg ) ) c = cos( rad( deg ) ) hk = k * c - l * s hl = k * s + l * c k = hk l = hl end sub function range( l , h ) range = rnd(0) * ( h - l ) + l end function function rad( deg ) rad = deg * pi / 180 end function function rgb$( r , g , b ) r = int( r ) and 255 g = int( g ) and 255 b = int( b ) and 255 rgb$ = str$( r ) ; " " ; g ; " " ; b end function function rainbow$( deg ) r = sin( rad( deg ) ) * 127 + 128 g = sin( rad( deg - 120 ) ) * 127 + 128 b = sin( rad( deg + 120 ) ) * 127 + 128 rainbow$ = rgb$( r , g , b ) end function
''bluatigr 2 may 2018 ''sprite3d module
sub sprite3d.add no , bmp$ #m "addsprite spr" ; no ; " " ; bmp$ end sub
sub sprite3d.xyz no , x , y , z s.x( no ) = x s.y( no ) = y s.z( no ) = z end sub
sub sprite3d.get.xyz no , byref x , byref y , byref z x = s.x( no ) y = s.y( no ) z = s.z( no ) end sub
''bluatigro 26 apr 2018 ''sprite module
[sprite] global sprite.width , sprite.height return
sub sprite.clear w , h #m "fill white" #m "goto 0 " ; h #m "size 1" #m "down" #m "color black" #m "backcolor black" #m "boxfilled " ; w ; " " ; h * 2 #m "up" sprite.width = w sprite.height = h end sub
sub sprite.triangle x1 , y1 , x2 , y2 , x3 , y3 , clr$ if y1 = y2 then y1 = y1 - 1e-10 if y2 = y3 then y3 = y3 + 1e-10 if y1 > y3 then h = y1 y1 = y3 y3 = h h = x1 x1 = x3 x3 = h end if if y1 > y2 then h = y1 y1 = y2 y2 = h h = x1 x1 = x2 x2 = h end if if y2 > y3 then h = y2 y2 = y3 y3 = h h = x2 x2 = x3 x3 = h end if for i = y1 to y3 a = x1 + ( x3 - x1 ) * (i-y1) / ( y3 - y1 ) if i < y2 then b = x1 + ( x2 - x1 ) * (i-y1) / ( y2 - y1 ) else b = x2 + ( x3 - x2 ) * (i-y2) / ( y3 - y2 ) end if call sprite.line a , i + sprite.height _ , b , i + sprite.height , clr$ , 1 call sprite.line a , i , b , i , "black" , 1 next i #m "flush" end sub
sub sprite.rectangle x1,y1,x2,y2,clr$ #m "goto " ; x1 ; " " ; y1 #m "size 1" #m "color black" #m "backcolor black" #m "down" #m "boxfilled " ; x2 ; " " ; y2 #m "up" #m "goto " ; x1 ; " " ; y1 + sprite.height #m "color " ; clr$ #m "backcolor " ; clr$ #m "down" #m "boxfilled " ; x2 ; " " ; y2 + 60 #m "up" end sub
sub sprite.ellipse x,y,dx,dy,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "ellipsefilled " ; dx ; " " ; dy #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "ellipsefilled " ; dx ; " " ; dy #m "up" end sub
sub sprite.pie x,y,dx,dy,a,b,clr$,bclr$,size #m "goto " ; x ; " " ; y #m "size " ; size #m "down" #m "color black" #m "backcolor black" #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" #m "goto " ; x ; " " ; y + sprite.height #m "down" #m "color " ; clr$ #m "backcolor " ; bclr$ #m "piefilled " ; dx ; " " ; dy _ ; " " ; a ; " " ; b #m "up" end sub
sub sprite.line x1,y1 , x2,y2 , clr$ , size #m "color black" #m "size " ; size #m "down" #m "line " ; x1 ; " " ; y1 _ ; " " ; x2 ; " " ; y2 #m "up" #m "color " ; clr$ #m "down" #m "line " ; x1 ; " " ; y1 + sprite.height _ ; " " ; x2 ; " " ; y2 + sprite.height #m "up" end sub
sub sprite.getbmp bmp$ #m "getbmp " ; bmp$ ; " 0 0 " _ ; sprite.width ; " " ; sprite.height * 2 end sub
|
|