File: graphicsutilitiesstamp2sprite.html

package info (click to toggle)
basic256 1.1.4.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,456 kB
  • sloc: cpp: 10,148; yacc: 3,023; java: 1,091; lex: 1,051; sh: 117; xml: 33; makefile: 15
file content (106 lines) | stat: -rw-r--r-- 4,683 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<!DOCTYPE html>
<html lang="en" dir="ltr" class="no-js">
<head>
    <meta charset="utf-8" />
    <title>graphicsutilitiesstamp2sprite [BASIC 256 - Language Documentation]</title>
<link rel="stylesheet" type="text/css" href="lib/exe/cssc171c1dfe8519125bb40a349172b001a.css"/>
    </head>
<body>
    <div id="dokuwiki__site"><div id="dokuwiki__top" class="site dokuwiki mode_show tpl_dokuwiki     ">
<div id="dokuwiki__header"><div class="pad group">
    <div class="headings group">
        <h1><a href="start.html"  accesskey="h" title="[H]"><img src="lib/tpl/dokuwiki/images/logo.png" width="64" height="64" alt="" /> <span>BASIC 256 - Language Documentation</span></a></h1>
            </div>
    </div>
            <div class="breadcrumbs">
                            <div class="youarehere"><span class="bchead">You are here: </span><span class="home"><bdi><a href="start.html" class="wikilink1" title="start">start</a></bdi></span> » <bdi><span class="curid"><a href="graphicsutilitiesstamp2sprite.html" class="wikilink1" title="graphicsutilitiesstamp2sprite">graphicsutilitiesstamp2sprite</a></span></bdi></div>
                    </div>
    <hr class="a11y" />
</div></div>
        <div class="wrapper group">
            <div id="dokuwiki__content"><div class="pad group">
                <div class="pageId"><span>graphicsutilitiesstamp2sprite</span></div>
                <div class="page group">
<p>
<a href="http://doc.basic256.org/lib/exe/detail.php?id=graphicsutilitiesstamp2sprite&amp;media=graphicsutilitiesstamp2sprite.png" class="media" title="graphicsutilitiesstamp2sprite.png"><img src="lib/exe/graphicsutilitiesstamp2sprite.png" class="media" alt="" width="200" /></a>
Subroutine to draw a stamp on the screen and then capture it as a sprite.  Requires 0.9.9.28 or higher.<br/>
With 1.0.0.0 this fancy code is no longer needed.  Please see the <a href="http://doc.basic256.org/doku.php?id=spritepoly" class="wikilink2" title="spritepoly" rel="nofollow">Spritepoly</a> statement.<br/>
</p>
<pre class="code"># 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,10,10,20,20,20,20,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,ref(s),white,red,clear,4)
penwidth 2
call stamp2sprite(1,ref(s),clear,clear,white,4)
penwidth 3
call stamp2sprite(2,ref(s),purple,purple,clear,4)
penwidth 4
call stamp2sprite(3,ref(s),rgb(0,255,0,128),rgb(0,255,0,64),clear,4)
print &quot;press any key to stop&quot;
color black
rect 0,0,300,300
dim dx(4)
dim dy(4)
for t = 0 to 3
   dx[t] = 1
   dy[t] = 1
   spriteplace t,rand*300, rand*300
   spriteshow t
next t
while key = 0
   for t = 0 to 3
      spritemove t, dx[t], dy[t]
      if spritex(t) &lt;= 0 or spritex(t)&gt;=300 then dx[t] *= -1
      if spritey(t) &lt;= 0 or spritey(t)&gt;=300 then dy[t] *= -1
   next t
   refresh
end while
end
subroutine stamp2sprite(spriteno, ref(points), pencolor, brushcolor, backgroundcolor, scale)
   # 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[?]/2-1
      if points[t*2] &lt; minx then minx = points[t*2]
      if points[t*2] &gt; maxx then maxx = points[t*2]
      if points[t*2+1] &lt; miny then miny = points[t*2+1]
      if points[t*2+1] &gt; 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,y,scale,0,points
   refresh
   spriteslice spriteno,0,0,w,h
end subroutine
</pre>
                                    </div>
                <div class="docInfo"><bdi>graphicsutilitiesstamp2sprite.txt</bdi> · Last modified: 2013/11/14 14:08 by <bdi>admin</bdi></div>
                            </div></div>
            <hr class="a11y" />
        </div>
<div id="dokuwiki__footer"><div class="pad">
    <div class="license">Except where otherwise noted, content on this wiki is licensed under the following license: <bdi><a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license" class="urlextern">CC Attribution-Share Alike 3.0 Unported</a></bdi></div>
</div></div>
    </div></div>
    <div id="screen__mode" class="no"></div>
</body>
</html>