1: 2: 3: rem 4: rem This program demonstrates the use of memory bitmaps. 5: rem 6: rem It prompts for the name of a bitmap file, reads in the file 7: rem and then, using memory bitmaps for speed, moves a 'window' 8: rem around the picture 9: rem 10: 11: if ostype<>2 then 12: print "Program designed for Windows only..." 13: stop 14: end if 15: 16: 17: dim a&(256) 18: maxcolor=system(17) 19: screen 1000,maxcolor 20: 21: rem 22: rem since we are going to store the picture in a memory bitmap 23: rem it is more efficient if we do our own repainting 24: rem 25: on paint gosub 1000 26: 27: rem 28: rem get the name of the file to display 29: rem 30: a$="text"+chr$(0)+"*.bmp"+chr$(0)+chr$(0) 31: openfileread a$,"marble","","Load a Picture" 32: 33: a$=dialog$(102) 34: if a$<>"1" then stop 35: 36: rem 37: rem get here if legal file selected 38: rem 39: 40: ffname$=dialog$(100) 41: 42: 43: 44: rem 45: rem read bitmap header and get info on it 46: rem 47: a=bitmaph(ffname$,a&(0)) 48: x=0 49: y=0 50: pxsize=a&(1) 51: pysize=a&(2) 52: colors=a&(4) 53: if colors=1 or colors=2 then 54: colors=1 55: elseif colors=4 then 56: colors=16 57: else 58: colors=256 59: end if 60: 61: rem 62: rem change our palette to have same colors as files 63: rem 64: rem (except windows in 16 color mode doesn't allow palette changes) 65: rem 66: if maxcolor>16 then 67: a=bitmapc(ffname$,a&(0)) 68: if colors>236 then 69: for i=10 to 245 70: palette i,a&(i) 71: next i 72: else 73: for i=0 to colors 74: palette i,a&(i) 75: next i 76: end if 77: end if 78: 79: rem 80: rem create a bitmap to hold entire image 81: rem 82: createbitmap 1,0,pxsize,pysize 83: 84: 85: rem 86: rem select my memory bitmap and load it in 87: rem 88: selectbitmap 1 89: loadbitmap sd$+ffname$,0,x,y,0,0,pxsize,pysize,0,xmult,ymult 90: 91: rem 92: rem select screen as my output 93: rem 94: selectbitmap 0 95: 96: rem 97: rem select a subset of memory image to display 98: rem 99: 100: dx=0 101: dy=0 102: hx=pxsize/2 103: hy=pysize/2 104: dx=pxsize-hx 105: dy=pysize-hy 106: sy=0 107: xoff=1 108: yoff=1 109: 110: rem 111: rem make my window size of picture to display 112: rem 113: position 1,1,dx-1,dy-1 114: 115: rem 116: rem loop and display a portion of picture 117: rem 118: 50 119: copybits 1,sx,sy,dx,dy,0,0,0,0 120: 121: rem 122: rem delay for a while 123: rem 124: t=timer 125: 75 126: if timer-t<.1 then goto 75 127: 128: 129: rem 130: rem randomly move x and/or y direction 131: rem 132: i=int(rnd*10) 133: if i>4 then 134: if xoff>0 then 135: sx=sx+1 136: else 137: sx=sx-1 138: end if 139: if sx<0 then 140: sx=1 141: xoff=1 142: end if 143: if sx>pxsize-hx then 144: sx=pxsize-hx 145: xoff=0 146: end if 147: goto 50 148: else 149: if yoff>0 then 150: sy=sy+1 151: else 152: sy=sy-1 153: end if 154: if sy<0 then 155: sy=1 156: yoff=1 157: end if 158: if sy>pysize-hy then 159: sy=pysize-hy 160: yoff=0 161: end if 162: goto 50 163: 164: end if 165: goto 50 166: 167: 168: 169: rem 170: rem Since I update the screen often, I will do nothing in repaint. 171: rem 172: 173: 1000 174: return 175: 176: |