Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.objective-c > #192 > unrolled thread

New to Objective-c: issue with libraries

Started bymodelling.data@gmail.com
First post2015-11-10 23:25 -0800
Last post2015-11-11 19:26 +0100
Articles 2 — 2 participants

Back to article view | Back to comp.lang.objective-c


Contents

  New to Objective-c: issue with libraries modelling.data@gmail.com - 2015-11-10 23:25 -0800
    Re: New to Objective-c: issue with libraries "Pascal J. Bourguignon" <pjb@informatimago.com> - 2015-11-11 19:26 +0100

#192 — New to Objective-c: issue with libraries

Frommodelling.data@gmail.com
Date2015-11-10 23:25 -0800
SubjectNew to Objective-c: issue with libraries
Message-ID<23e4b497-b862-4c4a-9326-8aaabea64ec2@googlegroups.com>
Hello!

I am new to programming, and to Objective-C. I currently take a free online 
course on CS, which includes C programming, and has also introduced Objective-C.

Please, take a look at the program below, which uses Stanford Portable Library.

I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3, and would like to make
and compile such programs within these programs. What shall I do, which headers
shall I use? Shall I download them? 

**
 * bounce.c
 * Bounces a circle back and forth in a window.
 */

// standard libraries
#include <stdio.h>

// Stanford Portable Library
#include <spl/gevents.h>
#include <spl/gobjects.h>
#include <spl/gwindow.h>

int main(void)
{
    // instantiate window
    GWindow window = newGWindow(320, 240);

    // instantiate circle
    GOval circle = newGOval(0, 110, 20, 20);
    setColor(circle, "BLACK");
    setFilled(circle, true);
    add(window, circle);

    // initial velocity
    double velocity = 2.0;

    // bounce forever
    while (true)
    {
        // move circle along x-axis
        move(circle, velocity, 0);

        // bounce off right edge of window
        if (getX(circle) + getWidth(circle) >= getWidth(window))
        {
            velocity = -velocity;
        }

        // bounce off left edge of window
        else if (getX(circle) <= 0)
        {
            velocity = -velocity;
        }

        // linger before moving again
        pause(10);
    }
}

Thank you!

[toc] | [next] | [standalone]


#197

From"Pascal J. Bourguignon" <pjb@informatimago.com>
Date2015-11-11 19:26 +0100
Message-ID<878u644ckw.fsf@kuiper.lan.informatimago.com>
In reply to#192
modelling.data@gmail.com writes:

> Hello!
>
> I am new to programming, and to Objective-C. I currently take a free online 
> course on CS, which includes C programming, and has also introduced Objective-C.
>
> Please, take a look at the program below, which uses Stanford Portable Library.
>
> I work on Mac OS 10.7.5, Xcode 4.6.3, Terminal 2.2.3, and would like to make
> and compile such programs within these programs. What shall I do, which headers
> shall I use? Shall I download them? 

Yes.

You could write a makefile to compile your spl-example.m file:

-----(Makefile)-----------------------------------------------------------------

all:spl-example

.PHONY::run get-dependencies
get-dependencies:
	cd /usr/local/src/ ; git clone git@github.com:cs50/spl.git
	cd /usr/local/src/spl ; make && make install

run:spl-example
	CLASSPATH=/usr/local/lib/spl.jar ./spl-example

spl-example:spl-example.m
	gcc -o spl-example spl-example.m -lcs -lm

clean:
	rm spl-example

----------------------------------------------------------------------------------

To install spl:

    make get-dependencies

and then to run your program:

    make run


WFM on MacOSX and on Linux.

-- 
__Pascal Bourguignon__                 http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.objective-c


csiph-web