January 15, 2021, 06:21:50 PM

Author Topic: [bb] Random & Graphics by chwaga [ 1+ years ago ]  (Read 490 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Random & Graphics by chwaga [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : Random & Graphics
Author : chwaga
Posted : 1+ years ago

Description : Not quite finished, but a lot can be learned from it.  It utilizes tons of Rnd commands, texturebuffering on a 3d phase, and examples of using loops inside loops(inside loops?!).  Unfortunately, it's incomplete and i left a ton of unfinished code changed to comments.  The pixels drawn randomly on phase 1 and 2 could be more efficiently drawn with the for ... next code, I'll do that later.  
I added a few comments for newbie's to learn from...kinda.

Post any questions, comments, add-ons (Try to keep it media-free!)

Hope you guys have fun with it.


Code :
Code: BlitzBasic
  1. AppTitle "Time Waster"
  2.  
  3. Graphics 1280,1024,32,2
  4.  
  5. SeedRnd MilliSecs()
  6. Global n=0
  7. ;SORRY FOR THE CRYPTIC VARIABLE NAMES
  8. ;oldx
  9. Global ox
  10. ;oldy
  11. Global oy
  12. ;newx
  13. Global nx=640
  14. ;newy
  15. Global ny=512
  16. ;etch-e-sketch mode
  17. Global ees=False
  18. ;keyx (etch-e-sketch)
  19. Global kx=640
  20. ;keyy (etch-e-sketch)
  21. Global ky=512
  22. ;font...for some reason i had to repeat the font=loadfont() thing every time i changed graphics-mode
  23. Global font=LoadFont("Arial",36,1,0,0)
  24. ;incomplete
  25. Global s
  26. ;linex1
  27. Global lx1=Rnd(0,1280)
  28. ;liney1
  29. Global ly1=Rnd(0,1024)
  30. ;linex2
  31. Global lx2=Rnd(0,1280)
  32. ;liney2
  33. Global ly2=Rnd(0,1024)
  34. ;line drawing speed
  35. Global speed=50
  36. ;set the font
  37. SetFont font
  38.  
  39.  
  40. Print "WELCOME TO THE TIME-WASTER"
  41. Print "PRESS ANY KEY (except escape) TO CONTINUE"
  42. Print "FOLLOW GIVEN DIRECTIONS PER 'PHASE' AND"
  43. Print "PRESS THE ESCAPE KEY To CONTINUE To THE Next PHASE"
  44. Print "AT ANY TIME PRESS F10 TO TAKE A SCREENSHOT (named 'screenshot.bmp')
  45. Print "PRESS KEYS 1-7 TO SWITCH AROUND THE PROGRAM & PHASES"
  46. Print "0 to exit"
  47. WaitKey
  48.  
  49. .phase1
  50. While Not KeyHit(1)
  51.         Text 500,950,"PHASE ONE"
  52.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  53.         Rect Rnd(0,1280),Rnd(0,1024),Rnd(0,1280),Rnd(0,1024),Rnd(0,1)
  54.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  55. ;every time you see the below goto's, its the code set to use keys 1-7 and 0 to jump around the program using labels
  56.         If KeyHit(2) Then Goto phase1
  57.         If KeyHit(3) Then Goto phase2
  58.         If KeyHit(4) Then Goto phase3
  59.         If KeyHit(5) Then Goto phase4
  60.         If KeyHit(6) Then Goto phase5
  61.         If KeyHit(7) Then Goto phase6
  62.         If KeyHit(8) Then Goto phase7
  63.         If KeyHit(11) Then Goto el
  64.  
  65.  
  66.  
  67.         For n=0 To 1000
  68.                 WritePixel Rnd(0,1280),Rnd(0,1024),ReadPixel(Rnd(0,1280),Rnd(0,1024))
  69.                 n=n+1
  70.  
  71.         Next
  72. n=0
  73. Wend
  74. n=0
  75.  
  76.  
  77. .phase2
  78. Cls
  79. While Not KeyHit(1)
  80.         If KeyHit(2) Then Goto phase1
  81.         If KeyHit(3) Then Goto phase2
  82.         If KeyHit(4) Then Goto phase3
  83.         If KeyHit(5) Then Goto phase4
  84.         If KeyHit(6) Then Goto phase5
  85.         If KeyHit(7) Then Goto phase6
  86.         If KeyHit(8) Then Goto phase7
  87.         If KeyHit(11) Then Goto el
  88.         Text 500,950,"PHASE TWO"
  89.         WritePixel Rnd(0,1280),Rnd(0,1024),ReadPixel(401,401)
  90.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  91.         Rect 400,400,500,500,1
  92.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  93.  
  94. Wend
  95.  
  96.  
  97. .phase3
  98. Cls
  99. While Not KeyHit(1)
  100.         If KeyHit(2) Then Goto phase1
  101.         If KeyHit(3) Then Goto phase2
  102.         If KeyHit(4) Then Goto phase3
  103.         If KeyHit(5) Then Goto phase4
  104.         If KeyHit(6) Then Goto phase5
  105.         If KeyHit(7) Then Goto phase6
  106.         If KeyHit(8) Then Goto phase7
  107.         If KeyHit(11) Then Goto el
  108.         Text 500,950,"PHASE THREE"
  109.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  110.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  111.  
  112.  
  113.         For n=0 To 1000
  114.                 WritePixel Rnd(0,1280),Rnd(0,1024),ReadPixel(Rnd(0,1280),Rnd(0,1024))
  115.                 n=n+1
  116.  
  117.         Next
  118.         Oval Rnd(0,1280),Rnd(0,1024),Rnd(0,1280),Rnd(0,1024),Rnd(0,1)
  119.  
  120.         Delay 16.666
  121.  
  122. Wend
  123.  
  124.  
  125.  
  126. .phase4
  127. Cls
  128. While Not KeyHit(1)
  129.         Text 500,950,"PHASE FOUR"
  130.         If KeyHit(2) Then Goto phase1
  131.         If KeyHit(3) Then Goto phase2
  132.         If KeyHit(4) Then Goto phase3
  133.         If KeyHit(5) Then Goto phase4
  134.         If KeyHit(6) Then Goto phase5
  135.         If KeyHit(7) Then Goto phase6
  136.         If KeyHit(8) Then Goto phase7
  137.         If KeyHit(11) Then Goto el
  138.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  139.         Rect Rnd(0,1280),Rnd(0,1024),Rnd(0,1280),Rnd(0,1024),Rnd(0,1)
  140.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  141.  
  142.  
  143.         For n=0 To 1000
  144.                 WritePixel Rnd(0,1280),Rnd(0,1024),ReadPixel(Rnd(0,1280),Rnd(0,1024))
  145.                 n=n+1
  146.  
  147.         Next
  148.         n=0
  149.         Oval Rnd(0,1280),Rnd(0,1024),Rnd(0,1280),Rnd(0,1024),Rnd(0,1)
  150.  
  151. Wend
  152.  
  153. .phase5
  154. Cls
  155. MoveMouse 640,512
  156.  
  157. While Not KeyHit(1)
  158.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  159.  
  160.  
  161.         Text 500,0,"PRESS THE SPACE-BAR TO CLEAR THE SCREEN"
  162.         Text 400,40,"PRESS ENTER TO ENTER/EXIT ETCH-E-SKETCH MODE"
  163.         Text 500,950,"PHASE FIVE"
  164.         If KeyHit(2) Then Goto phase1
  165.         If KeyHit(3) Then Goto phase2
  166.         If KeyHit(4) Then Goto phase3
  167.         If KeyHit(5) Then Goto phase4
  168.         If KeyHit(6) Then Goto phase5
  169.         If KeyHit(7) Then Goto phase6
  170.         If KeyHit(8) Then Goto phase7
  171.         If KeyHit(11) Then Goto el
  172.  
  173.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  174.         Rect 0,0,1,1,1
  175.  
  176.         If Not KeyDown(20) And ees=False
  177.                 ox=MouseX()
  178.                 oy=MouseY()
  179.  
  180.                 connect
  181.                 nx=MouseX()
  182.                 ny=MouseY()
  183.                 connect
  184.  
  185.         EndIf
  186.  
  187.         If KeyHit(28) And ees=False Then
  188.                 ees=True
  189.                 Cls
  190.         Else If ees=True And KeyHit(28)
  191.                 ees=False
  192.         EndIf
  193.  
  194.         While ees=True
  195.                 Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  196.                 Rect 0,0,1,1,1
  197.  
  198.  
  199.                 WritePixel kx,ky,ReadPixel(0,0)
  200.                 If KeyDown(200) Then ky=ky-1
  201.                 If KeyDown(208) Then ky=ky+1
  202.                 If KeyDown(203) Then kx=kx-1
  203.                 If KeyDown(205) Then kx=kx+1
  204.  
  205.                 Delay 10
  206.                 If KeyHit(28) Then
  207.                         ees=False
  208.                         Cls
  209.                 EndIf
  210.  
  211.         Wend
  212.  
  213.  
  214.  
  215.         If KeyHit(57) Then Cls
  216.  
  217. Wend
  218.  
  219. .phase6
  220.  
  221. Cls
  222. Graphics3D 1280,1024,32,2
  223. SetBuffer BackBuffer()
  224. font=LoadFont("Arial",36,1,0,0)
  225.  
  226. SetFont font
  227.  
  228. ;While Not KeyHit(1)
  229.  
  230. campivot=CreatePivot()
  231. PositionEntity campivot,0,0,0
  232. camera=CreateCamera(campivot)
  233. PositionEntity camera,0,0,-10
  234.  
  235. ;EntityParent camera,campivot
  236.  
  237. light=CreateLight()
  238. PositionEntity light,30,70,0
  239.  
  240. cube=CreateCube()
  241. PositionEntity cube,0,0,0
  242.  
  243. cube2=CreateCube()
  244. PositionEntity cube2,0,30,0
  245. ScaleEntity cube2,50,50,50
  246.  
  247. sphere=CreateSphere(20)
  248. PositionEntity sphere,5,0,0
  249.  
  250. cone=CreateCone()
  251. PositionEntity cone,-5,0,0
  252.  
  253. FlipMesh cube2
  254.  
  255.  
  256. tex=CreateTexture(256,256)
  257. EntityTexture cube,tex
  258. EntityTexture sphere,tex
  259. EntityTexture cone,tex
  260. EntityTexture cube2,tex
  261.  
  262. While Not KeyHit(1)
  263.         If KeyHit(2) Then Goto phase1
  264.         If KeyHit(3) Then Goto phase2
  265.         If KeyHit(4) Then Goto phase3
  266.         If KeyHit(5) Then Goto phase4
  267.         If KeyHit(6) Then Goto phase5
  268.         If KeyHit(7) Then Goto phase6
  269.         If KeyHit(8) Then Goto phase7
  270.         If KeyHit(11) Then Goto el
  271.         If KeyHit(68) Then SaveBuffer(FrontBuffer(),"screenshot.bmp")
  272.  
  273.  
  274.         If KeyDown(203) Then TurnEntity campivot,0,1,0
  275.         If KeyDown(205) Then TurnEntity campivot,0,-1,0
  276.  
  277.  
  278.  
  279. ;EVERYTHING FROM HERE TO RESETTING TO BACKBUFFER IS PUT INSIDE THE TEXTURE tex
  280.         SetBuffer TextureBuffer(tex)
  281.                 Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  282.                 Rect Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,1)
  283.                 Oval Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,256),Rnd(0,1)
  284.  
  285.         SetBuffer BackBuffer()
  286.  
  287.         TurnEntity cube,3,3,3
  288.         TurnEntity sphere,-4,-3,-2
  289.         TurnEntity cone,-3,3,-3
  290.  
  291.  
  292. RenderWorld
  293.         Text 500,950,"PHASE SIX"
  294.  
  295.         If Not KeyDown(20)  
  296.                 ox=MouseX()
  297.                 oy=MouseY()
  298.  
  299.                 connect
  300.                 nx=MouseX()
  301.                 ny=MouseY()
  302.                 connect
  303.  
  304.         EndIf
  305.  
  306.  
  307. Flip
  308. Wend
  309.  
  310.  
  311. .phase7
  312. Cls
  313.  
  314.  
  315. Graphics 1280,1024,32,2
  316. font=LoadFont("Arial",36,1,0,0)
  317.  
  318. SetFont font
  319. While Not KeyHit(1)
  320.         If KeyHit(2) Then Goto phase1
  321.         If KeyHit(3) Then Goto phase2
  322.         If KeyHit(4) Then Goto phase3
  323.         If KeyHit(5) Then Goto phase4
  324.         If KeyHit(6) Then Goto phase5
  325.         If KeyHit(7) Then Goto phase6
  326.         If KeyHit(8) Then Goto phase7
  327.         If KeyHit(11) Then Goto el
  328.         If KeyHit(68) Then
  329.                 SaveBuffer(BackBuffer(),"screenshot.bmp")
  330.         EndIf
  331.  
  332.         Color Rnd(0,255),Rnd(0,255),Rnd(0,255)
  333.         Text 500,0,"PRESS THE SPACE-BAR TO CLEAR THE SCREEN"
  334.         Text 400,40,"PRESS NUM + AND NUM - TO DECREASE AND INCREASE "
  335.         Text 500,80,"THE SPEED THAT THE LINES DRAW AT"
  336.         Text 0,0,"DRAWING SPEED = "+speed
  337.         Text 0,40,"(low is fast :D)"
  338.  
  339.         Text 500,950,"PHASE SEVEN"
  340.         lx2=Rnd(0,1280)
  341.         ly2=Rnd(0,1024)
  342.         Line lx1,ly1,lx2,ly2
  343.         lx1=lx2
  344.         ly1=ly2
  345.  
  346.         If KeyDown(78) And speed > 3 Then speed=speed-1
  347.         If KeyDown(74) Then speed=speed+1
  348.  
  349.         If KeyHit(57) Then Cls
  350. Delay speed
  351.  
  352. Wend
  353. .el
  354. End
  355.  
  356.  
  357. ;Cls
  358. ;Graphics3D 1280,1024,32,2
  359. ;SetBuffer BackBuffer()
  360.  
  361.  
  362. Function connect()
  363.  
  364.         Line ox,oy,nx,ny
  365.  
  366. End Function


Comments :


CS_TBL(Posted 1+ years ago)

 Not the best code example for beginners tho. There's no indenting, there're too many globals, and  .. --w000t?-- GOTO and labels? That's so non-procedural. All blitzes are at least procedural languages. Furthermore: why use while/wend loops when FOR is so much easier/clearer? There's no single FOR loop in that whole source! As a whole, I wonder what it's doing in the archives in the first place.No, if I were the pope, I wouldn't bless this one.., -sorry- .. :P There's a lot left to learn, and it's certainly not impossible to become good, however your path currently heads into the wrong direction.


chwaga(Posted 1+ years ago)

 There.  I told you it was messy and stuff at the top.  I added for ... next 's and did indenting.   I don't get what's non-procedural about goto's and labels, it's the best way i can think of for hopping around the program....(the only reason the goto thing is repeated every time is because there's no way to have a global label...as far as i know)


tonyg(Posted 1+ years ago)

 <div class="quote"> I don't get what's non-procedural about goto's and labels, it's the best way i can think of for hopping around the program...  </div>Look at creating functions and I agree with CS_TBL.If I am painfully honest I could believe this uses the worst programming approach as a jape.


chwaga(Posted 1+ years ago)

 well, I'm a noob to b3d myself, and apparently I'm a messy coder, but if you could put up an improvement that i could use to figure out what i did wrong?


tonyg(Posted 1+ years ago)

 How about creating a topic for it in the B3D Beginner's forum?


CS_TBL(Posted 1+ years ago)

 chwaga: everyone has to start at some point. I don't mind people who are slowly progressing, I'm often helping ppl out in the B+ beginners section anyway. The only real problem I'm seeing here is that you've put this code into the archives, which is -according to me- like an section where one can find: 1) functionality that's not in the basic command set of any Blitz, or 2) complete games/demos/things that are written in a way so that they are informative (near-tutorials!). It has happened before that ppl posted your kind of code snippets into the archives, something I completely don't agree on. For those purposes there's a showcase section in the forum. This archives 'forum section' might look like a forum section, but that's only a look-up for the code database, it's very annoying for anyone to have to browse through non-relevant code when searching the archives for something.Something I'd wish is a BRL/nonBRL archives moderator who will move irrelevant entries to other places. Any chance, BRL?If the showcase forum is actually for gfx/games/media, then I propose a "beginner's code" section.


chwaga(Posted 1+ years ago)

 k.  If a moderator can move this out or something, I'd appreciate it


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal