<?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>Code Exchange (new threads)</title>
		<link>http://kogics.wikidot.com/forum/c-109808/code-exchange</link>
		<description>Threads in the forum category &quot;Code Exchange&quot; - Show your code. Learn from code written by others.</description>
				<copyright></copyright>
		<lastBuildDate>Sun, 19 Jul 2026 21:23:39 +0000</lastBuildDate>
		
					<item>
				<guid>http://kogics.wikidot.com/forum/t-14392493</guid>
				<title>Penrose tilings</title>
				<link>http://kogics.wikidot.com/forum/t-14392493/penrose-tilings</link>
				<description></description>
				<pubDate>Tue, 21 Dec 2021 15:46:26 +0000</pubDate>
				<wikidot:authorName>Joost Winter</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Congratulations to the devs for this awesome project! I am just getting started in Kojo and wrote a little small program to draw some rhombus-type Penrose tilings. So this here is really my first program using Kojo (and in fact, also my first program ever in Scala):</p> <div class="code"> <pre><code>var baseOne = 2 * math.sin(math.Pi * 54 / 180) var baseTwo = 2 * math.sin(math.Pi * 18 / 180) def triangleOne(depth: Int, length: Double, mirrored: Int): Unit = { if(depth == 0) { setFillColor(cm.green) forward(length) right(mirrored * 72) forward(length) right(mirrored * 144) hop(length * baseOne) right(mirrored * 144) } else { right(mirrored * 36) hop(length) left(mirrored * 144) triangleOne(depth - 1, length / baseOne, -mirrored) hop(length / baseOne) right(180) triangleTwo(depth - 1, length / baseOne, -mirrored) hop(length / baseOne) right(-mirrored * 36) hop(length / baseOne) right(180) triangleOne(depth - 1, length / baseOne, mirrored) hop(length * baseOne) right(mirrored * 144) } } def triangleTwo(depth: Int, length: Double, mirrored: Int): Unit = { if(depth == 0) { setFillColor(cm.blue) forward(length) right(mirrored * 144) forward(length) right(mirrored * 108) hop(length * baseTwo) right(mirrored * 108) } else { hop(length * baseTwo * baseTwo) right(mirrored * 108) triangleTwo(depth - 1, length * baseTwo, mirrored) hop(length * baseTwo) right(mirrored * 180) triangleOne(depth - 1, length * baseTwo, mirrored) left(mirrored * 36) hop(length * baseTwo) right(mirrored * 108) } } def decagon(depth: Int, length: Double) { clear() setBackground(cm.black) setSpeed(superFast) invisible() setPenColor(cm.black) left(90) hop(length) right(180) repeat(5) { triangleTwo(depth, length, 1) triangleTwo(depth, length, -1) right(72) hop(length * baseTwo) left(36) hop(length * baseTwo) left(108) } } clear() toggleFullScreenCanvas() var depth = 0 repeat(7) { decagon(depth, 400) depth = depth + 1 Thread.sleep(3000) }</code></pre></div> <img src="http://joostwinter.net/penrose.png" alt="penrose.png" class="image" /> <p>My compliments to the Kojo devs for creating an environment that makes it surprisingly easy to do things like this&#8230;</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-982922</guid>
				<title>Beginning on Kojo</title>
				<link>http://kogics.wikidot.com/forum/t-982922/beginning-on-kojo</link>
				<description>Just found Kojo while searching for a tool to teach programming to my kid Asmita.  Here are couple of basic scripts I created along with Asmita.</description>
				<pubDate>Wed, 13 Aug 2014 04:41:34 +0000</pubDate>
				<wikidot:authorName>Abhijeet Ramdhave</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p><strong>Star</strong></p> <div class="code"> <pre><code>clear() setBackground(black) setPenColor(red) setFillColor(blue) for (i &lt;- 1 to 5) { forward(200) right(144) }</code></pre></div> <p><strong>Kojo Design</strong></p> <div class="code"> <pre><code>clear() setBackground(black) setPenColor(red) setFillColor(blue) for (i &lt;- 1 to 12) { for (i &lt;- 1 to 4) { forward(50) right(90) } penUp() right(180 - 180 * 10 / 12) forward(50) penDown() }</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-261332</guid>
				<title>PhiLho&#039;s code</title>
				<link>http://kogics.wikidot.com/forum/t-261332/philho-s-code</link>
				<description>My code in Kojo.
Also in [http://bazaar.launchpad.net/~philho/+junk/Kojo/files Kojo experiments on Launchpad]</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>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-229555</guid>
				<title>Another example, with sq and dist methods</title>
				<link>http://kogics.wikidot.com/forum/t-229555/another-example-with-sq-and-dist-methods</link>
				<description>A straight port of the Array2D example from Processing.  The most interesting part is the sq and dist methods, which should be generic enough (requires 2.8, I think) and possibly efficient (I&#039;m not implementation-savvy in the Java environment).</description>
				<pubDate>Thu, 25 Mar 2010 09:09:01 +0000</pubDate>
				<wikidot:authorName>Peter Lewerin</wikidot:authorName>				<wikidot:authorUserId>459742</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <div class="code"> <pre><code>import java.awt.Color._ def sq[A](x: A)(implicit n: Numeric[A]): A = n.times(x, x) def dist[A](x0: A, y0: A, x1: A, y1: A)(implicit n: Numeric[A]): A = { val v = n.plus(sq(n.minus(x0, x1)), sq(n.minus(y0, y1))) val r = Math.sqrt(n.toDouble(v)) if (v.isInstanceOf[Int]) r.toInt.asInstanceOf[A] else if (v.isInstanceOf[Float]) r.toFloat.asInstanceOf[A] else r.asInstanceOf[A] } clear invisible Canvas.fgClear //? val width = 200 val height = 200 // background(0) val maxDistance = dist(width/2, height/2, width, height) val distances = Seq.tabulate(width, height){ case (i, j) =&gt; dist(width/2f, height/2f, j, i)/maxDistance * 255 } for (i &lt;- 0 until(height, 2) ; j &lt;- 0 until(width, 2)) { val c = distances(j)(i).toInt Canvas.setPenColor(new Color(c, c, c)) Canvas.point(j, i) }</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-229372</guid>
				<title>Rendering curves in grayscale</title>
				<link>http://kogics.wikidot.com/forum/t-229372/rendering-curves-in-grayscale</link>
				<description>Adapted from a Processing example, applies four different composed functions to sequence of radian values from 0 to pi and renders each as a grayscale gradient.</description>
				<pubDate>Wed, 24 Mar 2010 14:54:12 +0000</pubDate>
				<wikidot:authorName>Peter Lewerin</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <div class="code"> <pre><code>import Math._ import java.awt.Color._ clear invisible val width = 180 val height = 25 val halfwave = Vector.tabulate(width){ i =&gt; toRadians(i) } def render (level: Int)(fn: Double =&gt; Double) { val y0 = level * height val y1 = (level + 1) * height (halfwave map fn zipWithIndex) foreach { case(e, i) =&gt; val c = e.toFloat Canvas.setPenColor(new Color(c, c, c)) Canvas.line(i, y0, i, y1) } } val f = { x: Double =&gt; 1 - x } render (3) { sin } render (2) { sin _ andThen f } render (1) { cos _ andThen abs } render (0) { cos _ andThen abs andThen { x =&gt; 1 - x } }</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-229114</guid>
				<title>Dragon curve example.</title>
				<link>http://kogics.wikidot.com/forum/t-229114/dragon-curve-example</link>
				<description></description>
				<pubDate>Tue, 23 Mar 2010 13:10:28 +0000</pubDate>
				<wikidot:authorName>Łukasz Lew</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>def dragon (depth : Int, angle : Double) : Unit = {<br /> if (depth == 0) {<br /> forward (10)<br /> return;<br /> }</p> <p>turn (angle)<br /> dragon (depth-1, angle.abs)<br /> turn (-angle)</p> <p>turn (-angle)<br /> dragon (depth-1, -angle.abs)<br /> turn (angle)<br /> }</p> <p>clear<br /> setAnimationDelay(0)<br /> setPenThickness (7)</p> <p>dragon (10, 45)</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://kogics.wikidot.com/forum/t-228292</guid>
				<title>Welcome</title>
				<link>http://kogics.wikidot.com/forum/t-228292/welcome</link>
				<description>&#039;Code Exchange&#039; Category Information</description>
				<pubDate>Fri, 19 Mar 2010 20:21:19 +0000</pubDate>
				<wikidot:authorName>lalitp</wikidot:authorName>				<wikidot:authorUserId>66813</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Want to showcase what you're doing with Kojo? Or just browse and see what others are upto?<br /> Then this is the place to hang out in&#8230;</p> <p>You can create new threads within this category, and make new posts within existing threads, without having to register or login.</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>