<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>PhiLho&#039;s code</title>
		<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code</link>
		<description>Posts in the discussion thread &quot;PhiLho&#039;s code&quot; - My code in Kojo.
Also in [http://bazaar.launchpad.net/~philho/+junk/Kojo/files Kojo experiments on Launchpad]</description>
				<copyright></copyright>
		<lastBuildDate>Mon, 10 Aug 2026 11:27:59 +0000</lastBuildDate>
		
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-1800703</guid>
				<title>(no title)</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-1800703</link>
				<description></description>
				<pubDate>Thu, 20 Jun 2013 10:15:29 +0000</pubDate>
				<wikidot:authorName>praba</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>i don't get anything&#8230;..</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-860061</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-860061</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 15:23:42 +0000</pubDate>
				<wikidot:authorName>lalitp</wikidot:authorName>				<wikidot:authorUserId>66813</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <blockquote> <p>Suggestion: make overrides of setXxxColor to accept directly 0xAABBCC or 0xAABBCCDD or r, g, b or a, r, g, b</p> </blockquote> <p>Or maybe overload the color method (It's good to have the input type of setXxxColor be a color)</p> <blockquote> <p>Accepting some HSB color (via conversion function?) would be useful too.</p> </blockquote> <p>I'll need to play with that. Staging has all of this stuff, btw&#8230;</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-860031</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-860031</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 14:16:34 +0000</pubDate>
				<wikidot:authorName>lalitp</wikidot:authorName>				<wikidot:authorUserId>66813</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Very cool!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-860007</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-860007</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 13:35:10 +0000</pubDate>
				<wikidot:authorName>PhiLho</wikidot:authorName>				<wikidot:authorUserId>551317</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>I understood it was an odd meeting of circumstances, or, as you wrote, an edge case.</p> <blockquote> <p>In line-by-line mode, it just stops at the first problem, and never gets to the internal repeat</p> </blockquote> <p>Yes, silly me, the code above has no var in it!</p> <p>Contributor Agreement - will do</p> <blockquote> <p>Just create a Color with an alpha value e.g. setFillColor(new Color(0, 0, 255, 128))</p> </blockquote> <p>Ah, tried color() with four parameters, not quite the same thing.<br /> Suggestion: make overrides of setXxxColor to accept directly 0xAABBCC or 0xAABBCCDD or r, g, b or a, r, g, b<br /> Works well in Processing and simplifies the coding.<br /> Accepting some HSB color (via conversion function?) would be useful too.</p> <blockquote> <p>Just do number.toHexString</p> </blockquote> <p>Thanks! I expected something that simple&#8230; ^_^</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-860004</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-860004</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 13:26:22 +0000</pubDate>
				<wikidot:authorName>PhiLho</wikidot:authorName>				<wikidot:authorUserId>551317</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Today is Sunday, I have some free time. ^_^<br /> Level up! To recursive functions, and beyond. Kojo fits well with geometrical fractals, so here is the Sierpinski square:</p> <div class="code"> <pre><code>clear invisible setAnimationDelay(4) setPenColor(blue) setPenThickness(1) setFillColor(color(0x77FFAA)) def relativeJumpTo(dx: Int, dy: Int) = jumpTo(position.x + dx, position.y + dy) def doSquare(size: Int): Unit = { val diag = size * 0.707 // sqrt(2)/2 penUp setHeading(45) forward(diag) penDown setHeading(-90) repeat(4) { forward(size); right } penUp setHeading(-135) forward(diag) } def doSquares(level: Int, size: Int): Unit = { if (level == 0) { doSquare(size) return } val s = size / 3 for (i &lt;- -1 until 2) { for (j &lt;- -1 until 2) { if (!(i == 0 &amp; j == 0)) { relativeJumpTo(s * i, s * j) doSquares(level -1, s) relativeJumpTo(-s * i, -s * j) } } } } //doSquare(500) doSquares(3, 500)</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-859997</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-859997</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 13:14:56 +0000</pubDate>
				<wikidot:authorName>lalitp</wikidot:authorName>				<wikidot:authorUserId>66813</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <blockquote> <p>Ah, this is quite unexpected, first time I meet a language enforcing the brace style! ;-)</p> </blockquote> <p>Just to clarify, this is more of a scala interpreter thing (when it is fed input a line at a time) than a Scala thing. If you use the Scala compiler to compile code of this nature, it will work fine.</p> <p>One more thing in the mix here is the use of a 'var' in your script. If you don't use vars, Kojo is able to submit the whole script (in one batch, not line by line) to the interpreter, and things work fine.</p> <blockquote> <p>I suppose the rule applies to current scope, since the internal repeat is OK.</p> </blockquote> <p>In line-by-line mode, it just stops at the first problem, and never gets to the internal repeat</p> <blockquote> <p>Note: I place all my code under the zlib/libpng license, but small experiments like the one above are just put<br /> in public domain: if you find something of interest, feel free to add it to Kojo examples.</p> </blockquote> <p>Cool.<br /> Now is probably a good time to tell you that if you wish to contribute more substantial code to Kojo, I will request you to sign the <a href="http://wiki.kogics.net/forum/t-231811/contributor-license-agreement">Contributor Agreement</a>.</p> <blockquote> <p>What about transparency? Is it possible in Kojo or just not yet?</p> </blockquote> <p>Just create a Color with an alpha value e.g. setFillColor(new Color(0, 0, 255, 128))<br /> For Staging, you can also use the rgba color maker.</p> <blockquote> <p>And is there a convenient shortcut in Scala to display a number in hexa or do we have to use something like Message.format() or similar?</p> </blockquote> <p>I missed out on this yesterday. Just do number.toHexString</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-859925</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-859925</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 11:16:21 +0000</pubDate>
				<wikidot:authorName>PhiLho</wikidot:authorName>				<wikidot:authorUserId>551317</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Today's code is a little variant of the previous one, with some def to spice it up&#8230; ^_^</p> <div class="code"> <pre><code>val ROUND = 360.0 val REPEAT_NB = 7 val ANGLE = ROUND / REPEAT_NB val PENTA_ANGLE = ROUND / 5 val SIDE_LENGTH = 150 clear setAnimationDelay(42) setPenThickness(11) for (n &lt;- 0 until REPEAT_NB) { jumpTo(0, 0) setHeading(n * ANGLE) setPenColor(getColor(n)) repeat (3) { forward(SIDE_LENGTH) turn(PENTA_ANGLE) } forward(SIDE_LENGTH / 4) } penUp; home; penDown def lerp(start: Double, stop: Double, amount: Double): Double = { start + (stop - start) * amount } def getColor(n: Int): Color = { val amount = n.toDouble / REPEAT_NB color(0x80, lerp(0xF0, 0x80, amount).toInt, lerp(0x80, 0xF0, amount).toInt) }</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-859909</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-859909</link>
				<description></description>
				<pubDate>Sun, 29 Aug 2010 10:32:31 +0000</pubDate>
				<wikidot:authorName>PhiLho</wikidot:authorName>				<wikidot:authorUserId>551317</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Ah, this is quite unexpected, first time I meet a language enforcing the brace style! ;-)<br /> I understand it is a combination of unfortunate mix, Scala's line ending interpretation, repeat being a method and not a keyword, the interpreter mode, etc.<br /> I suppose the rule applies to current scope, since the internal repeat is OK.</p> <p>Note: I place all my code under the zlib/libpng license, but small experiments like the one above are just put in public domain: if you find something of interest, feel free to add it to Kojo examples.<br /> I updated the code above to have better contrast on the first three pentagons.</p> <p>What about transparency? Is it possible in Kojo or just not yet?<br /> And is there a convenient shortcut in Scala to display a number in hexa or do we have to use something like Message.format() or similar?</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-859477</guid>
				<title>Re: PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-859477</link>
				<description></description>
				<pubDate>Sat, 28 Aug 2010 16:58:50 +0000</pubDate>
				<wikidot:authorName>lalitp</wikidot:authorName>				<wikidot:authorUserId>66813</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <blockquote> <p>OK, my first baby steps in Kojo… Purely imperative for now.</p> </blockquote> <p>Nice and pretty!</p> <blockquote> <p>There is something that puzzles me: if I replace the for loop with:<br /> var n = 0<br /> repeat (5)<br /> I get an error:</p> </blockquote> <p>You've stumbled into an edge case within Kojo:<br /> - if a script uses vars, it is interpreted line by line. Your script has a var, so this applies.<br /> - the opening brace of your repeat command starts on the next line. When the scala interpreter encounters the line with the repeat command, it thinks that the code block for repeat is missing.</p> <p>The Fix - just pull the opening brace to the line with the repeat command:<br /> repeat (5) {</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332#post-859434</guid>
				<title>PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code#post-859434</link>
				<description></description>
				<pubDate>Sat, 28 Aug 2010 16:05:18 +0000</pubDate>
				<wikidot:authorName>PhiLho</wikidot:authorName>				<wikidot:authorUserId>551317</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>OK, my first baby steps in Kojo&#8230; Purely imperative for now.</p> <div class="code"> <pre><code>val ROUND = 360 val SIDE_NB = 5 val ANGLE = ROUND / SIDE_NB clear jumpTo(0, 300) write(&quot;Pentagon&quot;) jumpTo(0, 0) setAnimationDelay(42) setPenColor(blue) setPenThickness(11) for (n &lt;- -2 until 3) { setFillColor(color(0x80 - n * 40, 0xFF, 0x80 + n * 60)) setHeading((2 + n) * ANGLE) repeat (SIDE_NB) { forward(150) turn(-ANGLE) } }</code></pre></div> <br /> That's mostly an exploration of the API.<br /> I saw no means to specify a translucent fill color. I tried with a 32bit color like 0x8080FF80 but it is still opaque. <p>There is something that puzzles me: if I replace the for loop with:</p> <div class="code"> <pre><code>var n = 0 repeat (5)</code></pre></div> <br /> I get an error: <div class="code"> <pre><code>error: missing arguments for method repeat in object Builtins; follow this method with `_' if you want to treat it as a partially applied function repeat (5) ^</code></pre></div> <br /> Not sure if it is to be expected with Scala (ie. if I didn't fully understood the syntax) or if there is a bug in the interpreter. <p>BTW, if I want to print a number in hexa style, what is the idiom in Scala?</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>