<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>OM 2010 &#187; Markus Walthert</title>
	<atom:link href="http://ifdblog.org/ba-om2010/author/markus/feed/" rel="self" type="application/rss+xml" />
	<link>http://ifdblog.org/ba-om2010</link>
	<description></description>
	<lastBuildDate>Wed, 23 Jun 2010 10:22:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Processing Workshop &#124; Teil 7 &#124; Strings und Textobjekt</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-7/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-7/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:12:19 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=400</guid>
		<description><![CDATA[<img title="Übung 7" src="http://ifdblog.org/ba-om2010/wp-content/uploads/2009/10/uebung7_vorschau.jpg" alt="Übung 7" width="340" height="255" />]]></description>
			<content:encoded><![CDATA[<p><strong>Schrift in Processing einbinden</strong><br />
Schrift wird zusätzlich zur .pde Datei im Folder /data unserer Applikation zur Verfügung gestellt. Mit dem Processingeditor kann man das einfach über Tools -> Create Font und dem Fontnamen mit der Endung .vlw erstellen. Das Font selber ist ein Objekt vom Typ PFont. Der Text, der mit einem Fontobjekt dargestellt werden soll, ist eine String Variable.<br />
<img src="http://ifdblog.org/ba-om2010/wp-content/uploads/2010/01/Bildschirmfoto-2010-01-20-um-18.10.17-322x255.png" alt="Bildschirmfoto-2010-01-20-um-18 10 17-322x255 in " width="322" height="255" class="alignnone size-medium wp-image-640" /></p>
<p><strong>Bring me the Letter</strong><br />
Wie lang dieser String ist und was drin steht ist unerheblich. Einfache Operationen wie zum Beispiel ein Zeilenumbruch lassen sich  mit <code>\n</code> realisieren. Weiter liefert String auch bereits Methoden um z.B. die Position eines Zeichen in einem String zu ermitteln oder wiederzugeben <code>charAt()</code>.<br />
Damit Buchstabe um Buchstabe manipulieren kann, ist im folgenden Beispiel der String in einen Array <code>currentLetterObj[]</code> abgelegt. Die Größe des Arrays beträgt genau so viel wie der String lang ist <code>myString.length()</code>.</p>
<p>Mit  <code>text(myString,150,50);</code> wird der komplette Text wiedergegeben.<br />
Buchstabe um Buchstabe wird hier jedoch mit dem Array <code>currentLetterObj</code>, der bei jedem Mausklick ein neues Buchstabenobjekt <code>BringMeTheLetter</code> erzeugt. In der Klasse <code>BringMeTheLetter</code> wird der Buchstaben erzeugt und in der <code>drawLetter()</code> Methode animiert. Mit der Stringfunktion <code>charAt()</code> und dem Zähler <code>counter</code> rückt der Zeiger immer um ein Zeichen weiter und arbeitet den kompletten String ab.</p>
<p>Zum Anzeigen bitte auf das Vorschaubild links klicken.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">BringMeTheLetter<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> currentLetterObj<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #003399;">String</span> myString <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;i am here&quot;</span><span style="color: #339933;">;</span>
PFont myFont<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> counter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">char</span> currentChar<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">boolean</span> start <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">320</span>, <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">30</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myFont <span style="color: #339933;">=</span> createFont<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ArnoPro-ItalicSubhead&quot;</span>,<span style="color: #cc66cc;">40</span>,<span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  textFont<span style="color: #009900;">&#40;</span>myFont<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  textAlign<span style="color: #009900;">&#40;</span>LEFT<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  smooth<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  currentLetterObj <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BringMeTheLetter<span style="color: #009900;">&#91;</span>myString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  text<span style="color: #009900;">&#40;</span>myString,<span style="color: #cc66cc;">100</span>,<span style="color: #cc66cc;">120</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> w <span style="color: #339933;">=</span> textWidth<span style="color: #009900;">&#40;</span>currentChar<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,w<span style="color: #339933;">*</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>start<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> counter<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      currentLetterObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">drawLetter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      currentLetterObj<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">falling</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span>  mouseClicked<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  start <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
  currentChar <span style="color: #339933;">=</span> myString.<span style="color: #006633;">charAt</span><span style="color: #009900;">&#40;</span>counter<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> posX <span style="color: #339933;">=</span> mouseX<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> posY <span style="color: #339933;">=</span> mouseY<span style="color: #339933;">;</span>
  currentLetterObj<span style="color: #009900;">&#91;</span>counter<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> BringMeTheLetter<span style="color: #009900;">&#40;</span>currentChar, posX, posY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>counter <span style="color: #339933;">&gt;=</span> myString.<span style="color: #006633;">length</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    counter <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
    counter<span style="color: #339933;">++;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> BringMeTheLetter <span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">char</span> myChar<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> x<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> y<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> alpha<span style="color: #339933;">;</span>
&nbsp;
  BringMeTheLetter<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">char</span> _char,<span style="color: #000066; font-weight: bold;">int</span> _x, <span style="color: #000066; font-weight: bold;">int</span> _y<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    myChar <span style="color: #339933;">=</span> _char<span style="color: #339933;">;</span>
    x <span style="color: #339933;">=</span> _x<span style="color: #339933;">;</span>
    y <span style="color: #339933;">=</span> _y<span style="color: #339933;">;</span>
    alpha <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> drawLetter<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    alpha<span style="color: #339933;">--;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,alpha<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    text<span style="color: #009900;">&#40;</span>myChar,x,y<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> falling<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    y<span style="color: #339933;">++;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Vielen Dank an <a href="http://www.we-make-money-not-art.com/archives/2007/04/dennis-paul-and.php" target="_self"><strong>Patrick Paul</strong> </a>und <a href="http://www.we-make-money-not-art.com/archives/2007/04/dennis-paul-and.php" target="_self"><strong>Dennis Kochlick</strong></a> deren Beispiele hier zum Teil Pate standen und deren Buch &#8220;Gestalten mit Code&#8221; sehr inspirierend ist.</p>
]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 6 &#124; Bewegung und Spiegelung</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-6/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-6/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 17:08:12 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=397</guid>
		<description><![CDATA[<img title="Übung 6" src="http://ifdblog.org/ba-om2010/wp-content/uploads/2009/10/uebung6_vorschau.jpg" alt="Übung 6" width="340" height="255" />]]></description>
			<content:encoded><![CDATA[<p><strong>Spieglein Spieglein</strong><br />
In diesem Beispiel bewegen sich Linien von der Mitte der Screen zum linken Bildrand. Auf der rechten Bildhälfte passiert das genau gleiche, nur spiegelverkehrt &#8211; aber trotzdem mit den selben Variablen und Formeln. Der einzige Unterschied ist die if-Bedingung für den Richtungswechsel. der ist für die linke Bildhälfte bei 0 und width/2, für die rechte Bildhälfte bei width/2 und width.</p>
<p>In der <code>setup()</code> Methode  werden in einer <code>for</code>-Schleife die Anzahl der Linien <code>N</code> generiert und gleich beim Erstellen über den Parameter side als Linie definiert die sich nach links oder nach rechts bewegen soll. Die Variable <code>side</code> kennt zwei Zustände; <code>true</code> und <code>false</code>. Ich habe definiert, dass eine Bewegung nach link false und eine Bewegung nach rechts true ist. Die Abfrage kann dann einfach <code>if(side)</code> oder <code>if(!side)</code> lauten.</p>
<p>Zum Ansehen bitte auf das Vorschaubild klicken!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">VertLine<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> myVertLines<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> N <span style="color: #339933;">=</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Anzahl Linien für die linke Seite</span>
<span style="color: #000066; font-weight: bold;">boolean</span> side<span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//left = false, right = true</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">340</span>,<span style="color: #cc66cc;">400</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> xPos <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">;</span>
  myVertLines <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VertLine<span style="color: #009900;">&#91;</span>N<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>N<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">float</span> xPosLeft <span style="color: #339933;">=</span> width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">float</span> speedLeft <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span>,<span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">int</span> trans<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>i<span style="color: #339933;">&lt;</span>N<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      side <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span>
      side <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    myVertLines<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> VertLine<span style="color: #009900;">&#40;</span>xPosLeft, speedLeft, side<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>i<span style="color: #339933;">&lt;</span>N<span style="color: #339933;">*</span><span style="color: #cc66cc;">2</span><span style="color: #339933;">;</span>i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    myVertLines<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//Klasse für die Linien</span>
<span style="color: #000000; font-weight: bold;">class</span> VertLine<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">float</span> xPosLeft<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> speedLeft<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">boolean</span> side<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> trans<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">int</span> thickness<span style="color: #339933;">;</span>
&nbsp;
  VertLine<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> _xPosLeft, <span style="color: #000066; font-weight: bold;">float</span> _speedLeft, <span style="color: #000066; font-weight: bold;">boolean</span> _side<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    xPosLeft <span style="color: #339933;">=</span> _xPosLeft<span style="color: #339933;">;</span>
    side <span style="color: #339933;">=</span> _side<span style="color: #339933;">;</span>
    speedLeft <span style="color: #339933;">=</span> _speedLeft<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// println(side);</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/*
     * Die Linien sollen in der Mitte jeweils Dicke = 1 und 
     * opacity = 255, und am Rand dick und transparent sein
     */</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>side<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//Linke hälfte</span>
        xPosLeft <span style="color: #339933;">=</span> xPosLeft <span style="color: #339933;">+</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">//einzeilige if-Bedingungen können ohne geschweifte Klammer geschrieben werden</span>
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xPosLeft <span style="color: #339933;">&lt;</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span>
        speedLeft <span style="color: #339933;">=-</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xPosLeft <span style="color: #339933;">&gt;</span> width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
        speedLeft <span style="color: #339933;">=-</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">/*
       * innen dunkel / 255 alpha
       * aussen alpha 20
       * differenz = 235
       */</span>
      <span style="color: #000066; font-weight: bold;">float</span> trans <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">235</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>xPosLeft<span style="color: #339933;">;</span>
      stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,trans<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">/*
      * Breite in der Mitte = 1
      * aussen = 10
      */</span>
      <span style="color: #000066; font-weight: bold;">float</span> thickness <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span>xPosLeft<span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      strokeWeight<span style="color: #009900;">&#40;</span>thickness<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      drawShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">else</span><span style="color: #009900;">&#123;</span><span style="color: #666666; font-style: italic;">//rechte Hälfte</span>
      xPosLeft <span style="color: #339933;">=</span> xPosLeft <span style="color: #339933;">+</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xPosLeft <span style="color: #339933;">&gt;</span> width<span style="color: #009900;">&#41;</span>
        speedLeft <span style="color: #339933;">=-</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>xPosLeft <span style="color: #339933;">&lt;</span> width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span>
        speedLeft <span style="color: #339933;">=-</span> speedLeft<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">/*
       * innen dunkel / 255 alpha
       * aussen alpha 20
       * differenz = 235
       */</span>
      <span style="color: #000066; font-weight: bold;">float</span> trans <span style="color: #339933;">=</span> width<span style="color: #339933;">-</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">235</span><span style="color: #339933;">/</span><span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">*</span>xPosLeft<span style="color: #339933;">;</span>
      stroke<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,<span style="color: #cc66cc;">0</span>,trans<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #666666; font-style: italic;">/*
      * Breite in der Mitte = 1
      * aussen = 10
      */</span>
      <span style="color: #000066; font-weight: bold;">float</span> thickness <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>width <span style="color: #339933;">-</span> xPosLeft<span style="color: #009900;">&#41;</span><span style="color: #339933;">+</span><span style="color: #009900;">&#40;</span>width<span style="color: #339933;">/</span><span style="color: #cc66cc;">10</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      strokeWeight<span style="color: #009900;">&#40;</span>thickness<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      drawShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000066; font-weight: bold;">void</span> drawShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    line<span style="color: #009900;">&#40;</span>xPosLeft,<span style="color: #cc66cc;">0</span>,xPosLeft,height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-6/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 5 &#124; Klassen und Objekte, Bewegung</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-5/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-5/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 16:58:25 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=394</guid>
		<description><![CDATA[<img title="Übung 5" src="http://ifdblog.org/ba-om2010/wp-content/uploads/2009/10/uebung5_vorschau.jpg" alt="Übung 5" width="340" height="255" />]]></description>
			<content:encoded><![CDATA[<p><strong>Objekt</strong><br />
Die Stärke von Objekten beim programmieren ist, dass ein einmal definiertes und beschriebenes Objekt unendlich oft als Instanz weiterverwendet werden kann. Indem man dem Objekt unterschiedliche Parameter mitgibt, kann es auch jedes Mal seine Eigenschaften wie z.B. das Aussehen oder Bewegungsverhalten ändern.</p>
<p>In diesem Beispiele will ich Kreise auf der Screen verteilen. In der setup() Methode wird jedem Kreis ein zufällig generierter Wert für seine Startposition (x/y), seine Geschwindigkeit (vx/vy) und seine Größe (radius) erzeugt.</p>
<p>Der Kreis selber ist in einer Klasse mit dem Namen Ball beschrieben. Eine Klasse beginnt mit der Definition <code>class Name{ </code>und der Methode zum Aufruf der Klasse, hier <code>Ball(){</code>. Ob die Klasse im selben Script wie die Hauptklasse steht oder eine eigene Datei, spielt keine Rolle. Bei der Namensgebung ist lediglich wichtig, dass die Datei gleich heißt wie die Klasse auch. In der Regel beginnen Klassen mit einem Großbuchstaben.</p>
<p>Im Processingeditor können zusätzlich Dateien als Tabs abgelgt werden. Erstellt weden die Tabs mit dem Pfeil rechts oben.<br />
<img src="http://ifdblog.org/ba-om2010/wp-content/uploads/2010/01/editor-340x249.png" alt="Editor-340x249 in " width="340" height="249" class="alignnone size-medium wp-image-606" /><br />
In der sogenannten Superklasse, im Beispielbild oben die Datei _01, kann <code>Ball</code> nun wie ein Datentyp behandelt werden. Da ich die Möglichkeit für mehrere Bälle haben will, definiere ich Ball als Array <code>Ball[]</code> und gebe den Instanznamen <code>myBalls</code>. Damit der Array myBalls überhaupt zum Leben gebracht wird, muss ich ihn, ähnlich wie die Kugeln später auch, über das Schlüsselwort new erzeugen. Damit der Array auch weiß, wie viel Speicher für ihn reserviert werden soll, wird mit der Variable N für die Anzahl der Kugeln auch festgelegt, wie viele Kreise myBalls[] beinhalten kann.</p>
<p>In einer for-Schleife werden danach die Kreise ebenfalls mit new erzeugt<br />
<code>myBalls[i] = new Ball(x, y, vx, vy, radius);</code><br />
und jeweils aus dem Code der Klasse Ball eine Instanz erzeugt. In der Klasse selber werden in diesem Beispiel lediglich die übertragenen Parameter x, y, vx, vy, radius in global definierten Variablen, für jeden Ball einzeln, abgelegt. Global definierte Variablen können überall in der Klasse verwendet werden, die lokale Variable _x hingegen könnte nur in der Methode <code>Ball{}</code> verwendet werden.<br />
Die Zählervariable i dient gleichzeitig zum durchnummerieren der einzelnen Kreise. Beim ausführen des Codes, sind die Kreise nun alle  im Speicher vorhanden, aber noch nicht sichtbar.</p>
<p><strong>Make the things move</strong><br />
Den kontinuierlichen Aufruf der Methode <code>draw()</code> kann ich nun auch gleich benutzen, um den Kreis zu bewegen. Damit alle Kreise angezeigt werden, müssen in jedem Renderzyklus immer alle Kreise über eine for-Schleife abgearbeitet werden. Bei einer Framerate von 25 Zyklen pro Sekunden und 100 Kreisen müssen also je fünfunzwanzigstel Sekunde 100 Kreise gerendert werden.</p>
<p>Bewegt werden die Kreise in der Ball Klasse. In der Superklasse wird die Methode run() über die Punktsyntax aufgerufen<br />
<code>myBalls[i].run();</code><br />
und jeweils mit der jeder Kugel eigenen Geschwindigkeit vx und vy bewegt, indem bei jedem Aufruf der Wert vx rsp. vy zur aktuellen Position hinzuaddiert wird.<br />
<code>x = x + vx;</code></p>
<p>Erreicht der Kreis den Screenrand, muss die Richtung umgedreht werden. Dazu ändert man einfach das Vorzeichen.<br />
<code>vx = -vx;</code></p>
<p>Um das folgende Beispiel anzuzeigen, bitte auf das Vorschaubild klicken.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Ball<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> myBalls<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> N <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Anzahl der Bälle</span>
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">320</span>, <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">25</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myBalls <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ball<span style="color: #009900;">&#91;</span>N<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> N<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">float</span> x <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, width<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">float</span> y <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span>, height<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">float</span> vx <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">7</span>, <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">float</span> vy <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">7</span>, <span style="color: #cc66cc;">7</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066; font-weight: bold;">float</span> radius <span style="color: #339933;">=</span> random<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">3</span>, <span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    myBalls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Ball<span style="color: #009900;">&#40;</span>x, y, vx, vy, radius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> N<span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    myBalls<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span>.<span style="color: #006633;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">class</span> Ball<span style="color: #009900;">&#123;</span>
  <span style="color: #000066; font-weight: bold;">float</span> x<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> y<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> vx<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> vy<span style="color: #339933;">;</span>
  <span style="color: #000066; font-weight: bold;">float</span> radius<span style="color: #339933;">;</span>
  Ball<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> _x, <span style="color: #000066; font-weight: bold;">float</span> _y, <span style="color: #000066; font-weight: bold;">float</span> _vx, <span style="color: #000066; font-weight: bold;">float</span> _vy, <span style="color: #000066; font-weight: bold;">float</span> _radius<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    x <span style="color: #339933;">=</span> _x<span style="color: #339933;">;</span>
    y <span style="color: #339933;">=</span> _y<span style="color: #339933;">;</span>
    vx <span style="color: #339933;">=</span> _vx<span style="color: #339933;">;</span>
    vy <span style="color: #339933;">=</span> _vy<span style="color: #339933;">;</span>
    radius <span style="color: #339933;">=</span> _radius<span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">void</span> run<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    drawShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    x <span style="color: #339933;">=</span> x <span style="color: #339933;">+</span> vx<span style="color: #339933;">;</span>
    y <span style="color: #339933;">=</span> y <span style="color: #339933;">+</span> vy<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">/*
    * Abfragen nach Kollisionen links, rechts, oben und unten zur Screen
    */</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&lt;</span> radius<span style="color: #009900;">&#41;</span>    <span style="color: #009900;">&#123;</span>
      x <span style="color: #339933;">=</span> radius<span style="color: #339933;">;</span>
      vx <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>vx<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>x <span style="color: #339933;">&gt;</span> width <span style="color: #339933;">-</span> radius<span style="color: #009900;">&#41;</span>    <span style="color: #009900;">&#123;</span>
      x <span style="color: #339933;">=</span> width <span style="color: #339933;">-</span> radius<span style="color: #339933;">;</span>
      vx <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>vx<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&lt;</span> radius<span style="color: #009900;">&#41;</span>    <span style="color: #009900;">&#123;</span>
      y <span style="color: #339933;">=</span> radius<span style="color: #339933;">;</span>
      vy <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>vy<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>y <span style="color: #339933;">&gt;</span> height <span style="color: #339933;">-</span> radius<span style="color: #009900;">&#41;</span>    <span style="color: #009900;">&#123;</span>
      y <span style="color: #339933;">=</span> height <span style="color: #339933;">-</span> radius<span style="color: #339933;">;</span>
      vy <span style="color: #339933;">=</span> <span style="color: #339933;">-</span>vy<span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000066; font-weight: bold;">void</span> drawShape<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  <span style="color: #009900;">&#123;</span>
    ellipseMode<span style="color: #009900;">&#40;</span>CENTER_RADIUS<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    ellipse<span style="color: #009900;">&#40;</span>x, y, radius, radius<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 4 &#124; Button</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-4/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-4/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 16:53:47 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=391</guid>
		<description><![CDATA[<img title="Übung 4" src="http://ifdblog.org/ba-om2010/wp-content/uploads/2009/10/uebung4_vorschau.jpg" alt="Übung 4" width="340" height="255" />]]></description>
			<content:encoded><![CDATA[<p><strong>Button und Mausabfragen</strong><br />
In einem sogenannten Hittest frage ich die Mausposition ab. Um zu kontrollieren, ob ein viereckiger Button gedrückt wird, brauche ich die x und y Koordinate links oben des Buttons und die y und y Koordinate rechts unten des Buttons, also vier Bedingungen.<br />
Diese vier  if-Abfragen kann ich logisch miteinander verknüpfen: <code>&#038;&#038;</code> </p>
<p>Um das Beispiel anzuzeigen bitte auf das Vorschaubild klicken!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> size <span style="color: #339933;">=</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> x <span style="color: #339933;">=</span> <span style="color: #cc66cc;">160</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> y <span style="color: #339933;">=</span> <span style="color: #cc66cc;">120</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">320</span>, <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rectMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  noStroke<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">/* Boolean Abfrage /  */</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>hittest<span style="color: #009900;">&#40;</span>mouseX, mouseY<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span>, <span style="color: #cc66cc;">0</span>, <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    fill<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">127</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">/* Button malen */</span>
  rect<span style="color: #009900;">&#40;</span>x, y, size, size<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">boolean</span> hittest<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> theX, <span style="color: #000066; font-weight: bold;">int</span> theY<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>theX <span style="color: #339933;">&gt;</span> x <span style="color: #339933;">-</span> size <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">&amp;&amp;</span>
    theX <span style="color: #339933;">&lt;</span> x <span style="color: #339933;">+</span> size <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">&amp;&amp;</span>
    theY <span style="color: #339933;">&gt;</span> y <span style="color: #339933;">-</span> size <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #339933;">&amp;&amp;</span>
    theY <span style="color: #339933;">&lt;</span> y <span style="color: #339933;">+</span> size <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">false</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 3 &#124; Pixeldaten verarbeiten und Arrays</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-3/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-3/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 14:55:00 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=361</guid>
		<description><![CDATA[<img title="Übung 3" src="http://ifdblog.org/ba-om2010/wp-content/uploads/2009/10/uebung3_vorschau.jpg" alt="Übung 3" width="340" height="255" />]]></description>
			<content:encoded><![CDATA[<p><strong>Bild- und Pixeloperationen</strong><br />
Bilder können in mit <code>loadImage()</code> geladen und im <code>PImage</code> Objekt weiter verarbeitet werden. Neben dem einfachen Darstellen des Bildes kann man auch Pixel um Pixel verändern, ähnlich einem Photoshopfilter.<br />
<img src="http://ifdblog.org/ba-om2010/wp-content/data_processingws/_13/manfred-pecki.png" alt="Manfred-pecki in "  /><br />
Dieses Bild von Manfred Pecki besteht aus verschiedenen Grauwerten. Ich will das Bild in ein reines schwarz/weiß Bild verwandeln. Um zu entscheiden, ob ein Pixel in weiß umgewandelt werden soll, analysiere ich seine Grauwert. Liegt es innerhalb eines bestimmten Grenzwertes (myThreshold), wird es weiß, ansonsten schwarz (Farbwert: 255).</p>
<p>Dieser Grenzwert ist in diesem Beispiel dynamisch an die X-Position des Mauszeigers gekoppelt und gibt einen Wert zwischen 0 und 255 aus<br />
<code>float myThreshold = (float)mouseX / width * 255;</code></p>
<p>Nachdem das Bild geladen ist<br />
<code>myImage = loadImage("data/manfred-pecki.png");</code><br />
und als Hintergrundbild wiedergegeben ist<br />
<code>background(myImage);</code></p>
<p>kann ich mit <code>loadPixels()</code> jedes einzelne Pixel meiner Anwendung in einem Array zur Verfügung stellen, verändern und dieses veränderte Pixel mit <code>updatePixels()</code> neu auf die Screen rendern.</p>
<p>Das passiert alles in der <code>draw()</code> Methode in einer for-Schleife, die genau so lang ist wie das Bild Pixel hat. Diese Länge erhalte ich in einem Array mit pixels.length. Bei welchem Pixel ich mich gerade befinde sagt mir der Zähler <code>myPixelPosition</code>.</p>
<p>In jedem Schleifendurchlauf wird die Funbktion <code>setPixelFromBitmap()</code> aufgerufen, die entscheidet ob ein Pixel weiß oder schwarz werden soll.<br />
Ist die Schleife abgearbeitet, wird das Ergebnis mit <code>updatePixels()</code>; auf die Screen gerendert.</p>
<p>Hier wird auch deutlich, das die Länge und Breite des Bildes für die Verarbeitung keine Rolle spielt, sondern das Bild einfach eine lineare Aneinanderreihung von einzelnen Pixeln ist.<br />
<img src="http://ifdblog.org/ba-om2010/wp-content/uploads/2010/01/pixelreihe-340x135.gif" alt="Pixelreihe-340x135 in " width="340" height="135" class="alignnone size-medium wp-image-582" /></p>
<p>Um diesen Prozess auch visuell wahrzunehmen, können wir die Schleife dahingehend ändern, nicht das gesamte Bild je Renderzyklus in<code> draw()</code> zu verändern, sondern entweder Zeilenweise<br />
<code>for (int i=0; i < width; i++) { </code><br />
oder Pixelweise<br />
<code>for (int i=0; i < 1; i++) { </code></p>
<p>Um dieses Beispiel anzuzeigen bitt auf das Vorschaubild klicken!</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">PImage myImage<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">int</span> myPixelPosition<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">176</span>,<span style="color: #cc66cc;">247</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #666666; font-style: italic;">//Screnn in der Größe des importieren Bildes</span>
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">60</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">// myImage = loadImage(&quot;http://ifdblog.org/ba-om2010/data_processingblog&quot;);</span>
  myImage <span style="color: #339933;">=</span> loadImage<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;data/manfred-pecki.png&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  background<span style="color: #009900;">&#40;</span>myImage<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">/* lädt die komplette Screen in den Array pixels[] von myImage */</span>
  loadPixels<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/* den &quot;Schwellwert&quot; festlegen
  *  Operation ergibt einen Wert von 0 - 255
  */</span>
  <span style="color: #000066; font-weight: bold;">float</span> myThreshold <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span><span style="color: #009900;">&#41;</span>mouseX <span style="color: #339933;">/</span> width <span style="color: #339933;">*</span> <span style="color: #cc66cc;">255</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> i<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> pixels.<span style="color: #006633;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    setPixelFromBitmap<span style="color: #009900;">&#40;</span>myThreshold<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">/*
    * Inkrement von myPixelPosition und mit dem *Modulo* wird
    * garantierrt, dass der Array in seinen Grenzen bleibt
    */</span>
    myPixelPosition<span style="color: #339933;">++;</span>
    myPixelPosition<span style="color: #339933;">%=</span> pixels.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #666666; font-style: italic;">/* alle Pixels darstellen */</span>
  updatePixels<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> setPixelFromBitmap<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">float</span> theThreshold<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">/*
  * das aktuelle Pixel abfragen
  * myPixePosition ist global definiert und kann deshalb überall verwendet werden
  */</span>
  <span style="color: #000066; font-weight: bold;">int</span> myImagePixel <span style="color: #339933;">=</span> myImage.<span style="color: #006633;">pixels</span><span style="color: #009900;">&#91;</span>myPixelPosition<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*
  * Abfrage, ob aktuelle Pixel größer oder kleiner ist als der Schwellwert...
  * entsprechend wird der Farbwert invertiert
  */</span>
  <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>brightness<span style="color: #009900;">&#40;</span>myImagePixel<span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span> theThreshold<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    pixels<span style="color: #009900;">&#91;</span>myPixelPosition<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #000000; font-weight: bold;">else</span> <span style="color: #009900;">&#123;</span>
    pixels<span style="color: #009900;">&#91;</span>myPixelPosition<span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> color<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>Modulo</strong><br />
Der Modulo gibt mir den Rest einer Division zurück.<br />
<code>5 Modulo 2 = 1<br />
5 % 2 = 1</code><br />
Damit kann ich einen Zähler erstellen, der nie über einen Bestimmten Wert wächst und einen Array out of Bounds Fehler produziert, also einen Arrayindex abfragt der größer wäre als der Arry tatsächlich ist:<br />
<code>myPixelPosition%= pixels.length;<br />
wo_befinde_ich_mich_im_array %= gesamtlänge_des_arrays</code></p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> myArray<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> myArrayPosition<span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">320</span>, <span style="color: #cc66cc;">240</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  frameRate<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">5</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rectMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  myArray <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #000066; font-weight: bold;">int</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #cc66cc;">40</span>, <span style="color: #cc66cc;">80</span>, <span style="color: #cc66cc;">120</span>, <span style="color: #cc66cc;">160</span>, <span style="color: #cc66cc;">200</span>, <span style="color: #cc66cc;">240</span>, <span style="color: #cc66cc;">280</span>  <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  myArrayPosition<span style="color: #339933;">++;</span>
  myArrayPosition <span style="color: #339933;">%=</span> myArray.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
  println<span style="color: #009900;">&#40;</span>myArrayPosition<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  rect<span style="color: #009900;">&#40;</span>myArray<span style="color: #009900;">&#91;</span>myArrayPosition<span style="color: #009900;">&#93;</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span>, <span style="color: #cc66cc;">40</span>, height <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 2 &#124; Methode, Funktion und Schleife</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-2/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-2/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 19:51:30 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=279</guid>
		<description><![CDATA[Schleife
Die graphische Grundelemente sind die Linie, Ellipse, Rechteck, Bogen und Bezier. Damit können mit Reihungen, Schaltungen oder anderen Kombinationen alle beliebigen zweidimensionale Geometrien erstellt werden. Weitere Formen findet man in der Reference unter &#8220;Shapes&#8221;.
Reihungen können unter anderem mit der for-Schleife erstellt werden. Die for-Schleife wiederholt sich so lange, bis eine definierte Bedingung erfüllt ist. Dazu [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Schleife</strong><br />
Die graphische Grundelemente sind die Linie, Ellipse, Rechteck, Bogen und Bezier. Damit können mit Reihungen, Schaltungen oder anderen Kombinationen alle beliebigen zweidimensionale Geometrien erstellt werden. Weitere Formen findet man in der Reference unter &#8220;Shapes&#8221;.</p>
<p>Reihungen können unter anderem mit der for-Schleife erstellt werden. Die for-Schleife wiederholt sich so lange, bis eine definierte Bedingung erfüllt ist. Dazu werden in der Klammer nach for drei &#8220;Gesetze&#8221; aufgestellt;<br />
for(wie beginnt die Schleife, wann endet die Schleife; was verändert sich in jedem Durchlauf)<br />
Dazu definiert man einen Startwert, einen Endwert. Kontrolliert wird die Schleife durch den Zähler, der sich in jedem Schleifendurchlauf ein klein wenig verändert,  z.B. um 1 erhöht. Zugleich kann der Zähler, da er sich nach meinen Wünschen verändert, für die Programmsteuerung verwendet werden. Z.B:</p>
<p>for(Zähler bekommt einen Anfangswert; Zähler kleiner als Endwert?; dann wird der Zähler nochmal ein wenig größer)</p>
<p>Ist der Zähler nicht mehr kleiner als der Endwert, wir die Schleife einfach verlassen und der Programmablauf geht zum nächsten Schritt.</p>
<p><strong>Methode</strong><br />
Um immer wiederkehrende Aufgaben nicht mehrmals programmieren zu müssen, können diese in sogenannte Methoden gepackt werden. Methoden sind wie setup() und draw() in sich geschlossene Blöcke die mit einer geschweiften Klammer beginne und enden. Dazwischen liegt der Methodenrumpf.<br />
Im Beispiel unten sind<br />
drawHalfWay()<br />
getAverage()<br />
solche Methoden, die von jeder beliebigen Stelle aus aufgerufen werden können.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">int</span> numLines <span style="color: #339933;">=</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">int</span> distLine<span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">600</span>,<span style="color: #cc66cc;">600</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 distLine <span style="color: #339933;">=</span> width<span style="color: #339933;">/</span>numLines<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 background<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">255</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #666666; font-style: italic;">/* Line malen, aber erst die Hälfte berechnen...*/</span>
 <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> x<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>x<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span>numLines<span style="color: #339933;">;</span>x<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  <span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> y<span style="color: #339933;">=</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>y<span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;=</span>numLines<span style="color: #339933;">;</span>y<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
   drawHalfWay<span style="color: #009900;">&#40;</span>x<span style="color: #339933;">*</span>distLine,y<span style="color: #339933;">*</span>distLine<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
 <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> drawHalfWay<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> theX, <span style="color: #000066; font-weight: bold;">int</span> theY<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">int</span>  myHalfX <span style="color: #339933;">=</span> getAverage<span style="color: #009900;">&#40;</span>mouseX, theX<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000066; font-weight: bold;">int</span>  myHalfY <span style="color: #339933;">=</span> getAverage<span style="color: #009900;">&#40;</span>mouseY, theY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 line<span style="color: #009900;">&#40;</span>theX, theY, myHalfX, myHalfY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">int</span> getAverage<span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">int</span> theA, <span style="color: #000066; font-weight: bold;">int</span> theB<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 <span style="color: #000066; font-weight: bold;">int</span> myHalfWay <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>theA <span style="color: #339933;">+</span> theB<span style="color: #009900;">&#41;</span> <span style="color: #339933;">/</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 <span style="color: #000000; font-weight: bold;">return</span> myHalfWay<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing Workshop &#124; Teil 1</title>
		<link>http://ifdblog.org/ba-om2010/processing-workshop-teil-1/</link>
		<comments>http://ifdblog.org/ba-om2010/processing-workshop-teil-1/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 18:28:08 +0000</pubDate>
		<dc:creator>Markus Walthert</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://ifdblog.org/ba-om2010/?p=267</guid>
		<description><![CDATA[Mit dem processing Workshop am 6. und 7. November 2009 versuchte ich, die die wichtigsten Elemente zu vermitteln um danach möglichst eigene Ideen umzusetzen. Um diesen Schritt zu meistern, sollte anhand eines kleines eher kleinen Vokabulars jedoch der Umgang mit dem &#8220;Wörterbuch&#8221;, der Reference, in groben Zügen möglich sein und vor allem sollte die Angst [...]]]></description>
			<content:encoded><![CDATA[<p>Mit dem processing Workshop am 6. und 7. November 2009 versuchte ich, die die wichtigsten Elemente zu vermitteln um danach möglichst eigene Ideen umzusetzen. Um diesen Schritt zu meistern, sollte anhand eines kleines eher kleinen Vokabulars jedoch der Umgang mit dem &#8220;Wörterbuch&#8221;, der Reference, in groben Zügen möglich sein und vor allem sollte die Angst vor Code genbommen werden.</p>
<p>Die Beispiele lehnen sich an Tutorials von <a href="http://www.we-make-money-not-art.com/archives/2007/04/dennis-paul-and.php" target="_self"><strong>Patrick Paul</strong> </a>und <a href="http://www.we-make-money-not-art.com/archives/2007/04/dennis-paul-and.php" target="_self"><strong>Dennis Kochlick</strong></a> an.</p>
<p><a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-2/" target="_self">Teil 2: Schleifen und Methoden</a><br />
<a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-3/" target="_self"> Teil 3: Pixeldaten verarbeiten und Arrys</a><br />
<a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-4/" target="_self"> Teil 4: Hittest und Button</a><br />
<a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-5/" target="_self"> Teil 5: Objekt und Bewegung</a><br />
<a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-6/"> Teil 6: Spiegeln</a><br />
<a href="http://ifdblog.org/ba-om2010/processing-workshop-teil-7/" target="_self"> Teil 7: Stringoperation</a></p>
<p><strong>setup und draw</strong><br />
Die Grundzüge einer einfachen processing Anwendung besteht aus dem <code>setup()</code> und dem <code>draw()</code>. Das <code>setup()</code> wird in der Programmausführung einmal durchlaufen und legt die ersten Einstellungen wie der Größe des Darstellungsfensters fest. Die <code>draw()</code> wird zyklisch durchlaufen wobei jeder Zyklus neue Bedingungen erfüllen kann, z.B. die Mausposition in eine Ellipsengröße umwandeln.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000066; font-weight: bold;">void</span> setup<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 size<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">300</span>,<span style="color: #cc66cc;">300</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000066; font-weight: bold;">void</span> draw<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
 ellipseMode<span style="color: #009900;">&#40;</span>CENTER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
 ellipse<span style="color: #009900;">&#40;</span>mouseX, mouseY, pmouseX, pmouseY<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://ifdblog.org/ba-om2010/processing-workshop-teil-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
