Home
> MicroWorlds Logo Links & Examples >
MicroWorlds Code Pages > Art2 Code
art2.txt 6 KB
; Purpose: To play with art brushes
; Copyright © 2004 by Rupert Russell
; e-mail: rupert.russell1@gmail.com
; URL: http://www.rupert.id.au/microworlds/
; Created: October 13, 2004
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
; ----------------------------------------------------------------------
; Based on art1.mw2
; Overview or psudocode
; move the blue turtle to the green turtle
; repeat the following
; turn the blue turtle towards to the red turtle
; draw a line
; turn the blue turtle to the green turtle
; draw a line back again
; then move the green turtle in a random direction 100 times
; end
; ---------------------------------------------------------------------
to startup
; this procedure is called each time the project is loaded
; set up default values
t_instructions, st ; show the instructions
setsh_all_off
make "offset 5
make "browns 999
make "blues 100
make "greens 60
make "yellows 45
make "reds 12
make "magentas 115
greens ; set the default brush to greens
line_up_turtles
; set the initial position of the red and green turtles
red, home
green, home fd 100
end
to line_up_turtles
; align and distribute the 15 coloured turtles
make "x_offset 132
make "y_offset -198
make "count 0
repeat 15 [
run (word char 32 "t_show_unknown_colour_
:count ", char 32 "setx char 32 :x_offset + :count * 8)
run (word char 32 "t_show_unknown_colour_
:count ", char 32 "sety char 32 :y_offset)
make "count :count + 1
]
end
to setsh_all_off
; set all turtles to "off
t_browns, setsh "browns_off
t_random, setsh "random_off
t_blues, setsh "blues_off
t_greens, setsh "greens_off
t_yellows, setsh "yellows_off
t_reds, setsh "reds_off
t_magentas, setsh "magentas_off
t_unknown, setsh "unknown_off
end
to blues
setsh_all_off
t_blues, setsh "blues_on
make "offset 5
make "colour :blues
show_colours :colour :offset
end
to magentas
setsh_all_off
t_magentas, setsh "magentas_on
make "offset 8
make "colour :magentas
show_colours :colour :offset
end
to reds
setsh_all_off
t_reds, setsh "reds_on
make "offset 5
make "colour :reds
show_colours :colour :offset
end
to yellows
setsh_all_off
t_yellows, setsh "yellows_on
make "offset 3
make "colour :yellows
show_colours :colour :offset
end
to browns
setsh_all_off
t_browns, setsh "browns_on
make "offset 5
make "colour :browns
show_colours :colour :offset
end
to greens
setsh_all_off
t_greens, setsh "greens_on
make "offset 5
make "colour :greens
show_colours :colour :offset
end
to random_colour
; every line is a different random colour
setsh_all_off
t_random, setsh "random_on
make "offset 999
make "colour :blues
show_random_colours
end
to unknown
; pick a random range of colours
setsh_all_off
t_unknown, setsh "unknown_on
make "offset 15
make "colour random 999
show_colours :colour :offset
end
to show_random_colours
make "count 0
repeat 15 [
run (word "t_show_unknown_colour_ :count ",
char 32 "setc char 32 random 999)
make "count :count + 1
]
; show all the coloured turtles
make "count 0
repeat 15 [
run (word "t_show_unknown_colour_ :count ", char 32 "st)
make "count :count + 1
]
end
to show_colours :colour :offset
make "count 0
repeat 15 [
run (word "t_show_unknown_colour_ :count ", char 32 "ht)
make "count :count + 1
]
make "count 0
repeat :offset [
run (word "t_show_unknown_colour_ :count ",
char 32 "setc char 32 :colour + :count)
make "count :count + 1
]
make "count 0
repeat :offset [
run (word "t_show_unknown_colour_ :count ", char 32 "st)
make "count :count + 1
]
end
to paint
t_instructions, ht
snapshot ; record the current screen
talkto "blue clickon
end
to undo
restore ; restore background to previous snapshot
end
to go_to_green ; move the blue turtle to the green turtle
talkto "blue ; tell the blue turtle to do the following
towards "green ; turn towards the green turtle
pu
fd distance "green ; go forwards to the green turtle
end
to draw_line
talkto "blue ; tell the blue turtle to do the following
go_to_green ; use the go_to_green procedure above
pd
; put the pen down to draw a line
ht
; hide the blue turtle to speed up drawing
repeat 100 [
; repeat the following 100 times
talkto "blue ; tell the blue turtle to do the following
towards "red ; turn towards the red turtle
setc (random :offset) + :colour
fd distance "red ; go forwards to the red turtle
towards "green ; turn towards the green turtle
fd distance "green ; go forwards to the green turtle
talkto "green
fd random 20 ; go forward up to 20 steps
rt random 20 ; turn to the right up to 20 degrees
]
end
APA citation:
Russell, R. (2016, July 04, 04:16 pm). Art2 code.
Retrieved November 22, 2024, from http://www.rupert.id.au/microworlds/code/art2.php