Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335438
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:01:06+00:00 2026-05-18T00:01:06+00:00

Here’s what I got so far. I rewrote the code to simplify things a

  • 0

Here’s what I got so far. I rewrote the code to simplify things a bit. Previous code wasn’t actually the real, basic algorithm. It had fluff that I didn’t need. I answered the question about pitch, and below you’ll see some images of my test results.

local function Line (buf, x1, y1, x2, y2, color, pitch)

    -- identify the first pixel
    local n = x1 + y1 * pitch

    -- // difference between starting and ending points
    local dx = x2 - x1;
    local dy = y2 - y1;

    local m = dy / dx
    local err = m - 1

    if (dx > dy) then   -- // dx is the major axis
        local j = y1
        local i = x1
        while i < x2 do
            buf.buffer[j * pitch + i] = color
            if (err >= 0) then
                i = i + 1
                err = err - 1
            end
            j = j + 1
            err = err + m
        end
    else        -- // dy is the major axis
        local j = x1
        local i = y1
        while i < y2 do
            buf.buffer[i * pitch + j] = color
            if (err >= 0) then
                i = i + 1
                err = err - 1
            end
            j = j + 1
            err = err + m
        end
    end
end


-- (visdata[2][1][576], int isBeat, int *framebuffer, int *fbout, int w, int h
function LibAVSSuperScope:Render(visdata, isBeat, framebuffer, fbout, w, h)
    local size = 5

    Line (self.buffer, 0, 0, 24, 24, 0xffff00, 24)
    do return end
end

Edit: Oh I just realized something. 0,0 is in the lower left-hand corner. So the function’s sort of working, but it’s overlapping and slanted.

Edit2:

Yeah, this whole thing’s broken. I’m plugging numbers into Line() and getting all sort of results. Let me show you some.

Here’s Line (self.buffer, 0, 0, 23, 23, 0x00ffff, 24 * 2)

alt text

And here’s Line (self.buffer, 0, 1, 23, 23, 0x00ffff, 24 * 2)

alt text

Edit: Wow, doing Line (self.buffer, 0, 24, 24, 24, 0x00ffff, 24 * 2) uses way too much CPU time.

Edit: Here’s another image using this algorithm. The yellow dots are starting points.

Line (self.buffer, 0, 0, 24, 24, 0xff0000, 24)
Line (self.buffer, 0, 12, 23, 23, 0x00ff00, 24)
Line (self.buffer, 12, 0, 23, 23, 0x0000ff, 24)

alt text

Edit: And yes, that blue line wraps around.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:01:07+00:00Added an answer on May 18, 2026 at 12:01 am

    This is what I settled on. I just had to find valid information on that Bresenham algorithm. Thanks cs-unc for the information about various line algorithms, from simple to complex.

    function LibBuffer:Line4(x0, y0, x1, y1, color, pitch)
        local dx = x1 - x0;
        local dy = y1 - y0;
        local stepx, stepy
    
        if dy < 0 then
            dy = -dy
            stepy = -1
        else
            stepy = 1
        end
    
        if dx < 0 then
            dx = -dx
            stepx = -1
        else
            stepx = 1
        end
    
        self.buffer[x0 + y0 * pitch] = color
        if dx > dy then
            local fraction = dy - bit.rshift(dx, 1)
            while x0 ~= x1 do
                if fraction >= 0 then
                    y0 = y0 + stepy
                    fraction = fraction - dx
                end
                x0 = x0 + stepx
                fraction = fraction + dy
                self.buffer[floor(y0) * pitch + floor(x0)] = color
            end
        else
            local fraction = dx - bit.rshift(dy, 1)
            while y0 ~= y1 do
                if fraction >= 0 then
                    x0 = x0 + stepx
                    fraction = fraction - dy
                end
                y0 = y0 + stepy
                fraction = fraction + dx
                self.buffer[floor(y0) * pitch + floor(x0)] = color
            end
        end
    end
    

    Here’s what this one looks like.

    alt text

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here are 2 screen shots when i try to debug my code in visual
Here a simple question : What do you think of code which use try
Here is what I am trying to achieve in PHP: I have this string:
Here is my simplified data structure: Object1.h template <class T> class Object1 { private:
Here's what I'm trying to do... It's quite simple and obviously there must be
Here's my test function (c#, visual studio 2010): [TestMethod()] public void TestGetRelevantWeeks() { List<sbyte>
Here is another spoj problem that asks how to find the number of distinct
Here is my question. I am having this simple menu. <div id=menu> <ul> <li>
Here is a snippet of my xaml: <ComboBox x:Name=cbo1 Width=100 SelectedValue=200> <ComboBoxItem Name=n1>100</ComboBoxItem> <ComboBoxItem
i want to parse a xhtml file and display in UITableView. what is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.