This shows you the differences between two versions of the page.
graphicsutilitiesstamp2sprite [2016/01/12 10:12] renejm |
graphicsutilitiesstamp2sprite [2020/02/28 10:46] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{graphicsutilitiesstamp2sprite.png? | ||
- | Subroutine to draw a stamp on the screen and then capture it as a sprite. | ||
- | With 1.0.0.0 this fancy code is no longer needed. | ||
- | < | ||
- | # stamp2sprite.kbs | ||
- | # convert a stamp into a sprite | ||
- | # will clear screen so do this first | ||
- | # 2013-01-06 j.m.reneau | ||
- | # requires BASIC-256 0.9.9.28 or higher | ||
- | |||
- | fastgraphics | ||
- | dim s(1) | ||
- | #square | ||
- | #s = {10, | ||
- | #ghost | ||
- | s = {2,-10, -2,-10, -5,-9, -6,-8, -7,-5, -2,-5, -2,-3, -4,-3, -4,-5, -7,-5, -7,9, -6,7, -5,9, -4,7, -3,9, -2,7, -1,9, 0,7, 1,9, 2,7, 3,9, 4,7, 5,9, 6,7, 7,9, 7,3, -3,3, -3,2, 3,2, 3,3, 7,3, 7,-5, 4,-5, 4,-3, 2,-3, 2,-5, 7,-5, 6,-8, 5,-9 } | ||
- | spritedim 4 | ||
- | penwidth 1 | ||
- | call stamp2sprite(0, | ||
- | penwidth 2 | ||
- | call stamp2sprite(1, | ||
- | penwidth 3 | ||
- | call stamp2sprite(2, | ||
- | penwidth 4 | ||
- | call stamp2sprite(3, | ||
- | |||
- | print "press any key to stop" | ||
- | |||
- | color black | ||
- | rect 0,0,300,300 | ||
- | |||
- | dim dx(4) | ||
- | dim dy(4) | ||
- | for t = 0 to 3 | ||
- | dx[t] = 1 | ||
- | dy[t] = 1 | ||
- | | ||
- | | ||
- | next t | ||
- | |||
- | while key = 0 | ||
- | for t = 0 to 3 | ||
- | spritemove t, dx[t], dy[t] | ||
- | if spritex(t) <= 0 or spritex(t)> | ||
- | if spritey(t) <= 0 or spritey(t)> | ||
- | next t | ||
- | | ||
- | end while | ||
- | |||
- | end | ||
- | |||
- | subroutine stamp2sprite(spriteno, | ||
- | # DRAW A STAMP ON THE SCREEN WITH SPECIFIED COLORS AND SCALE AND | ||
- | # CAPTURE IT AS A SPRITE | ||
- | minx = points[0] | ||
- | miny = points[1] | ||
- | maxx = points[0] | ||
- | maxy = points[1] | ||
- | for t = 1 to points[? | ||
- | if points[t*2] < minx then minx = points[t*2] | ||
- | if points[t*2] > maxx then maxx = points[t*2] | ||
- | if points[t*2+1] < miny then miny = points[t*2+1] | ||
- | if points[t*2+1] > maxy then maxy = points[t*2+1] | ||
- | next t | ||
- | w = (maxx-minx)*scale + getpenwidth | ||
- | h = (maxy-miny)*scale + getpenwidth | ||
- | x = minx*-scale | ||
- | y = miny*-scale | ||
- | clg | ||
- | color backgroundcolor | ||
- | rect 0,0,w,h | ||
- | color pencolor, brushcolor | ||
- | stamp x, | ||
- | | ||
- | | ||
- | end subroutine | ||
- | |||
- | |||
- | </ | ||