Difference between revisions of "Ruby:Programming Tutorial"

From Progzoo
Jump to: navigation, search
m (Andr3w moved page Ruby:ProgZoo to Ruby:Programming Tutorial)
 
(12 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
{{topTenTips}}
 
An introduction to computer programming using Ruby. Comprising
 
An introduction to computer programming using Ruby. Comprising
 
*[[ruby:Tutorials| Tutorials]] which present problems and their solutions.
 
*[[ruby:Tutorials| Tutorials]] which present problems and their solutions.
Line 4: Line 5:
 
*[[ruby:Assessments| Assessments]] graded problems with solutions.
 
*[[ruby:Assessments| Assessments]] graded problems with solutions.
 
==An Example: drawing the French tricolour ==
 
==An Example: drawing the French tricolour ==
You can create images using the GD2 library. The first tutorial [[Flags]] looks at drawing flags of the world, from simple flags such as Libya to more complicated flags such as the Stars and Stripes of the USA.
+
You can create images using the GD2 library. The first tutorial [[{{NAMESPACE}}:Flags Tutorial|Flags]] looks at drawing flags of the world, from simple flags such as Libya to more complicated flags such as the Stars and Stripes of the USA.
  
 
With GD2 you can set the canvas color and draw a rectangle to create simple images.         
 
With GD2 you can set the canvas color and draw a rectangle to create simple images.         
Line 10: Line 11:
 
[[Image:Flag_guide_france.png|border|right]]  
 
[[Image:Flag_guide_france.png|border|right]]  
 
Notice that the blue rectangle has corners at (0,0) and (50,100) and has color [1,0,0]
 
Notice that the blue rectangle has corners at (0,0) and (50,100) and has color [1,0,0]
 +
<div style='clear:right'>
 
  g.color = image.palette.resolve Color[1.0, 0, 0]
 
  g.color = image.palette.resolve Color[1.0, 0, 0]
 
  g.rectangle(0,0,50,100,filled=true)
 
  g.rectangle(0,0,50,100,filled=true)
 +
</div>
 
<shell lang="rb" className="Flag" import="shells.xml#rasterrb"/>
 
<shell lang="rb" className="Flag" import="shells.xml#rasterrb"/>
 
<prog>
 
<prog>
Line 23: Line 26:
 
end
 
end
 
</prog>
 
</prog>
<answer>
 
image.draw do |g|
 
  g.color = image.palette.resolve Color[0,0,1.0]
 
  g.rectangle(0,0,50,100,filled=true)
 
  g.color = image.palette.resolve Color[1.0,1.0,1.0]
 
  g.rectangle(50,0,100,100,filled=true)
 
  g.color = image.palette.resolve Color[1.0,0,0]
 
  g.rectangle(100,0,150,100,filled=true)
 
end
 
</answer>
 
 
</question>
 
</question>
  

Latest revision as of 15:44, 21 March 2015

An introduction to computer programming using Ruby. Comprising

An Example: drawing the French tricolour

You can create images using the GD2 library. The first tutorial Flags looks at drawing flags of the world, from simple flags such as Libya to more complicated flags such as the Stars and Stripes of the USA.

With GD2 you can set the canvas color and draw a rectangle to create simple images.

Flag guide france.png

Notice that the blue rectangle has corners at (0,0) and (50,100) and has color [1,0,0]

g.color = image.palette.resolve Color[1.0, 0, 0]
g.rectangle(0,0,50,100,filled=true)


[Font] [Default] [Show] [Resize] [History] [Profile]

Consult the User's Guide for information on changing material in progzoo.

You can mess about in the Playpen.