Just starting out...need help...

Pixilang programming language
Post Reply
hseiken
Posts: 175
Joined: Thu Jul 17, 2008 3:52 am

Just starting out...need help...

Post by hseiken »

Hey, I'm not a super awesome programmer (really, all I've done are very simple things with Basic and VB Script that was taylored to a specific system) but I understand how things work and I'm having a hard time picking apart the docs to find my answer to my problem.

I was getting my feet wet and trying some simple 'test' programs and couldn't get any of them to work.

Can someone help?

This was intended to simply make a black screen. If you touch the palm's screen with the stylus, the screen would turn white. If you let up, it would return to black. But it didn't work and I couldn't figure out why! So then I tried to make another simple test: Wherever the stylus touches the screen, put a dot there. Again, no success. I think it's me not understanding how to use the pen_get_ commands...If someone could correct this code and explain what makes the changes work, I'd like that! Here's the faulty program...

Code: Select all

// Testing Commands

clear(BLACK)

draw_screen = {dot(x,y,WHITE)}

mainloop:
 x = gpx
 y = gpy
 if x + y =! 0 
 {
  draw_screen
 }
 frame
 goto mainloop
I know there's probably something STUPID I'm missing...what is it?

Any help would be awesome.
WARNINGThis angry old nerd may rant about modern computers or computer culture! It is not directed at you 99% of the time! Ignore it if it seems silly or personal!
hseiken
Posts: 175
Joined: Thu Jul 17, 2008 3:52 am

Re: Just starting out...need help...

Post by hseiken »

Also, this code locked up my Palm Tungsten T3!

It was intended to display the x/y coordinance of the stylus. But instead, it crashes the OS.

Code: Select all


clear(BLACK)

doit:
 x = gpx
 y = gpy
 print("x is $x and y is $y", 10, 10, WHITE)
go doit


Edit: Just tried this code in linux pixelang. Crashed it too (just pixelang, not linux!)
WARNINGThis angry old nerd may rant about modern computers or computer culture! It is not directed at you 99% of the time! Ignore it if it seems silly or personal!
Zuf
Posts: 110
Joined: Fri Dec 21, 2007 7:30 pm
Location: Msc
Contact:

Re: Just starting out...need help...

Post by Zuf »

Hi! Welcome here =)
I see few mistakes in your code.

The first program:

Code: Select all

    // Testing Commands
    clear(BLACK)
    draw_screen = {dot(x,y,WHITE)}

    mainloop:
    //x = gpx
    handle_pen_keys( {x=gpx}, 0, 0 )
    //y = gpy
    handle_pen_keys( {y=gpy}, 0, 0 )
    if x + y != 0
    {
      draw_screen
    }
    frame
    goto mainloop
Here the uncommon mistake: you use operator =! instead of != :)
Also you must use (as I know) function like handle_pen_keys to get pen coordinates.
See more info in manual and examples.

In your second code:

Code: Select all


clear(BLACK)

doit:
x = gpx
y = gpy
print("x is $x and y is $y", 10, 10, WHITE)
go doit
You miss frame call before go doit...

About linux, we know some problems related to KDE (I used pixilang in KDE) or maybe X.org things... Just we need more testing and bug reports about it =)

Of course, if you have any questions you can ask it here =)
hseiken
Posts: 175
Joined: Thu Jul 17, 2008 3:52 am

Re: Just starting out...need help...

Post by hseiken »

Hey, I understand my error when trying to plot points with the stylus now...however, I'm not understanding how to continually gather pen location. In other words, that code only records the first spot the pen touches. How can I track the pen? I would have thought that gpx/gpy in a loop would do that!

I look at source code to the graphics editor demos, but the way the code is written doesn't quite make sense to me. I understand the statements well enough (i.e. fbox, gpr, etc.), but I'm not seeing how the demos are able to make continuous lines by dragging the stylus around...
WARNINGThis angry old nerd may rant about modern computers or computer culture! It is not directed at you 99% of the time! Ignore it if it seems silly or personal!
Zuf
Posts: 110
Joined: Fri Dec 21, 2007 7:30 pm
Location: Msc
Contact:

Re: Just starting out...need help...

Post by Zuf »

Hello.

To handle pen movements you must set second parameter (subprogram) in handle_pen_keys like this:

handle_pen_keys( 0, {y=gpy x=gpx}, 0 )
See more information at manual:
Interaction with the user

handle_pen_keys (button_down_handler, pen_move_handler, button_up_handler) - handle all mouse (stylus) events that happen in a current frame.
Parameters of these commands are user-defined programs (subprograms) - handlers.

Example: handle_pen_keys( {x=get_pen_x}, 0, 0 )

get_pen_x, gpx - get current x-coordinate of mouse (or stylus)

get_pen_y, gpy - get current y-coordinate of mouse (or stylus)
http://en.wikibooks.org/wiki/Pixilang#I ... h_the_user


And one another thing. When you want to draw continuous line in graphical editor you must connect points, that you get from input device by lines.
Common raster editors doing it same way.

This is an example code:

Code: Select all

// Testing Commands
clear(BLACK)

// variables:
// current pen coordinates:
x=0
y=0
// previous pen coordinates:
px=x
py=y
//begin draw flag:
begin_draw=0

mainloop:

   // In the next line if pen (or mouse) down we set flag to only start
   // draw our line. So we must set our previous pen coordinates to current pen position.
   // When mouse moved we call draw_func to draw a line between previous and current pen position.
   // See more at http://en.wikibooks.org/wiki/Pixilang#Interaction_with_the_user
   handle_pen_keys({begin_draw=1}, {draw_func}, 0 )


  frame
goto mainloop

// Our handler for mouse move event:
draw_func:

  // Save previous pen position
  px=x
  py=y

  // Get current pen position
  x=gpx
  y=gpy

  // If we start new line set perios pos = current pos to get dot at pen position
  if (begin_draw=1)
  {
    px=x
    py=y

    begin_draw=0
  }

  // And draw line between previous and current position
  line (px,py,x,y, GREEN)

ret
P.S. Sorry for bad English, have no time to correct it =)
User avatar
Al_Rado
Posts: 239
Joined: Tue Dec 04, 2007 2:33 pm
Location: Krasnodar
Contact:

Re: Just starting out...need help...

Post by Al_Rado »

Zuf, thank you very mach! Очень интересный алгоритм рисования! Подобную идею как раз обдумывал как реализовать в CreaGraFix!
ВекторКодПиксельПолигон - ВотЧтоЯЛюблю!
Zuf
Posts: 110
Joined: Fri Dec 21, 2007 7:30 pm
Location: Msc
Contact:

Re: Just starting out...need help...

Post by Zuf »

Thanks Al_Rado! It is very common algorithm. :)
Post Reply