kopia lustrzana https://github.com/backface/turtlestitch
Add BUTTON block to penTrails library
This is in response to a Piazza request. Uses pen trail to make a button-shaped costume with given text.upd4.1
rodzic
88b0fe1052
commit
6c97a347ce
|
@ -1 +1 @@
|
|||
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="pen trails" type="reporter" category="pen"><header></header><code></code><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list></list><l>var cst = new Costume(
 this.parentThatIsA(StageMorph).trailsCanvas
);
cst.shrinkWrap();
return cst;</l></block><list></list></block></block></script></block-definition><block-definition s="set pen trails to: %'costume'" type="command" category="pen"><header></header><code></code><inputs><input type="%s" readonly="true"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>cst</l></list><l>var stage = this.parentThatIsA(StageMorph);
stage.trailsCanvas = cst.contents;
stage.changed();</l></block><list><block var="costume"/></list></block></script></block-definition><block-definition s="make costume named %'name' from pen trail %'trail'" type="command" category="looks"><header></header><code></code><inputs><input type="%s">pen trail</input><input type="%s"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>name</l><l>trail</l></list><l>trail.name = this.newCostumeName(name, null);
this.addCostume(trail);
this.wearCostume(trail);</l></block><list><block var="name"/><block var="trail"/></list></block></script></block-definition></blocks>
|
||||
<blocks app="Snap! 4.0, http://snap.berkeley.edu" version="1"><block-definition s="label %'text' of size %'size'" type="command" category="pen"><comment x="0" y="0" w="90" collapsed="false">LABEL will stamp text on the stage at the given font size. The direction of the text is the direction the sprite is facing, and color will match the pen color.</comment><header></header><code></code><inputs><input type="%txt">Hello!</input><input type="%n">12</input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>text</l><l>size</l></list><l>var stage = this.parentThatIsA(StageMorph),
 context = stage.penTrails().getContext('2d'),
 rotation = radians(this.direction() - 90),
 trans = new Point(
 this.center().x - stage.left(),
 this.center().y - stage.top()
 ),
 isWarped = this.Warped,
 len,
 pos;

if (isWarped) {endWarp(); }
context.save();
context.font = size + 'px monospace';
context.textAlign = 'left';
context.textBaseline = 'alphabetic';
context.fillStyle = this.color.toString();
len = context.measureText(text).width;
trans = trans.multiplyBy(1 / stage.scale);
context.translate(trans.x, trans.y);
context.rotate(rotation);
context.fillText(text, 0, 0);
context.translate(-trans.x, -trans.y);
context.restore();
pos = new Point(
 len * Math.sin(radians(this.direction())),
 len * Math.cos(radians(this.direction())));
pos = pos.add(new Point(this.xPosition(), this.yPosition()));
this.gotoXY(pos.x, pos.y, false);
this.changed();
if (isWarped) {this.startWarp(); }
stage.changed();</l></block><list><block var="text"/><block var="size"/></list></block></script></block-definition><block-definition s="button %'text'" type="command" category="pen"><comment w="176" collapsed="false">Make a new sprite, have it run this block to turn into a button. This will clear anything drawn on the stage.</comment><header></header><code></code><inputs><input type="%s">Push me!</input></inputs><script><block s="clear"></block><block s="up"></block><block s="gotoXY"><l>0</l><l>0</l></block><block s="setHeading"><l>90</l></block><block s="setColor"><color>3,0,0,1</color></block><custom-block s="label %txt of size %n"><block var="text"/><l>30</l></custom-block><block s="doDeclareVariables"><list><l>width</l></list></block><block s="doSetVar"><l>width</l><block s="xPosition"></block></block><block s="gotoXY"><l>0</l><l>10</l></block><block s="setColor"><color>251,255,13,1</color></block><block s="setSize"><l>30</l></block><block s="down"></block><block s="forward"><block var="width"/></block><block s="up"></block><block s="setSize"><l>1</l></block><block s="setColor"><color>3,0,0,1</color></block><block s="gotoXY"><l>0</l><l>0</l></block><custom-block s="label %txt of size %n"><block var="text"/><l>30</l></custom-block><custom-block s="make costume named %s from pen trail %s"><block var="text"/><custom-block s="pen trails"></custom-block></custom-block><block s="gotoXY"><l>0</l><l>0</l></block><block s="clear"></block></script></block-definition><block-definition s="pen trails" type="reporter" category="pen"><header></header><code></code><inputs></inputs><script><block s="doReport"><block s="evaluate"><block s="reportJSFunction"><list></list><l>var cst = new Costume(
 this.parentThatIsA(StageMorph).trailsCanvas
);
cst.shrinkWrap();
return cst;</l></block><list></list></block></block></script></block-definition><block-definition s="make costume named %'name' from pen trail %'trail'" type="command" category="looks"><header></header><code></code><inputs><input type="%s">pen trail</input><input type="%s"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>name</l><l>trail</l></list><l>trail.name = this.newCostumeName(name, null);
this.addCostume(trail);
this.wearCostume(trail);</l></block><list><block var="name"/><block var="trail"/></list></block></script></block-definition></blocks>
|
Ładowanie…
Reference in New Issue