MultiDraw

by Ihsan Fazal: U6 Age ~17

Introduction

This neat and effective program copies each line that you draw to six other positions on the screen. Each line has a different colour of the rainbow. The program prints to the graphics screen the instruction and your response and so does not need to use a console window as well. Enter the offset, move the mouse with the left mouse button down to draw lines, and press the right mouse button to reset.

You can have a rainbow brush with small values of offset:

Rainbow brush

Rainbow brush

and draw multiple separated shapes with larger values:

Separated shapes

Separated shapes

You could easily adapt the program (i) to set x and y offsets independently and (ii) to output different colours.

In order to run program MultiDraw, you will need to have downloaded Stefan Berinde`s wingraph.zip file as described in our Graphics tutorial. You should copy the unzipped wincrt.pas, wingraph.pas and winmouse.pas (from the src folder) into your program folder. (The compiled units are included in the zip file but you might as well have the source code available for reference). You should find these three files useful for your own graphics programs.

The Program

program MultiDraw;
{
    Copyright (c) 2011 Ihsan Fazal
    
    Licensed under the Apache License, Version 2.0 (the "License"); you may not 
    use this file except in compliance with the License, as described at
    http://www.apache.org/licenses/ and http://www.pp4s.co.uk/licenses/
}

  {$APPTYPE GUI}
uses
  SysUtils,
  wingraph,
  winmouse,
  wincrt;

var
  driver, mode : smallint;
  ymouse, xMouse : word;
  inoffset : shortstring;
  offset : integer;

begin
  driver := detect;
  mode := 0;
  InitGraph(Driver, mode, 'MultiDraw');
  writebuf('Enter offset: ');
  readbuf(inoffset, 0);
  offset := strtoint(inoffset);

  repeat
    if getmousebuttons=1 then
      begin;
        putpixel(xmouse, ymouse, red);
        putpixel(xmouse+offset, ymouse+offset, orange);
        putpixel(xmouse + 2 * offset, ymouse + 2 * offset, yellow);
        putpixel(xmouse + 3 * offset, ymouse + 3 * offset, green);
        putpixel(xmouse + 4 * offset, ymouse + 4 * offset, blue);
        putpixel(xmouse + 5 * offset, ymouse + 5 * offset, indigo);
        putpixel(xmouse + 6 * offset, ymouse + 6 * offset, violet);
      end;
  ymouse:=getmousey;
  xmouse:=getmousex;

  if getmousebuttons=2 then
    begin
      cleardevice;
      writebuf('Enter offset: ');
      readbuf(inoffset, 0);
      offset:=strtoint(inoffset);
    end;

  until CloseGraphRequest;
  CloseGraph;
end.

Remarks

Can you develop this program?

Programming - a skill for life!

Student programs to inspire you!