Subscribe to RSS Subscribe to Comments

Sensthethesia

LASER HARP IS DONE!!!!!

I have been working all summer on a laser harp. It is finally done. It has 14 parallel strings right now. It pretty much works perfectly. I am having a heat dissipation issue and some sensor issues, but the fact that it’s working the first time and not just catching on fire is a marked success in my book.

I will try to explain this a little bit more in detail so that is can be replicated.

I am adding this to my MyoPLS (Make your own Personal Laser Show-Mayo Please) topic.

Here are some pictures and then I need a much deserved rest.

Gameboy Music

I have learned a lot in my assembly language class! I have made a really cool TicTacToe game as my final project. The part I am most excited about though is that I have learned how to make music for Gameboys. It’s so much fun that I will probably be doing it all summer just for fun!

Here is a link to a Tutorial I made to make Gameboy Music. It also has the source files to the songs below:

http://cratel.wichita.edu/cratel/ECE238Spr08/tutorials/GameBoyMusic%28.MOD-%3EAssembly%29

Here are some of the songs I have made.

Alf:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Gameboy Boogie:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Mario Land:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Popcorn:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Ride:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Star Trek TNG:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Super Mario:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Between2Waters:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

FastQuest:

Audio clip: Adobe Flash Player (version 9 or above) is required to play this audio clip. Download the latest version here. You also need to have JavaScript enabled in your browser.

Z80 VS Logochip

I was so stoked when I found out we are programming a gameboy in my ECE 238 Class. Now I will be working on a project with the Z80 and logochip this semester. I am going to be knee deep in code I feel, but it could be the be the best semester yet!

Now I just need to get added to the Class blog for ECE238

you know….this one:

http://cratel.wichita.edu/blogs/Assembly08

Art Review Project 2

Jeffery Bennett and I went to the Ulrich museum to see what was new there. Opposed to the last time, I was at the museum we entered the gallery from the front entrance. As we got the elevator, one piece in the dark corner took our attention. We spoke about this piece for a good thirty minutes to an hour. The piece was called Automata Studies by john F. Simon Jr. and I really feel like it was the most effective piece for me to study.

The piece was constructed from an LCD monitor and parts of a laptop. On the screen were six rectangular sections. Each section had a distinct routine and pattern that it would follow and gradually change or vary over time. The primary colors of the piece over the time we observed it were blue and green. This seems to make sense to me as an electrical engineer as the primary colors of the video display are red green and blue. I am not sure if this was intended for a cool look, if it changed over time, or perhaps these colors were easiest for the artist to manipulate logistically or to achieve the most intended color scheme in a random program. The program did seem to have either a random pattern or a pattern that was too long term to contemplate over the period we observed it.

The upper left hand section was the most organic section. A figure constructed of connected obtuse triangle shifted its way across the space. The segments seem to squirm as the artist allowed the angles of the triangle to vary as the shifted one at a time. As the body segments cam the rest it look as though a trail of tangent lines were printed on the area both looking like creatures legs and a residue trail that the creature left. The body segments seemed to be subtractive as the area they passed was cleared the background blue color. This seemed to embody both that the creature was eating the trail and also a balance between the colors as elements were working to both create and destroy color leaving the space in a constant state of equilibrium. These seem like more natural themes, which is interesting because of its embodiment in such a technical and geometric piece.

The next segment below it seems to have some parallel themes. This segment created random square patterns of two different shades place like a checkerboard but with no pattern. Then the algorithm sorts the two types of squares by moving one square of each color at the same time each covering a square of the opposite color. The routine would eventually sort the squares until all the squares of each color were sorted the opposite side of the screen section. This again embodied another type of balance as the routine always started with the same number of squares of two colors, only one subtractive of the other. Jeffery and I discussed this pattern quite a while. I believe that the program that does this pattern it recursive (it would be the most efficient but not the only way) function that probably changes a matrix of values corresponding to two square types and their position.

The section in the bottom middle was interesting. It was a complicated algorithm of Tetris that was used to continuously change the form and pattern of the screen. Random quadrilateral shapes would fall from the top of the screen. The falling shapes would change color after a certain number of shapes had fallen. If the falling shape was the same at the shape that was beneath it, it would stop on top of that shape and stack. If they were different colors, the falling piece would fall to the bottom or until it hit a shape of the same color. Some times a color would be subtractive and erase all the different color shapes it fell over, revealing the blue background behind it. This process again seems to embody a balance of color and the artist will to control his space with a building and a frequent renewal process. This renewal process seems to be akin to the easer to a chalkboard or the advent of winter to nature. How cluttered would a space be if it was never renewed and how would it look if too many colors were present at one time?

The upper middle and right hand section seemed the most enigmatic sections. At times it looked like they did the same thing but in a different way. Some times they look like a solid color. Then what looked like raster line patterns would scroll up from the bottom of these sections. These lines were at times one pixel in width. This would create an interesting effect as the pixel lines scrolled up the screen because this area would then fade in contrast at about two hertz, according to the rate of the scrolling pattern. At other times there would be fractal pattern based on triangles. The different of the two sections was that the middle section seemed to be based on a level horizontal line and the other was based on a diagonal. I was not sure what these section really meant to me and I also was not sure why they were so close together other than an obvious similarity or a message perhaps that was supposed to be derived from their fundamental differences.

The last lower right section was the easiest to understand. A triangular shape racked back and forth on anther triangle like a seesaw at a constant rate. At the end of each oscillation a sequence of square would fill or become hollow. It seemed obvious at the time that these squares were counting the oscillation with a non-standard number system. At first I thought the number system was binary but actually the system was exponentially weighted. Instead of each significant digit being able to count from a set zero to X (such as base ten 0-9 or binary 0-1), this system each digit as it becomes more significant can count from zero to two to the power of its significance. This makes a third order number much more significant that a standard number. There was also another non-standardization as the numbers filled left to right and bottom to top. The most significant row contained sixteen digits. This process was interesting to me. It signified that all the programs here were based of a clock and were synconized and it made me ponder the process in which it worked. Jeffery also mentioned that the piece was to “run its course” and eventually die. I pondered if maybe this was a count down or a system that only the artist could read. I did some work on a chalkboard right now. I don’t know if I quite got the right mathematical express for this but if there were 2^16×2^8×2^4×2^2 combinations then this clock could count 1,073,741,824 second. That is roughly 34 years. Perhaps that is the lifetime of the piece?

Over this entire piece was very effective in it’s execution, particularly to my scholastic expertise and me. I enjoyed talking about this piece with Jeffery and we seemed to have a very good fusion in conversation within our two disciplines with this piece. I think it will be interesting to see how art will harness these new mediums more and more to make more poignant and precise expression or how they may be muralized or institutionalize in future spaces and architecture. This pieces are very interesting to me because I can contemplate how they work and how I personally could make my own pieces, much like listening to the trombone is closer to me because it emulates emotions that I have, can, and want to express. This piece has given me some ideas for future personal pieces with this medium such a satire to the time with my laptop screen was cracked and the adaptively I had to create in my use to the computer by moving and resizing all my applications to a small corner of the screen.

As far as a critique for this piece, the only thing I didn’t like was how the screen was mounted on the outside of the frame, allowing the mounting bracket show on the outside of the screen. The unused metal fittings reminded me of the painstaking procedures of replacing my own laptop monitor and their inoperability in the piece seems to detract from the over all fusion of the piece and the relationship between the LCD component and the framing. It seems to be a less intentional piece then the two are together this way than being a uniform piece with no previous intentions. It just didn’t seem to say to me “this used to be a computer” but rather ” this is a complete electronic art form” and I my opinion, needed to be one uniform component executing it’s function.

Final Project Is Over

Setting Up our project was a breeze. At least my parts were. Most of the fabrication I hear was time consumming. I helped out with the main parts of the fabrication on Tuesday and Wednesday. It seemed like out project demanded blood. People were burned and hands were perferated. I was afraid that I was due for a good electrocution. It took alot of man power to hold things up and fit on all the rubber. At times I kind of wish it was a floor piece so it was easier to service. Those were some long nights, but we were a pretty good team and relations never worsened. Setting up the peice was pretty easy after that. We just bolted a mounting bracket to the ceiling and Connected the piece to a chain. As far as lighting, we decided to use just one of the overhead lights. We shined the light on the floor in front of the piece in order to highlight the interactive portion of the space. Also, it cast a large shadow behind the piece, which Nick really liked. Once we had the piece mounted on Thursday, our project was pretty much done. I came in early on Friday to test it out. All seemed fine.

Unfortunately, something happened to the motor during the show. About two or three hours into the show I noticed a problem with the motor. Before the piece was running without sticking. I think after a long term of use/drying components or perhaps after a viewer held the piece in place, there was damage to the brushes in the motor. The motor’s performance then worsened until finally it died. The motor was fairly warm at that point but not really that hot. I tried letting to cool down a little bit. After I had prognosed brush damage, Nick and Ryan really shined through by calling the nearest auto zone and picked up the nearest motor in town. While they were getting the motor I stayed and explained the piece to the viewers. The whole occurance kind of went with the theme of sustaining life as I role played that the piece had “died”. After a while there was quite a crowd waiting to see this breathing organ that thier friends had told them about and hour earlier. When the motor arrived, where was a show, kind of a concantination of a surgery and a cursing automechanic as Nick, Ryan, and I tried to install a new “implant.” There were complications however and the piece suffered “nerve damage”. The sensor bus was damaged; A Metaphorical spinal chord of the piece. We hot wired the motor to run full tilt and was able to maintain a show however. (After which I became overly portective part of the piece.)
It was very interesting environment to be in an art gallery situation. It was very new to me. I remember when the first non-biased public viewer saw our piece at 6.P.M. as he utter a long “Wow” of approvoal. It was a very gratifing and rememberable moment to me. Probably something I will remember for the rest of my life.

There were also some disspleasurable moments as well — such as when a viewer decided to vandalize our project — and some awkward moments as well — such as very beautiful and very inebriated young women asking me to make her a Batgirl suit and being very….persistant…infront of her boyfriend…
In all it was very good experience and I hope to participate in something like it again.

Third Update: Doccia

On Friday I went to Nick’s studio to get some of my circuitry together. My part of the project is going inside of a large moving structure so I was concerted about 1. Getting my circuity into a small enough package 2. How to mount that to the rest of the piece 3. Making the circuit fail proof and able to withstand the duress of being moved and jolted over a long period of time. I decided the mount all my modules to a piece of wood. Then using the wood as a mounting surface to the piece. Using a piece of wood also enabled me to staple, nail, drill, wire and modules down to the support structure. This enabled me to take stress off important connections.

I used my pitch program from Wednesday to test my circuit in several way. I first used it as a stress tester. I run the program. Then I shake the circuit as hard as I can. If the sound cuts out then I know something has failed, fix it, and repeat. By the time of the lab, I was able to practically throw the thing and not have a failure although my friend dropped it later and broke something, so now it has been through a unbiased test as well.

At the lab at our space, I used the pitch program to test the range and field of the sensor with audible cues. This enabled my partner and I to discuss placements and routines that we wanted for our breathing algorithm. After the lab Nick and I tested the motor out on the mechanical structure. The resistance was to great on the up stroke so Nick devised a plan to use a tendon structure to help the motor upstroke.

Saturday I conducted an experiment at Nick studio on range values with the sensor and touched up the program and circuitry so that I could get minimum functions from the motor. Once I was finished with that I did a test of the circuit with the actual piece and the motor. All went well except the range of values in the PWM module were not great enough to make a noticeable change in speed. The sensor did to it’s job though and I was able to start and stop the motor with sensor cues. With a little bit more tweaking of code, the electronic part of the piece should be done. All that will be left to do is to finalize the visual aspects of the sculpture.

Here is my current version code:

include libsrf05.txt

to Powerup
SRF05init
clearbit 1 porta-ddr ;PWM
clearbit 1 porta
clearbit 3 porta-ddr ;On/off
setbit 3 porta
clearbit 5 porta-ddr ;Hi/Low
clearbit 5 porta

loop[
setn SRF05getvalue / 250

If(n < 3) [setn 32]
Ifelse(n < 8)[setn 0]
[
If(n > 30)[setn 30]
If(n < 2) [setn 32]
]

setbit 1 porta mwait n
clearbit 1 porta mwait (32 - n)
]
end

;Max ~7850 Min ~250
;7+ huge varience/outliers
;6ft threshold= ~3700
;5ft threshold= ~3200
;4ft threshold= >2270
;3ft threshold= >1880
;2ft threshold= >1450
;1ft threshold= >1200

Second Update: Doccia

I took some time in the lab Wednesday to try out the SRF05 ultra sonic sensors. After burning up one of my logo chips with a freakish battery explosion…I got the desired effect from my configuration. I took John’s advise and used one logo chip (because I only had one left.). The program I made was pretty simple. When we goto the gallery Friday I hope to test out the range and get the proper calibrations for all the circuits I have build this past week. Also I will be able to get some input from the artistic side of the group on what we want the program to do. Here is the program I made on the fly that should do at least something final Friday.
include libsrf05.txt

to Powerup
SRF05init
clearbit 1 porta-ddr
clearbit 1 porta

loop[
setn SRF05getvalue / 250
setbit 1 porta mwait n
clearbit 1 porta mwait (16 - n)
]
end
This program has really tickled my fancy. I have made some other programs that use sensors and hand movements to change a speaker’s pitch (instead of the tone in this program) to make some kinetic musical instruments. Later I hope to make an array with the musical pitch tuning and use rounding average/ a rounding tuning method to get specific pitches instead of a glissando effect.

Here is a simple version of the musical ultrasonic sensor.

include libsrf05.txt
include libmovingaverage.txt

to Powerup
SRF05init
clearbit 1 porta-ddr
clearbit 1 porta
if MAinit 8 SRF05getvalue [prs "error]

loop[
setn MAverage SRF05getvalue
setm n / 200

repeat 10
[
setbit 1 porta
clearbit 1 porta
repeat m [no-op]
]

]

end

Team Doccia Final Project

It has been a couple of weeks and here is what I have done for our final project.

For the past couple of weeks I have been getting parts together.

I got:

5 amp,9-12V power supply.

some 5amp+ relays

lots of transistors and mosfets

found some LM34 temperature probes

3-5 Pelteir junctions

still have John Carper’s logo chip and bread board

Ryan got a windshield wiper motor from an 80′ Fairmont

Lots or wires and heat sinks, etc.

It’s a lot of junk really but it’s only cost me 13$ plus the motor ran Ryan 25$ so far.

The idea is to get all these pieces to work in concert. In order to really explain what I have done so far I need to discuss the goal of the piece.

We want to create a hanging sculpture that will be placed in the corner. This bio-mechanical sculpture is supposed to breathe. As viewers get closer to the piece, the breath rate is to change.

Stop

This problem has been the main problem that I have been addressing this week. Ideas of temperature, lights, or sound will be a later process.

Nick and Ryan have been working on a metal frame that will be used to support the structure and a system of crankshafts/hinges to make it breathe. The windshield wiper motor is to drive this action. I have been working on this part of the project: Motor control and Sensory perception (A.K.A. project Cerebellum)

I will try to explain what I have built but I have few pictures and the piece is broken up as Nick has the motor currently to measure it to build the housing inside the piece.

1. Power:The windshield wiper motor is a DC motor and it hasn’t pull more than 5 amps so it has worked fine with the power supply I had laying in my garage. To run the logo chips I will use another “wall wart” that the dog chewed up and happened to be around 6v.

2. Motor Control: With Relays I am able to cut the main power line from the motor to shut it off. A second 2-pull relay allows me to select the high and the low setting built into the windshield wiper motor. With some 2n2222 transistors, I am able to activate the relays with 5v logic inputs (logo chips).

For variable speed I have a Pulse Width Modulation circuit in line with the motor’s power circuit. Currently I have built my PWM module exactly like Keith’s example except with a 2n2222 transistor and a IRFZ44n Power MOSFETs. I am considering trying a totem pole driver. That is where I basically replace the 10K resistor in Keith’s example and use a properly current limited PNP transistor instead. This should give me a better response curve on the MOSFET as it builds it’s channel possibly giving me better thermal stability. But as is, everything is work out as it should.

3.Sensory:Here is where I left off this weekend. I had gotten 2 SRF10’s ultrasonic sensors. Unfortunately I didn’t have the time or resources to figure them out this weekend. What we want to have a 90 degree field (because the piece is in a corner) where the viewer can approach the piece and the sensors detect presence and range and change it’s breathe rate. We are thinking of projecting 2 sensor fields from each wall face of the corner. Since I didn’t have a working sensor array I just used a logo chip and a potentiometer to change the motor speed. So…depending on what input I can get from the sensors I will have either a basic PWM loop something like this with various motor tricks, conditions and cutoffs inside:

_____________________For an analog input A0 ____________________________

include ad.lib

to Powerup
config-analog-lines 1
clearbit 1 porta-ddr
clearbit 1 porta
end

to startup
loop[
setn read-ad 0
setm n / 32
setbit 1 porta mwait m
clearbit 1 porta mwait (32 - m)
]
end
_________________________________________________

OR….

_______________For a digital binary input (write/read port) from another logochip__________

to powerup

write portb-ddr 0

write portb 0

end

to startup

loop[

setn read-ad 0

setm n / 32

setbit 7 portb mwait m

clearbit 7 portb mwait (32 - m)

]

end

_________________________________________________

So….That where I am at. Here are some pictures and a very bad drawing Of what I have done. I couldn’t get a picture of it all together so the pictures don’t make sense.

Mini Project Finally Done

We are done with our mini project and that makes me quite relieved. Our group had a pretty hard time scheduling times that we could meet. Most of our group was gone the first week and we were all pretty bad at or just terribly unlucky at checking our emails (except Muhammad Zahid, who deserves my apology for always getting his message a day late.) .It was even harder to decide what exactly we were going to do. A lot of ideas were too hard or were too artistically vague. Our group thought we had something going toward the end of the second week with the ferrofluid that Andy had ordered but that ended up being a chemical puzzle and we were lacking a chemist. I even asked some chemists I knew but nothing really came off the top of their head or they weren’t household solutions either. We finally had to make the executive decision of scraping the last two weeks research and coming up with something to do in a short amount of time. Nick had an interesting idea about having two logo chips hooked to keyboards that would type randomly and eventually write something from Shakespeare just as the saying goes…Put two computer chips in a room etc etc. Nick and I talked again toward the deadline about some kind of statement we could make about technology and computers. He was interested in changing and complicating interfaces, specifically the mouse. The mouse seemed like a simple idea to emulate to me. We sat and discussed it with Andy, while he was available, and came up with basics of how this would come about. That night I robbed my poor mother’s mouse from her computer and rewired it with CAT5 cables so that I could use the right and left click remotely. Around Ten O’clock that night Nick was able to meet me in the studio and we built the whole thing from scratch. It took us until about midnight. Today I found my old digital camera I got for Christmas and uploaded pictures to the mini project wiki. That has been what the mini project journey has been like for me. I don’t think we made as pristine of a product as we could be but I think the real message our group got out of this was the problems with concept vs. design. It seemed like the ideas that the engineers came up were to technical and a artistically unsound. I think it is important for the artist to take an initiative in coming up with the concept, the engineers providing a means, then both groups coming together in the execution. It seem that with Nick finally said “this is what I want to do” and I was able to say “this is how we could do it” and then we did it, that there was the most natural progression in our work and the most efficient use of our expertise. I hope this will help keep me in perspective for the final project and that it will be as much fun as do the mini project was!

LogoChip War Prototype

;WAR CITY PROTOCOL
;Tommy Engdahl
;This is the protocol for a city at war-a network of waring chips
;One on One /Green Side

global [rpop]
global [gpop]
global [pop]
global [color]
global [X]
global [y]
global [war]
global [army]
global [growth]
global [vic]

to Powerup
main_initialization
loop
[
warloop
if (vic = 1) [powerup]
]
end

;——————————————–
to main_initialization
;include ad.lib
write $fc1 $f
;config-analog-lines 2
;a0 a1 input tech and year input.

;green number in binary
clearbit 0 portb-ddr
clearbit 1 portb-ddr
clearbit 2 portb-ddr
clearbit 3 portb-ddr

;red number in binary
clearbit 4 portb-ddr
clearbit 5 portb-ddr
clearbit 6 portb-ddr
clearbit 7 portb-ddr

;set pop to 1 Green
setgpop 1
setbit 0 portb
clearbit 1 portb
clearbit 2 portb
clearbit 3 portb

;set pop to 0 Red
setrpop 0
clearbit 4 portb
clearbit 5 portb
clearbit 6 portb
clearbit 7 portb

;Color Channel
;setbit 5 portc-ddr
;setbit 6 portc-ddr

;Turn Channel
clearbit 0 porta-ddr
setbit 1 porta-ddr

;War Channel1
clearbit 2 porta-ddr
setbit 3 porta-ddr

;troop channel1
clearbit 4 porta-ddr
setbit 5 porta-ddr

clearbit 0 porta
clearbit 2 porta
clearbit 4 porta
;clearbit 5 portc

setcolor 0
setgrowth 2
setvic 0
end
;————————————–

to warloop
setbit 0 porta

showled

;GDP Phase———————————

ifelse (color = 0)[setx gpop][setx rpop]
ifelse (x = 9) [setx 9][setx x + (random % growth)]
ifelse (color = 0)[setgpop x][setrpop x]
print x
print rpop
print gpop
print “—–”
showled

sety random % 100

;foriegn polocies———————————
if (x = 9)[setwar 1]
ifelse (x > 5) [setwar 0][if (y > 90) [setwar 1]]
setwar 0 ;forced peace

;build army————————————
if (war = 1)
[
setarmy x - (random % (x - 2) + 1)
]

;war phase———————————-
ifelse (war = 1)[setbit 2 porta][clearbit 2 porta]

turnsync

;If ((testbit 6 portc and (color = 1)) or not(testbit 6 portc and (color not 0)))
ifelse (war = 1)
[
ifelse (testbit 3 porta)
[
turnsync
ifelse (color = 0)[setx gpop][setx rpop]
setx x - 1 ;border clash
ifelse (color = 0)[setgpop x][setrpop x]
]
[
turnsync
invade
]
]
[
ifelse (testbit 3 porta)
[
turnsync
defend
resolve
]
[
turnsync
]
]

showled

turnsync

victory

showled

turninit
end

to showled
showred rpop   ;decodeing pop and sending binary to 7 segment with logic
showgreen gpop
wait 20
end

to showred :pop
setpop rpop
if (pop = 0)
[
clearbit 4 portb
clearbit 5 portb
clearbit 6 portb
clearbit 7 portb
]
if (pop = 1)
[
setbit 4 portb
clearbit 5 portb
clearbit 6 portb
clearbit 7 portb
]
if (pop = 2)
[
clearbit 4 portb
setbit 5 portb
clearbit 6 portb
clearbit 7 portb
]
if (pop = 3)
[
setbit 4 portb
setbit 5 portb
clearbit 6 portb
clearbit 7 portb
]
if (pop = 4)
[
clearbit 4 portb
clearbit 5 portb
setbit 6 portb
clearbit 7 portb
]
if (pop = 5)
[
setbit 4 portb
clearbit 5 portb
setbit 6 portb
clearbit 7 portb
]
if (pop = 6)
[
clearbit 4 portb
setbit 5 portb
setbit 6 portb
clearbit 7 portb
]
if (pop = 7)
[
setbit 4 portb
setbit 5 portb
setbit 6 portb
clearbit 7 portb
]
if (pop = 8)
[
clearbit 4 portb
clearbit 5 portb
clearbit 6 portb
setbit 7 portb
]
if (pop = 9)
[
setbit 4 portb
clearbit 5 portb
clearbit 6 portb
setbit 7 portb
]
end

to showgreen :pop
setpop gpop
if (pop = 0)
[
clearbit 0 portb
clearbit 1 portb
clearbit 2 portb
clearbit 3 portb
]
if (pop = 1)
[
setbit 0 portb
clearbit 1 portb
clearbit 2 portb
clearbit 3 portb
]
if (pop = 2)
[
clearbit 0 portb
setbit 1 portb
clearbit 2 portb
clearbit 3 portb
]
if (pop = 3)
[
setbit 0 portb
setbit 1 portb
clearbit 2 portb
clearbit 3 portb
]
if (pop = 4)
[
clearbit 0 portb
clearbit 1 portb
setbit 2 portb
clearbit 3 portb
]
if (pop = 5)
[
setbit 0 portb
clearbit 1 portb
setbit 2 portb
clearbit 3 portb
]
if (pop = 6)
[
clearbit 0 portb
setbit 1 portb
setbit 2 portb
clearbit 3 portb
]
if (pop = 7)
[
setbit 0 portb
setbit 1 portb
setbit 2 portb
clearbit 3 portb
]
if (pop = 8)
[
clearbit 0 portb
clearbit 1 portb
clearbit 2 portb
setbit 3 portb
]
if (pop = 9)
[
setbit 0 portb
clearbit 1 portb
clearbit 2 portb
setbit 3 portb
]
end

to turnsync
flash
clearbit 0 porta
loop [if (not testbit 1 porta)[setbit 0 porta stop]]
end

to warsync
clearbit 2 porta
loop [if (not testbit 3 porta)[setbit 2 porta stop]]
end

to armylisten
loop [if (not testbit 5 porta)[setbit 2 porta stop]]
end

to turninit

end

to invade
clearbit 4 porta
warsync
loop
[
warsync
ifelse (not(army = 0))
[
setbit 4 porta
setarmy army - 1
armylisten
]
[
clearbit 4 porta
stop
]
]
end

to defend
clearbit 4 porta
setarmy 0
warsync
loop
[
warsync
wait 1

ifelse (testbit 5 porta)
[
setarmy army + 1
wait 1
setbit 4 porta
wait 1
clearbit 4 porta
]
[
stop
]
]
end

to victory   ;losing contditions for game and player “resets” (you’ll never know you won here) infinite battle
ifelse (color = 0)
[
if (gpop = 0)
[
setbit 0 portb
setbit 1 portb
setbit 2 portb
setbit 3 portb
wait 100
setrpop 0
setgpop 2
]
]
[
if (rpop = 0)
[
setbit 4 portb
setbit 5 portb
setbit 6 portb
setbit 7 portb
wait 100
setrpop 2
setgpop 0
]
setvic 1
]
end

to resolve
ifelse (color = 0)[setrpop army][setgpop army]
setarmy 0
showled
loop
[
showled
setx random % 3 ;1/3 chance of g,r,0 loss
if (x = 0) [setrpop rpop - 1]
if (x = 1) [setgpop gpop - 1]
if ((rpop = 0) or (gpop = 0))
[stop]

]
end

Next Page »

Based on FluidityTheme Redesigned by Kaushal Sheth Sponsored by Send Flowers